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
Conversation
# 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) | ||
pyxfilename = os.path.relpath(pyxfilename, common) | ||
pyxbuild_dir = os.path.relpath(pyxbuild_dir) | ||
os.chdir(common) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 ofpyxfilename
andpyxbuild_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
It should be relative to the new current directory, not the old one.
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.
a647f28
to
2e9368b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. I did try out PR #4630, but maybe there was something in the test directory structure that make relpath
work. This fix is better.
Hrm, the downside of the second commit is that baking in absolute paths is bad for non-reproducibility (Debian #988999). However, that should be solved systematically, not with a 30-character heuristic. |
I am confused. How does |
What I meant is that I'm perpetuating the non-reproducibility problem by not using relpath on non-Windows. |
* 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.
Thanks - 3.0.x backport in 84273d6 |
#4630 started to use relative paths in pyximport, when the path got long, to avoid issues on Windows.
This has two issues:
stack_data
, if the source file isn't available at the same relative path.Discoverd these while investigating Debian bug #1056872