Skip to content

Commit

Permalink
Fix linter issues, move all IS_PYTHON_* to compat.py, explicit import
Browse files Browse the repository at this point in the history
  • Loading branch information
allburov committed Jan 16, 2025
1 parent 27d86fe commit 46728f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
15 changes: 6 additions & 9 deletions artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion dohq_artifactory/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions dohq_artifactory/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 46728f6

Please sign in to comment.