Skip to content

Commit

Permalink
[3.12] pythongh-120910: Fix issue resolving relative paths outside si…
Browse files Browse the repository at this point in the history
…te-packages. (pythonGH-120911)

Incorporates changes from importlib_metadata 7.2.1.
(cherry picked from commit 1ba0bb2)

Co-authored-by: Jason R. Coombs <[email protected]>
  • Loading branch information
jaraco committed Jun 23, 2024
1 parent 673cabc commit e49f67d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/importlib/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def _read_files_egginfo_installed(self):
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()
)
Expand Down
38 changes: 38 additions & 0 deletions Lib/test/test_importlib/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,44 @@ def setUp(self):
build_files(EggInfoPkgPipInstalledNoToplevel.files, prefix=self.site_dir)


class EggInfoPkgPipInstalledExternalDataFiles(OnSysPath, SiteDir):
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")
""",
}

def setUp(self):
super().setUp()
build_files(EggInfoPkgPipInstalledExternalDataFiles.files, prefix=self.site_dir)


class EggInfoPkgPipInstalledNoModules(OnSysPath, SiteDir):
files: FilesSpec = {
"egg_with_no_modules_pkg.egg-info": {
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_importlib/test_metadata_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class APITests(
fixtures.EggInfoPkg,
fixtures.EggInfoPkgPipInstalledNoToplevel,
fixtures.EggInfoPkgPipInstalledNoModules,
fixtures.EggInfoPkgPipInstalledExternalDataFiles,
fixtures.EggInfoPkgSourcesFallback,
fixtures.DistInfoPkg,
fixtures.DistInfoPkgWithDot,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When reading installed files from an egg, use ``relative_to(walk_up=True)``
to honor files installed outside of the installation root.

0 comments on commit e49f67d

Please sign in to comment.