From 678d296cf05175bc7c7f19ad733bb09127323f38 Mon Sep 17 00:00:00 2001 From: pem70 Date: Thu, 18 Jul 2024 11:04:35 -0400 Subject: [PATCH 01/12] Use pylint to check and modify function names Signed-off-by: pem70 --- .github/workflows/sdk-build.yml | 2 ++ .../zowe/core_for_zowe_sdk/config_file.py | 2 +- src/core/zowe/core_for_zowe_sdk/connection.py | 2 +- .../core_for_zowe_sdk/credential_manager.py | 2 +- src/core/zowe/core_for_zowe_sdk/logger.py | 8 +++--- .../zowe/core_for_zowe_sdk/profile_manager.py | 12 ++++---- .../zowe/core_for_zowe_sdk/request_handler.py | 8 +++--- src/core/zowe/core_for_zowe_sdk/sdk_api.py | 8 +++--- src/core/zowe/core_for_zowe_sdk/session.py | 28 +++++++++---------- .../zowe/core_for_zowe_sdk/zosmf_profile.py | 2 +- .../zowe/zos_files_for_zowe_sdk/files.py | 4 +-- tests/integration/test_zos_files.py | 4 +-- tests/unit/core/test_logger.py | 14 +++++----- .../files/file_systems/test_file_systems.py | 17 +++++------ 14 files changed, 58 insertions(+), 55 deletions(-) diff --git a/.github/workflows/sdk-build.yml b/.github/workflows/sdk-build.yml index c9746da4..9bf6caac 100644 --- a/.github/workflows/sdk-build.yml +++ b/.github/workflows/sdk-build.yml @@ -32,6 +32,8 @@ jobs: run: pydocstyle --match-dir='^(?!build$).*' --match='^(?!(__init__\.py|setup\.py$)).*\.py$' src - name: Lint with pydoclint run: pydoclint --exclude='.*/build/.*' src + - name: Lint with pylint + run: pylint src --disable=all --enable=C0103 --ignore=build - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/src/core/zowe/core_for_zowe_sdk/config_file.py b/src/core/zowe/core_for_zowe_sdk/config_file.py index 9bcd5665..bd12a91b 100644 --- a/src/core/zowe/core_for_zowe_sdk/config_file.py +++ b/src/core/zowe/core_for_zowe_sdk/config_file.py @@ -75,7 +75,7 @@ class ConfigFile: jsonc: Optional[dict] = None _missing_secure_props: list = field(default_factory=list) - __logger = Log.registerLogger(__name__) + __logger = Log.register_logger(__name__) @property def filename(self) -> str: diff --git a/src/core/zowe/core_for_zowe_sdk/connection.py b/src/core/zowe/core_for_zowe_sdk/connection.py index 97f94bfd..61c5b321 100644 --- a/src/core/zowe/core_for_zowe_sdk/connection.py +++ b/src/core/zowe/core_for_zowe_sdk/connection.py @@ -36,7 +36,7 @@ class ApiConnection: """ def __init__(self, host_url: str, user: str, password: str, ssl_verification: bool = True): - __logger = Log.registerLogger(__name__) + __logger = Log.register_logger(__name__) if not host_url or not user or not password: __logger.error("Missing connection argument") raise MissingConnectionArgs() diff --git a/src/core/zowe/core_for_zowe_sdk/credential_manager.py b/src/core/zowe/core_for_zowe_sdk/credential_manager.py index 007301a4..f1cc85e8 100644 --- a/src/core/zowe/core_for_zowe_sdk/credential_manager.py +++ b/src/core/zowe/core_for_zowe_sdk/credential_manager.py @@ -31,7 +31,7 @@ class CredentialManager: """A class including static functions for managing credentials.""" secure_props = {} - __logger = Log.registerLogger(__name__) + __logger = Log.register_logger(__name__) @staticmethod def load_secure_props() -> None: diff --git a/src/core/zowe/core_for_zowe_sdk/logger.py b/src/core/zowe/core_for_zowe_sdk/logger.py index 880128ea..0cb5a804 100644 --- a/src/core/zowe/core_for_zowe_sdk/logger.py +++ b/src/core/zowe/core_for_zowe_sdk/logger.py @@ -33,7 +33,7 @@ class Log: loggers: set = set() @staticmethod - def registerLogger(name: str) -> logging.Logger: + def register_logger(name: str) -> logging.Logger: """ Create and register a logger. @@ -52,7 +52,7 @@ def registerLogger(name: str) -> logging.Logger: return logger @staticmethod - def setAllLoggerLevel(level: int): + def set_all_logger_level(level: int): """ Set display level for all loggers. @@ -89,13 +89,13 @@ def open(logger: logging.Logger): logger.disabled = False @staticmethod - def closeAll(): + def close_all(): """Disable all loggers.""" for logger in Log.loggers: logger.disabled = True @staticmethod - def openAll(): + def open_all(): """Enable all loggers.""" for logger in Log.loggers: logger.disabled = False diff --git a/src/core/zowe/core_for_zowe_sdk/profile_manager.py b/src/core/zowe/core_for_zowe_sdk/profile_manager.py index df3e3248..a48c1eaa 100644 --- a/src/core/zowe/core_for_zowe_sdk/profile_manager.py +++ b/src/core/zowe/core_for_zowe_sdk/profile_manager.py @@ -67,7 +67,7 @@ def __init__(self, appname: Optional[str] = "zowe", show_warnings: Optional[bool self.__project_config = ConfigFile(type=TEAM_CONFIG, name=appname) self.__project_user_config = ConfigFile(type=USER_CONFIG, name=appname) - self.__logger = Log.registerLogger(__name__) + self.__logger = Log.register_logger(__name__) self.__global_config = ConfigFile(type=TEAM_CONFIG, name=GLOBAL_CONFIG_NAME) try: @@ -261,7 +261,7 @@ def get_profile( FormatError If validating a format in the configuration fails. """ - logger = Log.registerLogger(__name__) + logger = Log.register_logger(__name__) cfg_profile = Profile() try: @@ -405,13 +405,13 @@ def load( cfg_schema = cfg_layer.schema_property cfg_schema_dir = cfg_layer._location - usrProject = self.__project_user_config.profiles or {} + usr_project = self.__project_user_config.profiles or {} project = self.__project_config.profiles or {} - project_temp = always_merger.merge(deepcopy(project), usrProject) + project_temp = always_merger.merge(deepcopy(project), usr_project) - usrGlobal = self.__global_user_config.profiles or {} + usr_global = self.__global_user_config.profiles or {} global_ = self.__global_config.profiles or {} - global_temp = always_merger.merge(deepcopy(global_), usrGlobal) + global_temp = always_merger.merge(deepcopy(global_), usr_global) profiles_merged = project_temp for name, value in global_temp.items(): diff --git a/src/core/zowe/core_for_zowe_sdk/request_handler.py b/src/core/zowe/core_for_zowe_sdk/request_handler.py index f7e88838..5853d82f 100644 --- a/src/core/zowe/core_for_zowe_sdk/request_handler.py +++ b/src/core/zowe/core_for_zowe_sdk/request_handler.py @@ -36,7 +36,7 @@ def __init__(self, session_arguments: dict, logger_name: str = __name__): self.session_arguments = session_arguments self.__valid_methods = ["GET", "POST", "PUT", "DELETE"] self.__handle_ssl_warnings() - self.__logger = Log.registerLogger(logger_name) + self.__logger = Log.register_logger(logger_name) def __handle_ssl_warnings(self): """Turn off warnings if the SSL verification argument if off.""" @@ -146,10 +146,10 @@ def __normalize_response(self) -> Union[str, bytes, dict]: - `str` when the response is plain text - `dict` when the response is json """ - contentType = self.__response.headers.get("Content-Type") - if contentType == "application/octet-stream": + content_type = self.__response.headers.get("Content-Type") + if content_type == "application/octet-stream": return self.__response.content - elif contentType and contentType.startswith("application/json"): + elif content_type and content_type.startswith("application/json"): return "" if self.__response.text == "" else self.__response.json() else: return self.__response.text diff --git a/src/core/zowe/core_for_zowe_sdk/sdk_api.py b/src/core/zowe/core_for_zowe_sdk/sdk_api.py index 1a2a8174..31494889 100644 --- a/src/core/zowe/core_for_zowe_sdk/sdk_api.py +++ b/src/core/zowe/core_for_zowe_sdk/sdk_api.py @@ -37,7 +37,7 @@ def __init__(self, profile: dict, default_url: str, logger_name: str = __name__) session = Session(profile) self.session: ISession = session.load() - self.logger = Log.registerLogger(logger_name) + self.logger = Log.register_logger(logger_name) self._default_service_url = default_url self._default_headers = { @@ -52,7 +52,7 @@ def __init__(self, profile: dict, default_url: str, logger_name: str = __name__) "headers": self._default_headers, } self.__session_arguments = { - "verify": self.session.rejectUnauthorized, + "verify": self.session.reject_unauthorized, "timeout": 30, } self.request_handler = RequestHandler(self.__session_arguments, logger_name=logger_name) @@ -60,9 +60,9 @@ def __init__(self, profile: dict, default_url: str, logger_name: str = __name__) if self.session.type == session_constants.AUTH_TYPE_BASIC: self._request_arguments["auth"] = (self.session.user, self.session.password) elif self.session.type == session_constants.AUTH_TYPE_BEARER: - self._default_headers["Authorization"] = f"Bearer {self.session.tokenValue}" + self._default_headers["Authorization"] = f"Bearer {self.session.token_value}" elif self.session.type == session_constants.AUTH_TYPE_TOKEN: - self._default_headers["Cookie"] = f"{self.session.tokenType}={self.session.tokenValue}" + self._default_headers["Cookie"] = f"{self.session.token_type}={self.session.token_value}" elif self.session.type == session_constants.AUTH_TYPE_CERT_PEM: self.__session_arguments["cert"] = self.session.cert diff --git a/src/core/zowe/core_for_zowe_sdk/session.py b/src/core/zowe/core_for_zowe_sdk/session.py index f3cff7ec..d91d2a5a 100644 --- a/src/core/zowe/core_for_zowe_sdk/session.py +++ b/src/core/zowe/core_for_zowe_sdk/session.py @@ -23,14 +23,14 @@ class ISession: host: str port: int = session_constants.DEFAULT_HTTPS_PORT - rejectUnauthorized: bool = True + reject_unauthorized: bool = True user: Optional[str] = None password: Optional[str] = None protocol: str = session_constants.HTTPS_PROTOCOL - basePath: Optional[str] = None + base_path: Optional[str] = None type: Optional[str] = None - tokenType: Optional[str] = None - tokenValue: Optional[str] = None + token_type: Optional[str] = None + token_value: Optional[str] = None cert: Optional[str] = None @@ -51,7 +51,7 @@ class Session: def __init__(self, props: dict) -> None: # set host and port - self.__logger = Log.registerLogger(__name__) + self.__logger = Log.register_logger(__name__) if props.get("host") is not None: self.session: ISession = ISession(host=props.get("host")) @@ -63,14 +63,14 @@ def __init__(self, props: dict) -> None: if props.get("user") is not None and props.get("password") is not None: self.session.user = props.get("user") self.session.password = props.get("password") - self.session.rejectUnauthorized = props.get("rejectUnauthorized") + self.session.reject_unauthorized = props.get("rejectUnauthorized") self.session.type = session_constants.AUTH_TYPE_BASIC elif props.get("tokenType") is not None and props.get("tokenValue") is not None: - self.session.tokenType = props.get("tokenType") - self.session.tokenValue = props.get("tokenValue") + self.session.token_type = props.get("tokenType") + self.session.token_value = props.get("tokenValue") self.session.type = session_constants.AUTH_TYPE_TOKEN elif props.get("tokenValue") is not None: - self.session.tokenValue = props.get("tokenValue") + self.session.token_value = props.get("tokenValue") self.session.type = session_constants.AUTH_TYPE_BEARER elif props.get("certFile") is not None: if props.get("certKeyFile"): @@ -78,7 +78,7 @@ def __init__(self, props: dict) -> None: else: self.__logger.error("A certificate key file must be provided when certFile is specified") raise Exception("A certificate key file must be provided when certFile is specified") - self.session.rejectUnauthorized = props.get("rejectUnauthorized") + self.session.reject_unauthorized = props.get("rejectUnauthorized") self.session.type = session_constants.AUTH_TYPE_CERT_PEM else: self.session.type = session_constants.AUTH_TYPE_NONE @@ -86,10 +86,10 @@ def __init__(self, props: dict) -> None: # raise Exception("An authentication method must be supplied") # set additional parameters - self.session.basePath = props.get("basePath") + self.session.base_path = props.get("basePath") self.session.port = props.get("port", self.session.port) self.session.protocol = props.get("protocol", self.session.protocol) - self.session.rejectUnauthorized = False if props.get("rejectUnauthorized") == False else True + self.session.reject_unauthorized = False if props.get("rejectUnauthorized") == False else True def load(self) -> ISession: """ @@ -112,5 +112,5 @@ def host_url(self) -> str: str the formatted host URL """ - basePath = self.session.basePath or "" - return f"{self.session.protocol}://{self.session.host}:{self.session.port}{basePath}" + base_path = self.session.base_path or "" + return f"{self.session.protocol}://{self.session.host}:{self.session.port}{base_path}" diff --git a/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py b/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py index c940da6d..bbbddb2d 100644 --- a/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py +++ b/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py @@ -46,7 +46,7 @@ class ZosmfProfile: def __init__(self, profile_name: str): self.__profile_name = profile_name - self.__logger = Log.registerLogger(__name__) + self.__logger = Log.register_logger(__name__) @property def profiles_dir(self) -> str: diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py index d91bf07a..d0713d5d 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py @@ -158,11 +158,11 @@ def delete_data_set(self, dataset_name, volume=None, member_name=None): """Use ds.delete() instead of this deprecated function.""" return self.ds.delete(dataset_name, volume, member_name) - def create_zFS_file_system(self, file_system_name, options={}): + def create_zfs_file_system(self, file_system_name, options={}): """Use fs.create() instead of this deprecated function.""" return self.fs.create(file_system_name, options) - def delete_zFS_file_system(self, file_system_name): + def delete_zfs_file_system(self, file_system_name): """Use fs.delete() instead of this deprecated function.""" return self.fs.delete(file_system_name) diff --git a/tests/integration/test_zos_files.py b/tests/integration/test_zos_files.py index dd7d42cc..8e68d1f3 100644 --- a/tests/integration/test_zos_files.py +++ b/tests/integration/test_zos_files.py @@ -115,7 +115,7 @@ def test_mount_unmount_zfs_file_system(self): mount_point = self.files_fixtures["TEST_USS_MOUNT"] # Create a zfs file system - zfs_file_system = self.files.create_zFS_file_system(self.test2_zfs_file_system, self.create_zfs_options) + zfs_file_system = self.files.create_zfs_file_system(self.test2_zfs_file_system, self.create_zfs_options) # Mount file system command_output = self.files.mount_file_system( @@ -132,7 +132,7 @@ def test_mount_unmount_zfs_file_system(self): self.assertTrue(command_output == "") # Delete file system - command_output = self.files.delete_zFS_file_system(self.test2_zfs_file_system) + command_output = self.files.delete_zfs_file_system(self.test2_zfs_file_system) self.assertTrue(command_output == "") def test_upload_download_delete_dataset(self): diff --git a/tests/unit/core/test_logger.py b/tests/unit/core/test_logger.py index f7f7ba35..0fe1f05c 100644 --- a/tests/unit/core/test_logger.py +++ b/tests/unit/core/test_logger.py @@ -11,13 +11,13 @@ class test_logger_setLoggerLevel(TestCase): def test_logger_setLoggerLevel(self): """Test setLoggerLevel""" - test_logger = Log.registerLogger("test") + test_logger = Log.register_logger("test") test_value = logging.DEBUG - Log.setAllLoggerLevel(test_value) + Log.set_all_logger_level(test_value) self.assertEqual(test_logger.level, test_value) def test_single_logger(self): - test_logger = Log.registerLogger("test") + test_logger = Log.register_logger("test") # logger.Log.close(test_logger.name) with self.assertLogs(test_logger.name, level="WARNING") as log: Log.close(test_logger) @@ -29,12 +29,12 @@ def test_single_logger(self): self.assertIn("hi", log.output[0]) def test_all_loggers(self): - test_1 = Log.registerLogger("1") - test_2 = Log.registerLogger("2") + test_1 = Log.register_logger("1") + test_2 = Log.register_logger("2") with self.assertLogs(test_1.name, level="WARNING") as log1, self.assertLogs( test_2.name, level="WARNING" ) as log2: - Log.closeAll() + Log.close_all() test_1.error("hi") self.assertEqual(0, len(log1.output)) @@ -42,7 +42,7 @@ def test_all_loggers(self): test_2.error("hi") self.assertEqual(0, len(log2.output)) - Log.openAll() + Log.open_all() test_1.error("hi") self.assertIn("hi", log1.output[0]) diff --git a/tests/unit/files/file_systems/test_file_systems.py b/tests/unit/files/file_systems/test_file_systems.py index 9e49596b..1badb1b9 100644 --- a/tests/unit/files/file_systems/test_file_systems.py +++ b/tests/unit/files/file_systems/test_file_systems.py @@ -1,8 +1,9 @@ """Unit tests for the Zowe Python SDK z/OS Files package.""" + import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets +from zowe.zos_files_for_zowe_sdk import Datasets, Files, exceptions class TestFilesClass(TestCase): @@ -19,27 +20,27 @@ def setUp(self): } @mock.patch("requests.Session.send") - def test_create_zFS_file_system(self, mock_send_request): + def test_create_zfs_file_system(self, mock_send_request): """Test creating a zfs sends a request""" mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=201) - Files(self.test_profile).create_zFS_file_system( + Files(self.test_profile).create_zfs_file_system( "file_system_name", {"perms": 100, "cylsPri": 16777213, "cylsSec": 16777215} ) mock_send_request.assert_called_once() @mock.patch("requests.Session.send") - def test_delete_zFS_file_system(self, mock_send_request): + def test_delete_zfs_file_system(self, mock_send_request): """Test deleting a zfs sends a request""" mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=204) - Files(self.test_profile).delete_zFS_file_system("file_system_name") + Files(self.test_profile).delete_zfs_file_system("file_system_name") mock_send_request.assert_called_once() def test_invalid_permission(self): """Test that the correct exception is raised when an invalid permission option is provided""" with self.assertRaises(exceptions.InvalidPermsOption) as e_info: - Files(self.test_profile).create_zFS_file_system( + Files(self.test_profile).create_zfs_file_system( "file_system_name", {"perms": -1, "cylsPri": 16777213, "cylsSec": 16777215} ) self.assertEqual(str(e_info.exception), "Invalid zos-files create command 'perms' option: -1") @@ -47,7 +48,7 @@ def test_invalid_permission(self): def test_invalid_memory_allocation(self): """Test that the correct exception is raised when an invalid memory allocation option is provided""" with self.assertRaises(exceptions.MaxAllocationQuantityExceeded) as e_info: - Files(self.test_profile).create_zFS_file_system( + Files(self.test_profile).create_zfs_file_system( "file_system_name", {"perms": 775, "cylsPri": 1677755513, "cylsSec": 16777215} ) self.assertEqual(str(e_info.exception), "Maximum allocation quantity of 16777215 exceeded") @@ -66,4 +67,4 @@ def test_unmount_zFS_file_system(self, mock_send_request): mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=204) Files(self.test_profile).unmount_file_system("file_system_name") - mock_send_request.assert_called_once() \ No newline at end of file + mock_send_request.assert_called_once() From 9b16a4a0dff5f75480c83f45bb80280452ede227 Mon Sep 17 00:00:00 2001 From: pem70 Date: Thu, 18 Jul 2024 13:08:58 -0400 Subject: [PATCH 02/12] Update CHANGELOG.md Signed-off-by: pem70 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5c023b1..ec8b9312 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil - Add type annotations for all methods [#280] (https://github.com/zowe/zowe-client-python-sdk/issues/280) +- *Breaking*: Revised function names in `Logger` class and `files` class into snake_case. Supported for function case enforcer [#315] (https://github.com/zowe/zowe-client-python-sdk/issues/315) + ### Bug Fixes - Fixed a bug on `create` in `Datasets` where the target dataset gets created with a different block size when `like` is specified [#295] (https://github.com/zowe/zowe-client-python-sdk/issues/295) From 3579a21b1f5b9e31fd9c1975d91780ae1988fe61 Mon Sep 17 00:00:00 2001 From: pem70 Date: Thu, 18 Jul 2024 13:11:13 -0400 Subject: [PATCH 03/12] Update requirements.txt Signed-off-by: pem70 --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 45680bbd..51990d48 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,6 +20,7 @@ pydoclint==0.5.3 pyfakefs pyflakes==2.5.0 pylama==7.7.1 +pylint==3.2.5 pytest==7.1.2 python-decouple==3.4 PyYAML==6.0.1 From dddb3dbe59b9771e1176a9bffce3ea809ee36562 Mon Sep 17 00:00:00 2001 From: pem70 Date: Thu, 18 Jul 2024 13:19:21 -0400 Subject: [PATCH 04/12] Update requirements.txt Signed-off-by: pem70 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 51990d48..c4864b33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,7 @@ pydoclint==0.5.3 pyfakefs pyflakes==2.5.0 pylama==7.7.1 -pylint==3.2.5 +pylint==3.0.1 pytest==7.1.2 python-decouple==3.4 PyYAML==6.0.1 From e8f723deb4cb23d6f54fa80f2f8328054c104957 Mon Sep 17 00:00:00 2001 From: pem70 Date: Thu, 18 Jul 2024 13:23:13 -0400 Subject: [PATCH 05/12] Update requirements.txt Signed-off-by: pem70 --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index c4864b33..1c466358 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ black certifi==2024.7.4 chardet==4.0.0 -colorama==0.4.4 +colorama==0.4.5 commentjson==0.9.0 coverage==5.4 deepmerge==1.1.0 @@ -20,7 +20,7 @@ pydoclint==0.5.3 pyfakefs pyflakes==2.5.0 pylama==7.7.1 -pylint==3.0.1 +pylint==3.2.5 pytest==7.1.2 python-decouple==3.4 PyYAML==6.0.1 From 97e2599cc865255b27ad7dd23306a60ea98ebae2 Mon Sep 17 00:00:00 2001 From: pem70 Date: Fri, 19 Jul 2024 10:40:39 -0400 Subject: [PATCH 06/12] Update test_logger.py Signed-off-by: pem70 --- tests/unit/core/test_logger.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unit/core/test_logger.py b/tests/unit/core/test_logger.py index 94d067e1..59702d22 100644 --- a/tests/unit/core/test_logger.py +++ b/tests/unit/core/test_logger.py @@ -2,8 +2,6 @@ # Including necessary paths import logging -import os -from unittest import mock from pyfakefs.fake_filesystem_unittest import TestCase from zowe.core_for_zowe_sdk.logger import Log @@ -57,7 +55,7 @@ def test_all_loggers(self): def test_console_handler(self): Log.close_console_output() - test = Log.registerLogger("test") + test = Log.register_logger("test") self.assertEqual(test.handlers[0], Log.file_handler) Log.open_console_output() @@ -68,7 +66,7 @@ def test_console_handler(self): def test_file_handler(self): Log.close_file_output() - test = Log.registerLogger("test") + test = Log.register_logger("test") self.assertEqual(test.handlers[0], Log.console_handler) Log.open_file_output() From 2f964689799e9fa7e5661377aa4c18e61410e36c Mon Sep 17 00:00:00 2001 From: Peizhao Mei <105866197+pem70@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:14:45 -0400 Subject: [PATCH 07/12] Update CHANGELOG.md Co-authored-by: Trae Yelovich Signed-off-by: Peizhao Mei <105866197+pem70@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 681815aa..0f172fbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil - Add type annotations for all methods [#280] (https://github.com/zowe/zowe-client-python-sdk/issues/280) -- *Breaking*: Revised function names in `Logger` class and `files` class into snake_case. Supported for function case enforcer [#315] (https://github.com/zowe/zowe-client-python-sdk/issues/315) +- *Breaking*: Revised function names in `Logger` class and `files` class into snake_case. Enabled pylint rule to enforce function case. [#315] (https://github.com/zowe/zowe-client-python-sdk/issues/315) ### Bug Fixes From 58800e2223ea21b786fc2ca953d02391bdcb933c Mon Sep 17 00:00:00 2001 From: pem70 Date: Mon, 22 Jul 2024 14:25:11 -0400 Subject: [PATCH 08/12] Replace flake8 with pylint Signed-off-by: pem70 --- .github/workflows/sdk-build.yml | 12 +++---- requirements.txt | 1 - .../zowe/core_for_zowe_sdk/profile_manager.py | 36 +++++++++++-------- .../zowe/core_for_zowe_sdk/request_handler.py | 4 ++- .../zowe/zos_files_for_zowe_sdk/datasets.py | 1 - .../zowe/zos_jobs_for_zowe_sdk/jobs.py | 18 ++++++---- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/.github/workflows/sdk-build.yml b/.github/workflows/sdk-build.yml index 9bf6caac..895a608d 100644 --- a/.github/workflows/sdk-build.yml +++ b/.github/workflows/sdk-build.yml @@ -33,13 +33,11 @@ jobs: - name: Lint with pydoclint run: pydoclint --exclude='.*/build/.*' src - name: Lint with pylint - run: pylint src --disable=all --enable=C0103 --ignore=build - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 ./src --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 ./src --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + run: | + # check for Python errors + pylint src --errors-only --disable=E0401,E0611 --ignore=build + # check for lint + pylint ./src --disable=all --enable=C0103,C0301 --ignore=build --max-line-length=127 - name: Test with pytest run: | coverage run -m pytest ./tests/unit diff --git a/requirements.txt b/requirements.txt index 1c466358..ede98bc3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,6 @@ colorama==0.4.5 commentjson==0.9.0 coverage==5.4 deepmerge==1.1.0 -flake8==5.0.0 idna==3.7 importlib-metadata==3.6.0;python_version<"3.8" isort diff --git a/src/core/zowe/core_for_zowe_sdk/profile_manager.py b/src/core/zowe/core_for_zowe_sdk/profile_manager.py index a48c1eaa..172823c1 100644 --- a/src/core/zowe/core_for_zowe_sdk/profile_manager.py +++ b/src/core/zowe/core_for_zowe_sdk/profile_manager.py @@ -16,8 +16,14 @@ from copy import deepcopy from typing import Optional -import jsonschema from deepmerge import always_merger +from jsonschema.exceptions import ( + FormatError, + SchemaError, + UndefinedTypeCheck, + UnknownType, + ValidationError, +) from .config_file import ConfigFile, Profile from .credential_manager import CredentialManager @@ -268,25 +274,25 @@ def get_profile( cfg_profile = cfg.get_profile( profile_name=profile_name, profile_type=profile_type, validate_schema=validate_schema ) - except jsonschema.exceptions.ValidationError as exc: + except ValidationError as exc: logger.error(f"Instance was invalid under the provided $schema property, {exc}") - raise jsonschema.exceptions.ValidationError( - f"Instance was invalid under the provided $schema property, {exc}" - ) - except jsonschema.exceptions.SchemaError as exc: + raise ValidationError(f"Instance was invalid under the provided $schema property, {exc}") + except SchemaError as exc: logger.error(f"The provided schema is invalid, {exc}") - raise jsonschema.exceptions.SchemaError(f"The provided schema is invalid, {exc}") - except jsonschema.exceptions.UndefinedTypeCheck as exc: + raise SchemaError(f"The provided schema is invalid, {exc}") + except UndefinedTypeCheck as exc: logger.error(f"A type checker was asked to check a type it did not have registered, {exc}") - raise jsonschema.exceptions.UndefinedTypeCheck( - f"A type checker was asked to check a type it did not have registered, {exc}" - ) - except jsonschema.exceptions.UnknownType as exc: + raise UndefinedTypeCheck(f"A type checker was asked to check a type it did not have registered, {exc}") + except UnknownType as exc: logger.error(f"Unknown type is found in schema_json, {exc}") - raise jsonschema.exceptions.UnknownType(f"Unknown type is found in schema_json, {exc}") - except jsonschema.exceptions.FormatError as exc: + raise UnknownType( + f"Unknown type is found in schema_json, {exc}", + instance=profile_name, + schema=validate_schema, + ) + except FormatError as exc: logger.error(f"Validating a format config_json failed for schema_json, {exc}") - raise jsonschema.exceptions.FormatError(f"Validating a format config_json failed for schema_json, {exc}") + raise FormatError(f"Validating a format config_json failed for schema_json, {exc}") except ProfileNotFound: if profile_name: logger.warning(f"Profile '{profile_name}' not found in file '{cfg.filename}'") diff --git a/src/core/zowe/core_for_zowe_sdk/request_handler.py b/src/core/zowe/core_for_zowe_sdk/request_handler.py index 5853d82f..e36aafec 100644 --- a/src/core/zowe/core_for_zowe_sdk/request_handler.py +++ b/src/core/zowe/core_for_zowe_sdk/request_handler.py @@ -121,7 +121,9 @@ def __validate_response(self): if self.__response.ok: if self.__response.status_code not in self.__expected_code: self.__logger.error( - f"The status code from z/OSMF was: {self.__expected_code}\nExpected: {self.__response.status_code}\nRequest output:{self.__response.text}" + f"The status code from z/OSMF was: {self.__expected_code}\n" + f"Expected: {self.__response.status_code}\n" + f"Request output: {self.__response.text}" ) raise UnexpectedStatus(self.__expected_code, self.__response.status_code, self.__response.text) else: diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py index 376ac89e..bd942e29 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py @@ -21,7 +21,6 @@ _ZOWE_FILES_DEFAULT_ENCODING = zos_file_constants["ZoweFilesDefaultEncoding"] -@dataclass class DatasetOption: """A dataclass that represents options for creating a dataset. diff --git a/src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py b/src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py index 8c6ebe16..b73b4f13 100644 --- a/src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py +++ b/src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py @@ -65,7 +65,8 @@ def cancel_job(self, jobname: str, jobid: str, modify_version: str = "2.0") -> d jobid: str The job id on JES modify_version: str - Default ("2.0") specifies that the request is to be processed synchronously. For asynchronous processing - change the value to "1.0" + Default ("2.0") specifies that the request is to be processed synchronously. + For asynchronous processing - change the value to "1.0" Raises ------ @@ -101,7 +102,8 @@ def delete_job(self, jobname: str, jobid: str, modify_version: str = "2.0") -> d jobid: str The job id on JES modify_version: str - Default ("2.0") specifies that the request is to be processed synchronously. For asynchronous processing - change the value to "1.0" + Default ("2.0") specifies that the request is to be processed synchronously. + For asynchronous processing - change the value to "1.0" Raises ------ @@ -139,7 +141,8 @@ def _issue_job_request(self, req: dict, jobname: str, jobid: str, modify_version jobid: str The job id on JES modify_version: str - "2.0" specifies that the request is to be processed synchronously. For asynchronous processing - change the value to "1.0" + "2.0" specifies that the request is to be processed synchronously. + For asynchronous processing - change the value to "1.0" Returns ------- @@ -170,7 +173,8 @@ def change_job_class(self, jobname: str, jobid: str, class_name: str, modify_ver class_name: str The name of class to be set to modify_version: str - Default ("2.0") specifies that the request is to be processed synchronously. For asynchronous processing - change the value to "1.0" + Default ("2.0") specifies that the request is to be processed synchronously. + For asynchronous processing - change the value to "1.0" Raises ------ @@ -200,7 +204,8 @@ def hold_job(self, jobname: str, jobid: str, modify_version: str = "2.0") -> dic jobid: str The job id on JES modify_version: str - Default ("2.0") specifies that the request is to be processed synchronously. For asynchronous processing - change the value to "1.0" + Default ("2.0") specifies that the request is to be processed synchronously. + For asynchronous processing - change the value to "1.0" Raises ------ @@ -230,7 +235,8 @@ def release_job(self, jobname: str, jobid: str, modify_version: str = "2.0") -> jobid: str The job id on JES modify_version: str - Default ("2.0") specifies that the request is to be processed synchronously. For asynchronous processing - change the value to "1.0" + Default ("2.0") specifies that the request is to be processed synchronously. + For asynchronous processing - change the value to "1.0" Raises ------ From 69cdd6283db9aa6958fc8bfb427608b16003cfd3 Mon Sep 17 00:00:00 2001 From: pem70 Date: Mon, 22 Jul 2024 14:27:28 -0400 Subject: [PATCH 09/12] Update datasets.py Signed-off-by: pem70 --- src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py index bd942e29..f1f4564d 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py @@ -285,11 +285,6 @@ def like(self) -> Optional[str]: """Get the dataset name to copy attributes from.""" return self.__like - @like.setter - def like(self, like: Optional[str]): - """Set the dataset name to copy attributes from.""" - self.__like = like - def to_dict(self) -> dict: """Return the DatasetOption as a dict.""" return {key.replace("_DatasetOption__", ""): value for key, value in self.__dict__.items() if value is not None} From 1b5a773cc4063bd853bf734b75be35c26b9729d8 Mon Sep 17 00:00:00 2001 From: pem70 Date: Mon, 22 Jul 2024 14:44:53 -0400 Subject: [PATCH 10/12] Update requirements.txt Signed-off-by: pem70 --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ede98bc3..24de5c62 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,6 @@ pycodestyle==2.9.0 pydocstyle==5.1.1 pydoclint==0.5.3 pyfakefs -pyflakes==2.5.0 pylama==7.7.1 pylint==3.2.5 pytest==7.1.2 From 9cd2b2a3c8769cdd2536fdd811f3756d3211f93e Mon Sep 17 00:00:00 2001 From: pem70 Date: Mon, 22 Jul 2024 14:47:00 -0400 Subject: [PATCH 11/12] Update settings.json Signed-off-by: pem70 --- .vscode/settings.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index b378a106..fe2a97f8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,4 +19,6 @@ "./src/zos_jobs", "./src/zosmf" ], + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, } From 4f44ed61151de8d23720603d1bc8fdf2d6f6f4cb Mon Sep 17 00:00:00 2001 From: pem70 Date: Mon, 22 Jul 2024 15:04:43 -0400 Subject: [PATCH 12/12] Update CONTRIBUTING.md Signed-off-by: pem70 --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6ac66f87..fa15ff35 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,6 +65,6 @@ Code standards This project follows the [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guide. -This project also uses `flake8` for code linting. Make sure to run `flake8` on your code before submitting a pull request. +This project also uses `pydocstyle`, `pydoclint`, and `pylint` for code linting. Make sure to run them on your code before submitting a pull request. We recommend using `black` and `isort` as code formatters. Please format your code using these tools before creating a pull request.