From 46728f67725433e06141b5dc36239edf0b614c49 Mon Sep 17 00:00:00 2001 From: allburov Date: Thu, 16 Jan 2025 15:20:50 +0700 Subject: [PATCH] Fix linter issues, move all IS_PYTHON_* to compat.py, explicit import --- artifactory.py | 15 ++++++--------- dohq_artifactory/admin.py | 3 ++- dohq_artifactory/compat.py | 4 ++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/artifactory.py b/artifactory.py index a8ef568..0c4b63c 100755 --- a/artifactory.py +++ b/artifactory.py @@ -51,7 +51,9 @@ from dohq_artifactory.admin import User from dohq_artifactory.auth import XJFrogArtApiAuth from dohq_artifactory.auth import XJFrogArtBearerAuth -from dohq_artifactory.compat import * # noqa: this helper only contains version flags +from dohq_artifactory.compat import IS_PYTHON_2 +from dohq_artifactory.compat import IS_PYTHON_3_10_OR_NEWER +from dohq_artifactory.compat import IS_PYTHON_3_12_OR_NEWER from dohq_artifactory.exception import ArtifactoryException from dohq_artifactory.exception import raise_for_status from dohq_artifactory.logger import logger @@ -73,11 +75,6 @@ default_config_path = "~/.artifactory_python.cfg" global_config = None -# Pathlib.Path changed significantly in 3.12, so we will not need several -# parts of the code once python3.11 is no longer supported. This constant helps -# identifying those. -_IS_PYTHON_3_12_OR_NEWER = sys.version_info >= (3, 12) - def read_config(config_path=default_config_path): """ @@ -429,7 +426,7 @@ def quote_url(url): return quoted_url -class _ArtifactoryFlavour(object if _IS_PYTHON_3_12_OR_NEWER else pathlib._Flavour): +class _ArtifactoryFlavour(object if IS_PYTHON_3_12_OR_NEWER else pathlib._Flavour): """ Implements Artifactory-specific pure path manipulations. I.e. what is 'drive', 'root' and 'path' and how to split full path into @@ -1554,7 +1551,7 @@ def __new__(cls, *args, **kwargs): """ obj = pathlib.Path.__new__(cls, *args, **kwargs) - if _IS_PYTHON_3_12_OR_NEWER: + if IS_PYTHON_3_12_OR_NEWER: # After python 3.12, all this logic can be moved to __init__ return obj @@ -1611,7 +1608,7 @@ def _init(self, *args, **kwargs): def __init__(self, *args, **kwargs): # Up until python3.12, pathlib.Path was not designed to be initialized # through __init__, so all that logic is in the __new__ method. - if not _IS_PYTHON_3_12_OR_NEWER: + if not IS_PYTHON_3_12_OR_NEWER: return super().__init__(*args, **kwargs) diff --git a/dohq_artifactory/admin.py b/dohq_artifactory/admin.py index 9a515d1..bb1ca44 100644 --- a/dohq_artifactory/admin.py +++ b/dohq_artifactory/admin.py @@ -8,7 +8,8 @@ import jwt from dateutil.parser import isoparse -from dohq_artifactory.compat import * # noqa: this helper only contains version flags +from dohq_artifactory.compat import IS_PYTHON_2 +from dohq_artifactory.compat import IS_PYTHON_3_6_OR_NEWER from dohq_artifactory.exception import ArtifactoryException from dohq_artifactory.exception import raise_for_status from dohq_artifactory.logger import logger diff --git a/dohq_artifactory/compat.py b/dohq_artifactory/compat.py index cb4925c..d6ce8c7 100644 --- a/dohq_artifactory/compat.py +++ b/dohq_artifactory/compat.py @@ -5,3 +5,7 @@ # see changes in pathlib.Path, slots are no more applied # https://github.com/python/cpython/blob/ce121fd8755d4db9511ce4aab39d0577165e118e/Lib/pathlib.py#L952 IS_PYTHON_3_10_OR_NEWER = sys.version_info >= (3, 10) +# Pathlib.Path changed significantly in 3.12, so we will not need several +# parts of the code once python3.11 is no longer supported. This constant helps +# identifying those. +IS_PYTHON_3_12_OR_NEWER = sys.version_info >= (3, 12)