devopshq / artifactory

dohq-artifactory: a Python client for Artifactory
https://devopshq.github.io/artifactory/
MIT License
273 stars 144 forks source link

Add follow_symlinks argument to ArtifactoryPath.is_dir #440

Closed zhan9san closed 7 months ago

zhan9san commented 8 months ago

https://github.com/devopshq/artifactory/issues/432#issuecomment-1756275808

zhan9san commented 7 months ago

@barneygale

I understand your point. To avoid any misunderstanding, please allow me to leave more detailed information here.

follow_symlinks

Python <= 3.11.3, there is no follow_symlinks=False passed to entry.is_dir in _RecursiveWildcardSelector._iterate_directories

Python > 3.11.3, follow_symlinks=False is introduced when we use glob feature.

Let's see follow_symlinks change history in glob feature.

In Python 3.11.4-3.11.7, the follow_symlinks is explicitly set to False in pathlib._RecursiveWildcardSelector._iterate_directories.

In Python 3.12.0-3.12.2, the follow_symlinks is also explicitly set to False, but in pathlib.walk which is invoked in pathlib._RecursiveWildcardSelector._iterate_directories.

In Python latest(2/8/2024) main branch, pathlib is removed, pathlib._abc is introduced, and follow_symlinks=None is set to None in pathlib._abc.glob.

is_dir

In pathlib, it is is_dir in Modules/posixmodule.c is used if we use glob(instance of DirEntry) all the time(~3.11.3 - latest main branch), while is_dir in pathlib/_abc.py is used if glob is not used(instance of Path)

As the default value of follow_symlinks changes, it is better to ignore variable follow_symlinks in is_dir as Artifactory does not use it.

In Artifactory, we use the same is_dir no matter glob is used or not.

In Path class, the glob function is using os.scan, and it's a posix.DirEntry instance not Path instance, so it will use the method in Modules/posixmodule.c instead of pathlib/_abc.py.

In ArtifactoryPath class, there is no specific DirEntry-like class.


Please correct me if I say anything wrong

barneygale commented 7 months ago

That seems broadly correct.

In Python latest(2/8/2024) main branch, pathlib is removed, pathlib._abc is introduced, and follow_symlinks=None is set to None in pathlib._abc.glob.

Path.glob(follow_symlinks=None) is legacy behaviour that I'm intending to deprecate in Python 3.15 and remove in Python 3.17. It means "follow symlinks, except when expanding ** wildcards".

I'll change the default value to True in PathBase.glob() shortly.

is_dir() only accepts True and False for _followsymlinks

In ArtifactoryPath class, there is no specific DirEntry-like class.

ArtifactoryPath is itself the DirEntry-like class. If you make ArtifactoryPath inherit from pathlib_abc.PathBase and implement iterdir() and stat() (or is_dir()), globbing should just work.