Skip to content

Commit

Permalink
pyximport: Use relative paths less, and correctly (#5957)
Browse files Browse the repository at this point in the history
* pyximport: Calculate the relative path correctly

It should be relative to the new current directory, not the old one.

* 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.
  • Loading branch information
stefanor committed Feb 1, 2024
1 parent 71d1dc3 commit 09863a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pyximport/pyximport.py
Expand Up @@ -185,13 +185,13 @@ 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])
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,
Expand Down

0 comments on commit 09863a7

Please sign in to comment.