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

glob method broken in python 3.11 #396

Closed
sm-gravid-day opened this issue Nov 17, 2022 · 2 comments · Fixed by #424
Closed

glob method broken in python 3.11 #396

sm-gravid-day opened this issue Nov 17, 2022 · 2 comments · Fixed by #424
Labels
Bug Help Wanted We will be glad if somebody proposes a solution via PR

Comments

@sm-gravid-day
Copy link

The glob method is broken in python 3.11. I've tested the same code in 3.10.8 and all is fine, but looks like things have changed in 3.11...

from artifactory import ArtifactoryPath
rt_path = ArtifactoryPath(MY_ARTIFACTORY_PATH, apikey=MY_APIKEY)
print(len([p for p in rt_path]))  # all fine, but glob blows up...
next(rt_path.glob('**/manifest.json'))

Traceback (most recent call last):
  File "/src/./bug.py", line 9, in <module>
    next(rt_path.glob('**/manifest.json'))
  File "/usr/local/lib/python3.11/pathlib.py", line 953, in glob
    for p in selector.select_from(self):
  File "/usr/local/lib/python3.11/pathlib.py", line 407, in _select_from
    for starting_point in self._iterate_directories(parent_path, is_dir, scandir):
  File "/usr/local/lib/python3.11/pathlib.py", line 386, in _iterate_directories
    with scandir(parent_path) as scandir_it:
         ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/pathlib.py", line 938, in _scandir
    return os.scandir(self)
           ^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'my path set above ^^'
@allburov allburov added Bug Help Wanted We will be glad if somebody proposes a solution via PR labels Nov 21, 2022
@donhui
Copy link
Contributor

donhui commented Nov 29, 2022

I think the issue has something to do with this change:
pathlib._Accessor was removed from Python 3.11: python/cpython#25701

@allburov
Copy link
Member

allburov commented Dec 4, 2022

The _Accessor issue we (especially you, @donhui) have fixed in #376
Would be great if one look at this one too!

flichtenheld added a commit to flichtenheld/dohq_artifactory that referenced this issue Jul 19, 2023
Python 3.11 replaced _accessor.scandir with _scandir.
Override _scandir to still use our implementation.
Should be a noop on older Python versions because they
didn't have _scandir at all.

Fixes: devopshq#396

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
allburov pushed a commit that referenced this issue Jul 24, 2023
* ArtifactoryPath: fix mkdir and rmdir with Python 3.11

pathlib in Python 3.11 implements mkdir and rmdir directly
in terms of calling os.<func> without any accessor layer.
So copy the implementations of those functions from Python
3.10 to get the previous behavior back.

Fixes: #415

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>

* test_artifactory_path: Add basic unit test for mkdir()

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>

* ArtifactoryPath: Fix glob() in Python 3.11

Python 3.11 replaced _accessor.scandir with _scandir.
Override _scandir to still use our implementation.
Should be a noop on older Python versions because they
didn't have _scandir at all.

Fixes: #396

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>

---------

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Help Wanted We will be glad if somebody proposes a solution via PR
Development

Successfully merging a pull request may close this issue.

3 participants