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

CCompiler._make_relative ineffective with Python 3.13 #297

Open
mglisse opened this issue Sep 12, 2024 · 0 comments
Open

CCompiler._make_relative ineffective with Python 3.13 #297

mglisse opened this issue Sep 12, 2024 · 0 comments

Comments

@mglisse
Copy link

mglisse commented Sep 12, 2024

(This was noticed in pypa/setuptools#4645)

def _make_relative(base):
"""
In order to ensure that a filename always honors the
indicated output_dir, make sure it's relative.
Ref python/cpython#37775.
"""
# Chop off the drive
no_drive = os.path.splitdrive(base)[1]
# If abs, chop off leading /
return no_drive[os.path.isabs(no_drive) :]

In ccompiler.py, the function _make_relative aims to turn an arbitrary path into something "relative" in the sense that os.path.join can append it to some other path. In Python 3.13, os.path.isabs changed in a way that it now returns False for '/a/b' on Windows. This means that _make_relative('C:/a/b') only strips the drive but not the leading slash, and returns the bad '/a/b' (as opposed to 'a/b' with Python 3.12). Note that os.path.join still handles '/a/b' as an absolute path, os.path.join('build','/a/b') returns its second argument.

A suggestion (from someone not very familiar with the whole thing) would be to replace

return no_drive[os.path.isabs(no_drive) :]

with

return no_drive.lstrip(r'\/')
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

No branches or pull requests

1 participant