diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2024-06-23 17:06:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-23 17:06:07 (GMT) |
commit | 1ba0bb21ed4eb54023fdfccc9cb20be8fff946b1 (patch) | |
tree | 280369202a78e4b7be1b17274420763eded9eb64 /Lib | |
parent | 0b918e81c1de909f753f1d02bcba0f831d63cfa8 (diff) | |
download | cpython-1ba0bb21ed4eb54023fdfccc9cb20be8fff946b1.zip cpython-1ba0bb21ed4eb54023fdfccc9cb20be8fff946b1.tar.gz cpython-1ba0bb21ed4eb54023fdfccc9cb20be8fff946b1.tar.bz2 |
gh-120910: Fix issue resolving relative paths outside site-packages. (#120911)
Incorporates changes from importlib_metadata 7.2.1.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/importlib/metadata/__init__.py | 2 | ||||
-rw-r--r-- | Lib/test/test_importlib/metadata/fixtures.py | 34 | ||||
-rw-r--r-- | Lib/test/test_importlib/metadata/test_api.py | 1 |
3 files changed, 36 insertions, 1 deletions
diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py index 245f905..8ce62dd 100644 --- a/Lib/importlib/metadata/__init__.py +++ b/Lib/importlib/metadata/__init__.py @@ -567,7 +567,7 @@ class Distribution(DeprecatedNonAbstract): paths = ( (subdir / name) .resolve() - .relative_to(self.locate_file('').resolve()) + .relative_to(self.locate_file('').resolve(), walk_up=True) .as_posix() for name in text.splitlines() ) diff --git a/Lib/test/test_importlib/metadata/fixtures.py b/Lib/test/test_importlib/metadata/fixtures.py index 81ff678..826b1b3 100644 --- a/Lib/test/test_importlib/metadata/fixtures.py +++ b/Lib/test/test_importlib/metadata/fixtures.py @@ -234,6 +234,40 @@ class EggInfoPkgPipInstalledNoToplevel(OnSysPath, SiteBuilder): } +class EggInfoPkgPipInstalledExternalDataFiles(OnSysPath, SiteBuilder): + files: FilesSpec = { + "egg_with_module_pkg.egg-info": { + "PKG-INFO": "Name: egg_with_module-pkg", + # SOURCES.txt is made from the source archive, and contains files + # (setup.py) that are not present after installation. + "SOURCES.txt": """ + egg_with_module.py + setup.py + egg_with_module.json + egg_with_module_pkg.egg-info/PKG-INFO + egg_with_module_pkg.egg-info/SOURCES.txt + egg_with_module_pkg.egg-info/top_level.txt + """, + # installed-files.txt is written by pip, and is a strictly more + # accurate source than SOURCES.txt as to the installed contents of + # the package. + "installed-files.txt": """ + ../../../etc/jupyter/jupyter_notebook_config.d/relative.json + /etc/jupyter/jupyter_notebook_config.d/absolute.json + ../egg_with_module.py + PKG-INFO + SOURCES.txt + top_level.txt + """, + # missing top_level.txt (to trigger fallback to installed-files.txt) + }, + "egg_with_module.py": """ + def main(): + print("hello world") + """, + } + + class EggInfoPkgPipInstalledNoModules(OnSysPath, SiteBuilder): files: FilesSpec = { "egg_with_no_modules_pkg.egg-info": { diff --git a/Lib/test/test_importlib/metadata/test_api.py b/Lib/test/test_importlib/metadata/test_api.py index 7d26756..2256e0c 100644 --- a/Lib/test/test_importlib/metadata/test_api.py +++ b/Lib/test/test_importlib/metadata/test_api.py @@ -29,6 +29,7 @@ class APITests( fixtures.EggInfoPkg, fixtures.EggInfoPkgPipInstalledNoToplevel, fixtures.EggInfoPkgPipInstalledNoModules, + fixtures.EggInfoPkgPipInstalledExternalDataFiles, fixtures.EggInfoPkgSourcesFallback, fixtures.DistInfoPkg, fixtures.DistInfoPkgWithDot, |