From 2bf16ec8b398fe452f28431ec42814f4999f372d Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 21 Jan 2024 11:13:47 -0400 Subject: [PATCH 1/2] pyximport: Calculate the relative path correctly It should be relative to the new current directory, not the old one. --- pyximport/pyximport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyximport/pyximport.py b/pyximport/pyximport.py index 629325933ec..9f678bf3135 100644 --- a/pyximport/pyximport.py +++ b/pyximport/pyximport.py @@ -190,8 +190,8 @@ def build_module(name, pyxfilename, pyxbuild_dir=None, inplace=False, language_l # compiling, and then complains that the filename is too long common = os.path.commonprefix([pyxbuild_dir, pyxfilename]) if len(common) > 30: - pyxfilename = os.path.relpath(pyxfilename) - pyxbuild_dir = os.path.relpath(pyxbuild_dir) + pyxfilename = os.path.relpath(pyxfilename, common) + pyxbuild_dir = os.path.relpath(pyxbuild_dir, common) os.chdir(common) try: so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod, From 2e9368b3a36402f3d9254c5574de2685e10e45cb Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 21 Jan 2024 11:16:39 -0400 Subject: [PATCH 2/2] pyximport: Avoid chdir before build on non-Windows Using a relative path means we lose path information in the built module. This can be useful in packages such as stack_data that look up source code. --- pyximport/pyximport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyximport/pyximport.py b/pyximport/pyximport.py index 9f678bf3135..96a727961d9 100644 --- a/pyximport/pyximport.py +++ b/pyximport/pyximport.py @@ -185,7 +185,7 @@ def build_module(name, pyxfilename, pyxbuild_dir=None, inplace=False, language_l from . import pyxbuild olddir = os.getcwd() common = '' - if pyxbuild_dir: + if pyxbuild_dir and sys.platform == 'win32': # Windows concatenates the pyxbuild_dir to the pyxfilename when # compiling, and then complains that the filename is too long common = os.path.commonprefix([pyxbuild_dir, pyxfilename])