Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyximport: Use relative paths less, and correctly #5957

Merged
merged 2 commits into from Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug fix, since the chdir should have preceded the shortening of pyxfilename and pyxbuild_dir:

os.chdir(common)
pyxfilename = os.path.relpath(pyxfilename)
pyxbuild_dir = os.path.relpath(pyxbuild_dir)

Shouldn't the fix in the PR also apply to pyxbuild_dir?:

pyxbuild_dir = os.path.relpath(pyxbuild_dir, common)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chdir should have preceded the shortening of pyxfilename and pyxbuild_dir

Is there a guarantee that pyxfilename is absolute? If not, if you chdir first, your path to pyxfilename won't be correct any more.

Shouldn't the fix in the PR also apply to pyxbuild_dir?:

Oh, yeah, probably

try:
so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod,
Expand Down