Skip to content

Commit

Permalink
fix: support Python 3.12
Browse files Browse the repository at this point in the history
Apply path proposed in devopshq#430

See: devopshq#430
  • Loading branch information
okainov authored Nov 4, 2024
1 parent 42bb6f1 commit 560f3a4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def quote_url(url):
return quoted_url


class _ArtifactoryFlavour(pathlib._Flavour):
class _ArtifactoryFlavour():
"""
Implements Artifactory-specific pure path manipulations.
I.e. what is 'drive', 'root' and 'path' and how to split full path into
Expand All @@ -440,7 +440,6 @@ class _ArtifactoryFlavour(pathlib._Flavour):
sep = "/"
altsep = "/"
has_drv = True
pathmod = pathlib.posixpath
is_supported = True

def _get_base_url(self, url):
Expand Down Expand Up @@ -1501,10 +1500,16 @@ class ArtifactoryPath(pathlib.Path, PureArtifactoryPath):
# see changes in pathlib.Path, slots are no more applied
# https://github.com/python/cpython/blob/ce121fd8755d4db9511ce4aab39d0577165e118e/Lib/pathlib.py#L952
_accessor = _artifactory_accessor
parser = _ArtifactoryFlavour()
else:
# in 3.9 and below Pathlib limits what members can be present in 'Path' class
__slots__ = ("auth", "verify", "cert", "session", "timeout")


def __init__(self, *args, **kwargs):
# supplying keyword arguments to pathlib.PurePath is deprecated
return super().__init__(*args)

def __new__(cls, *args, **kwargs):
"""
pathlib.Path overrides __new__ in order to create objects
Expand All @@ -1514,6 +1519,10 @@ def __new__(cls, *args, **kwargs):
only then add auth information.
"""
obj = pathlib.Path.__new__(cls, *args, **kwargs)

if sys.version_info.major == 3 and sys.version_info.minor >= 12:
# supplying keyword arguments to pathlib.PurePath is deprecated
obj.__init__(*args)

cfg_entry = get_global_config_entry(obj.drive)

Expand Down

0 comments on commit 560f3a4

Please sign in to comment.