From 8da47f5784f41e521b0665ae269e01b7d38e97fa Mon Sep 17 00:00:00 2001 From: donhui <977675308@qq.com> Date: Sat, 10 Sep 2022 11:38:00 +0800 Subject: [PATCH 1/5] support python 3.11 --- .github/workflows/ci.yml | 4 ++-- artifactory.py | 22 +++++++++++++++++++++- setup.py | 1 + tox.ini | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be1c40e7..6c709b32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,14 +14,14 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] + python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11-dev'] steps: - uses: actions/checkout@v1 with: fetch-depth: 1 - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} diff --git a/artifactory.py b/artifactory.py index bfec2dd5..095c9357 100755 --- a/artifactory.py +++ b/artifactory.py @@ -640,7 +640,17 @@ def __iter__(self): return self.iterator -class _ArtifactoryAccessor(pathlib._Accessor): +_artifactory_access_parent_class = None +try: + _artifactory_access_parent_class = pathlib._Accessor +except AttributeError: + _artifactory_access_parent_class = ( + pathlib.WindowsPath if os.name == "nt" else pathlib.PosixPath + ) + + +class _ArtifactoryAccessor(_artifactory_access_parent_class): + """ Implements operations with Artifactory REST API """ @@ -1897,6 +1907,16 @@ def lchmod(self, mode): """ raise NotImplementedError() + def unlink(self, missing_ok=False): + """ + Removes a file or folder + """ + try: + self._accessor.unlink(self) + except ArtifactoryException: + if not missing_ok: + raise + def symlink_to(self, target, target_is_directory=False): """ Throw NotImplementedError diff --git a/setup.py b/setup.py index 37d18f4a..b748e24e 100755 --- a/setup.py +++ b/setup.py @@ -46,6 +46,7 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Topic :: Software Development :: Libraries", "Topic :: System :: Filesystems", ], diff --git a/tox.ini b/tox.ini index bb776255..224e13f4 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ envlist = py38 py39 py310 + py311 pre-commit [testenv] From fb2ebc59be39cbf2a31b2bd7aca98adcf17faf8f Mon Sep 17 00:00:00 2001 From: donghui <977675308@qq.com> Date: Sat, 10 Sep 2022 21:56:12 +0800 Subject: [PATCH 2/5] Update artifactory.py Co-authored-by: Maksim Beliaev --- artifactory.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/artifactory.py b/artifactory.py index 095c9357..879941ad 100755 --- a/artifactory.py +++ b/artifactory.py @@ -640,11 +640,7 @@ def __iter__(self): return self.iterator -_artifactory_access_parent_class = None -try: - _artifactory_access_parent_class = pathlib._Accessor -except AttributeError: - _artifactory_access_parent_class = ( +_artifactory_access_parent_class = ( pathlib.WindowsPath if os.name == "nt" else pathlib.PosixPath ) From 051b142680b3dd9fc22f6d40f799c23da04c6469 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 10 Sep 2022 13:56:21 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- artifactory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/artifactory.py b/artifactory.py index 879941ad..af1dbdf9 100755 --- a/artifactory.py +++ b/artifactory.py @@ -641,8 +641,8 @@ def __iter__(self): _artifactory_access_parent_class = ( - pathlib.WindowsPath if os.name == "nt" else pathlib.PosixPath - ) + pathlib.WindowsPath if os.name == "nt" else pathlib.PosixPath +) class _ArtifactoryAccessor(_artifactory_access_parent_class): From a937b755f98f2d6bb6b8c38a14145d394135bf05 Mon Sep 17 00:00:00 2001 From: donhui <977675308@qq.com> Date: Sun, 11 Sep 2022 20:21:31 +0800 Subject: [PATCH 4/5] remove base class for `_ArtifactoryAccessor` --- artifactory.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/artifactory.py b/artifactory.py index af1dbdf9..ec0fb142 100755 --- a/artifactory.py +++ b/artifactory.py @@ -640,12 +640,7 @@ def __iter__(self): return self.iterator -_artifactory_access_parent_class = ( - pathlib.WindowsPath if os.name == "nt" else pathlib.PosixPath -) - - -class _ArtifactoryAccessor(_artifactory_access_parent_class): +class _ArtifactoryAccessor: """ Implements operations with Artifactory REST API From 67a4bd48422450147917dd3459a8eb860c4038b7 Mon Sep 17 00:00:00 2001 From: donhui <977675308@qq.com> Date: Sun, 11 Sep 2022 20:36:11 +0800 Subject: [PATCH 5/5] use FileNotFoundError for unlink --- artifactory.py | 4 ++-- tests/unit/test_artifactory_path.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/artifactory.py b/artifactory.py index ec0fb142..f12e6b33 100755 --- a/artifactory.py +++ b/artifactory.py @@ -999,7 +999,7 @@ def unlink(self, pathobj): """ if not pathobj.exists(): - raise OSError(2, f"No such file or directory: {pathobj}") + raise FileNotFoundError(2, f"No such file or directory: {pathobj}") url = "/".join( [ @@ -1904,7 +1904,7 @@ def unlink(self, missing_ok=False): """ try: self._accessor.unlink(self) - except ArtifactoryException: + except FileNotFoundError: if not missing_ok: raise diff --git a/tests/unit/test_artifactory_path.py b/tests/unit/test_artifactory_path.py index 6454f258..e8d5c69a 100644 --- a/tests/unit/test_artifactory_path.py +++ b/tests/unit/test_artifactory_path.py @@ -801,7 +801,7 @@ def test_unlink_raises_not_found(self): status=404, body="Unable to find item", ) - with self.assertRaises(OSError) as context: + with self.assertRaises(FileNotFoundError) as context: path.unlink() self.assertTrue("No such file or directory" in context.exception.strerror)