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

Fix issue with absolute path with Python 3.13 on Windows #302

Merged
merged 9 commits into from
Jan 4, 2025

Conversation

adang1345
Copy link
Contributor

Fix pypa/setuptools#4669.

I originally opened a pull request at pypa/setuptools#4671 but was asked to submit the change here instead. See the above links for details about the bug and the fix.

@lazka
Copy link
Contributor

lazka commented Oct 18, 2024

lgtm in general, but the commit message could explain why it broke and why this fixes it.

For future reference, this function tries to implement os.path.splitroot()[-1], but that got only added in 3.12.

With Python 3.13 on Windows, `os.path.isabs()` no longer returns `True`
for a path that starts with a slash. Thus, when the argument to
`_make_relative()` is an absolute path, the return value starts with a
slash on Python 3.13 and does not start with a slash on older Python
versions. This causes the extension module build directory to be
calculated incorrectly with Python 3.13 on Windows.

Fix this by ensuring that the return value does not start with a slash.
@adang1345
Copy link
Contributor Author

I edited the commit message to explain the issue and the fix.

@lazka
Copy link
Contributor

lazka commented Oct 22, 2024

better, thanks

@jaraco
Copy link
Member

jaraco commented Dec 26, 2024

I think this change introduces some lint, so that'll need to be fixed after the other emergent lint issues in main are resolved.

I've left a comment in the original issue - I'd first like to understand if this change to Python 3.13 is indeed intentional. If it is, I'm hoping there's some advice on how to handle this situation, and I'd like to see a documented function that implements this logic in a re-usable way.

distutils/ccompiler.py Outdated Show resolved Hide resolved
@jaraco
Copy link
Member

jaraco commented Jan 4, 2025

I started working on adding a regression test for the missed behavior, but it's tricky because in #169 CCompiler._make_relative is disabled for tests, so adding a test to CCompiler._make_out_path won't exercise the make-relative behavior. So maybe we'll do without a test.

@jaraco jaraco force-pushed the fix-python313-abs branch from fe48898 to ede1af2 Compare January 4, 2025 10:26
@jaraco
Copy link
Member

jaraco commented Jan 4, 2025

For future reference, this function tries to implement os.path.splitroot()[-1], but that got only added in 3.12.

I've found that pathlib.Path.relative_to(pathlib.Path.anchor) works for older Pythons and is consistent across platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Extension module build files are written to source directory
5 participants