Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turned SDK APIs into context manager #283

Merged
merged 6 commits into from
Jun 17, 2024

Conversation

aadityasinha-dotcom
Copy link
Contributor

@aadityasinha-dotcom aadityasinha-dotcom commented Jun 7, 2024

What It Does

Resolves #145

How to Test

Review Checklist
I certify that I have:

Additional Comments

Signed-off-by: aadityasinha-dotcom <aadityasinha009@gmail.com>
Signed-off-by: aadityasinha-dotcom <aadityasinha009@gmail.com>
Copy link
Member

@t1m0thyj t1m0thyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aadityasinha-dotcom, left a comment 🙂

Could you please also update the examples in SDK readmes to use with statement? For example, in the z/OS Console readme:

from zowe.core_for_zowe_sdk import ProfileManager
from zowe.zos_console_for_zowe_sdk import Console

profile = ProfileManager().load(profile_name="zosmf")

with Console(profile) as console_info:
    print(console_info.issue_command(command="D IPLINFO", console="EMCS"))

src/core/zowe/core_for_zowe_sdk/sdk_api.py Outdated Show resolved Hide resolved
@JTonda JTonda requested a review from zFernand0 June 10, 2024 15:16
Co-authored-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Aaditya Sinha <75474786+aadityasinha-dotcom@users.noreply.github.com>
def __enter__(self):
return self

def __exit__(self, exc_type, exception, traceback):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there be any use of exc_type, exception, traceback?
I am curious 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these parameters could be used to do exception handling inside the __exit__ function 😋
https://realpython.com/python-with-statement/#handling-exceptions-in-a-context-manager

In our case we always want to clean up the request handler and session object, regardless of whether an error has been raised, so I don't think we need to use them at all.

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.27%. Comparing base (3a15fc1) to head (8d20b51).
Report is 198 commits behind head on main.

Files with missing lines Patch % Lines
src/core/zowe/core_for_zowe_sdk/sdk_api.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #283      +/-   ##
==========================================
- Coverage   89.32%   89.27%   -0.05%     
==========================================
  Files          53       53              
  Lines        2529     2536       +7     
==========================================
+ Hits         2259     2264       +5     
- Misses        270      272       +2     
Flag Coverage Δ
unittests 89.27% <75.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

aadityasinha-dotcom and others added 2 commits June 11, 2024 18:14
Signed-off-by: aadityasinha-dotcom <aadityasinha009@gmail.com>
Copy link
Member

@traeok traeok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @aadityasinha-dotcom!

Copy link
Member

@t1m0thyj t1m0thyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @aadityasinha-dotcom!

@t1m0thyj t1m0thyj merged commit 8ac7348 into zowe:main Jun 17, 2024
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

Enhancement: implement context manager decorator to the SDK classes
3 participants