From 464735f1f188fd2dd6eaac12d2985e851e4658bd Mon Sep 17 00:00:00 2001 From: Aohan Dang Date: Tue, 8 Oct 2024 10:14:57 -0400 Subject: [PATCH] Fix issue with absolute path with Python 3.13 on Windows 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. --- distutils/ccompiler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index 5e73e56d..fdbb1ca7 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -989,7 +989,8 @@ def _make_relative(base): # Chop off the drive no_drive = os.path.splitdrive(base)[1] # If abs, chop off leading / - return no_drive[os.path.isabs(no_drive) :] + is_abs = os.path.isabs(no_drive) or sys.platform == 'win32' and (no_drive.startswith('/') or no_drive.startswith('\\')) + return no_drive[is_abs:] def shared_object_filename(self, basename, strip_dir=False, output_dir=''): assert output_dir is not None