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

Function case #317

Merged
merged 16 commits into from
Jul 23, 2024
Merged
2 changes: 2 additions & 0 deletions .github/workflows/sdk-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

If we're adopting pylint then should we remove all references to flakes8 rather than having a mix of both?

  • Remove step that runs flake8 in this workflow
  • Remove pyflakes dependency from requirements.txt
  • Update .vscode/settings.json to include setting that enables Pylint in VS Code
  • Replace flakes8 with pylint in "Code Standards" section of CONTRIBUTING.md

Copy link
Member

@traeok traeok Jul 22, 2024

Choose a reason for hiding this comment

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

I definitely think this is worth considering, but in the interest of avoiding scope creep, maybe this can be created as a separate issue?

Update: Sorry, didn't realize that pylint was not in the codebase before this PR. If there is a flake8 rule we could use, we should leverage what's already in the dependencies instead - otherwise, maybe we can create an issue to remove flake8 if there isn't another use for it.

Copy link
Member

@zFernand0 zFernand0 Jul 22, 2024

Choose a reason for hiding this comment

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

I'll leave it up to @pem70 to handle that issue as part of this PR or as part of a new one 😋

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will handle this as part of this PR

run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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)
pem70 marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

## `1.0.0-dev18`
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/zowe/core_for_zowe_sdk/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/core/zowe/core_for_zowe_sdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/core/zowe/core_for_zowe_sdk/credential_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/core/zowe/core_for_zowe_sdk/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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.

Expand All @@ -68,7 +68,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.

Expand Down Expand Up @@ -107,13 +107,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
Expand Down
12 changes: 6 additions & 6 deletions src/core/zowe/core_for_zowe_sdk/profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions src/core/zowe/core_for_zowe_sdk/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/core/zowe/core_for_zowe_sdk/sdk_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -52,17 +52,17 @@ 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)

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

Expand Down
28 changes: 14 additions & 14 deletions src/core/zowe/core_for_zowe_sdk/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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"))
Expand All @@ -63,33 +63,33 @@ 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"):
self.session.cert = (props.get("certFile"), props.get("certKeyFile"))
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
self.__logger.info("Authentication method not supplied")
# 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:
"""
Expand All @@ -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}"
2 changes: 1 addition & 1 deletion src/core/zowe/core_for_zowe_sdk/zosmf_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/zos_files/zowe/zos_files_for_zowe_sdk/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_zos_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down
20 changes: 9 additions & 11 deletions tests/unit/core/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,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)
Expand All @@ -31,20 +29,20 @@ 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))

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])
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Loading
Loading