8000 [3.13] gh-120910: Fix issue resolving relative paths outside site-pac… · python/cpython@6be1048 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6be1048

Browse files
[3.13] gh-120910: Fix issue resolving relative paths outside site-packages. (GH-120911) (#120917)
gh-120910: Fix issue resolving relative paths outside site-packages. (GH-120911) Incorporates changes from importlib_metadata 7.2.1. (cherry picked from commit 1ba0bb2) Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
1 parent d6791cd commit 6be1048

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

Lib/importlib/metadata/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def _read_files_egginfo_installed(self):
567567
paths = (
568568
(subdir / name)
569569
.resolve()
570-
.relative_to(self.locate_file('').resolve())
570+
.relative_to(self.locate_file('').resolve(), walk_up=True)
571571
.as_posix()
572572
for name in text.splitlines()
573573
)

Lib/test/test_importlib/metadata/fixtures.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,40 @@ def main():
253253
}
254254

255255

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

Lib/test/test_importlib/metadata/test_api.py

Lines changed: 1 addition & 0 deletions
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,
Lines changed: 2 additions & 0 deletions
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)
0