]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-120910: Fix issue resolving relative paths outside site-packages. (GH-12091...
authorJason R. Coombs <jaraco@jaraco.com>
Sun, 23 Jun 2024 17:30:18 +0000 (13:30 -0400)
committerGitHub <noreply@github.com>
Sun, 23 Jun 2024 17:30:18 +0000 (17:30 +0000)
Incorporates changes from importlib_metadata 7.2.1.
(cherry picked from commit 1ba0bb21ed4eb54023fdfccc9cb20be8fff946b1)

Lib/importlib/metadata/__init__.py
Lib/test/test_importlib/fixtures.py
Lib/test/test_importlib/test_metadata_api.py
Misc/NEWS.d/next/Library/2024-06-23-11-21-27.gh-issue-120910.t0QXdB.rst [new file with mode: 0644]

index 54156e93afc5d443e040900c0f0a32e2648f0c97..e6ca17821d129ec2c77d02ada4678dbd5f5b8141 100644 (file)
@@ -534,7 +534,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()
         )
index 73e5da2ba9227914df47b89c234807b68840aee6..9339d68f33e731336a6085f503630c13e540316a 100644 (file)
@@ -245,6 +245,44 @@ class EggInfoPkgPipInstalledNoToplevel(OnSysPath, SiteDir):
         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": {
index 33c6e85ee94753503e8f6fbb853bff7f5e59a838..29b261baba4cccd6102a8b7dc1689fdfb61346b0 100644 (file)
@@ -29,6 +29,7 @@ class APITests(
     fixtures.EggInfoPkg,
     fixtures.EggInfoPkgPipInstalledNoToplevel,
     fixtures.EggInfoPkgPipInstalledNoModules,
+    fixtures.EggInfoPkgPipInstalledExternalDataFiles,
     fixtures.EggInfoPkgSourcesFallback,
     fixtures.DistInfoPkg,
     fixtures.DistInfoPkgWithDot,
diff --git a/Misc/NEWS.d/next/Library/2024-06-23-11-21-27.gh-issue-120910.t0QXdB.rst b/Misc/NEWS.d/next/Library/2024-06-23-11-21-27.gh-issue-120910.t0QXdB.rst
new file mode 100644 (file)
index 0000000..3773cdc
--- /dev/null
@@ -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.