Skip to content

Commit daef7de

Browse files
authored
[3.12] gh-120910: Fix issue resolving relative paths outside site-packages. (GH-120911) (#120918)
Incorporates changes from importlib_metadata 7.2.1. (cherry picked from commit 1ba0bb2)
1 parent 673cabc commit daef7de

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

Lib/importlib/metadata/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def _read_files_egginfo_installed(self):
534534
paths = (
535535
(subdir / name)
536536
.resolve()
537-
.relative_to(self.locate_file('').resolve())
537+
.relative_to(self.locate_file('').resolve(), walk_up=True)
538538
.as_posix()
539539
for name in text.splitlines()
540540
)

Lib/test/test_importlib/fixtures.py

+38
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,44 @@ def setUp(self):
245245
build_files(EggInfoPkgPipInstalledNoToplevel.files, prefix=self.site_dir)
246246

247247

248+
class EggInfoPkgPipInstalledExternalDataFiles(OnSysPath, SiteDir):
249+
files: FilesSpec = {
250+
"egg_with_module_pkg.egg-info": {
251+
"PKG-INFO": "Name: egg_with_module-pkg",
252+
# SOURCES.txt is made from the source archive, and contains files
253+
# (setup.py) that are not present after installation.
254+
"SOURCES.txt": """
255+
egg_with_module.py
256+
setup.py
257+
egg_with_module.json
258+
egg_with_module_pkg.egg-info/PKG-INFO
259+
egg_with_module_pkg.egg-info/SOURCES.txt
260+
egg_with_module_pkg.egg-info/top_level.txt
261+
""",
262+
# installed-files.txt is written by pip, and is a strictly more
263+
# accurate source than SOURCES.txt as to the installed contents of
264+
# the package.
265+
"installed-files.txt": """
266+
../../../etc/jupyter/jupyter_notebook_config.d/relative.json
267+
/etc/jupyter/jupyter_notebook_config.d/absolute.json
268+
../egg_with_module.py
269+
PKG-INFO
270+
SOURCES.txt
271+
top_level.txt
272+
""",
273+
# missing top_level.txt (to trigger fallback to installed-files.txt)
274+
},
275+
"egg_with_module.py": """
276+
def main():
277+
print("hello world")
278+
""",
279+
}
280+
281+
def setUp(self):
282+
super().setUp()
283+
build_files(EggInfoPkgPipInstalledExternalDataFiles.files, prefix=self.site_dir)
284+
285+
248286
class EggInfoPkgPipInstalledNoModules(OnSysPath, SiteDir):
249287
files: FilesSpec = {
250288
"egg_with_no_modules_pkg.egg-info": {

Lib/test/test_importlib/test_metadata_api.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class APITests(
2929
fixtures.EggInfoPkg,
3030
fixtures.EggInfoPkgPipInstalledNoToplevel,
3131
fixtures.EggInfoPkgPipInstalledNoModules,
32+
fixtures.EggInfoPkgPipInstalledExternalDataFiles,
3233
fixtures.EggInfoPkgSourcesFallback,
3334
fixtures.DistInfoPkg,
3435
fixtures.DistInfoPkgWithDot,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
When reading installed files from an egg, use ``relative_to(walk_up=True)``
2+
to honor files installed outside of the installation root.

0 commit comments

Comments
 (0)