|
4 | 4 | for the Distutils compiler abstraction model."""
|
5 | 5 |
|
6 | 6 | import os
|
| 7 | +import pathlib |
7 | 8 | import re
|
8 | 9 | import sys
|
9 | 10 | import types
|
@@ -976,31 +977,20 @@ def _make_out_path(self, output_dir, strip_dir, src_name):
|
976 | 977 | @classmethod
|
977 | 978 | def _make_out_path_exts(cls, output_dir, strip_dir, src_name, extensions):
|
978 | 979 | base, ext = os.path.splitext(src_name)
|
| 980 | + base = pathlib.PurePath(base) |
| 981 | + # Ensure base is relative to honor output_dir (python/cpython#37775). |
979 | 982 | base = cls._make_relative(base)
|
980 | 983 | try:
|
981 | 984 | new_ext = extensions[ext]
|
982 | 985 | except LookupError:
|
983 | 986 | raise UnknownFileError(f"unknown file type '{ext}' (from '{src_name}')")
|
984 | 987 | if strip_dir:
|
985 |
| - base = os.path.basename(base) |
986 |
| - return os.path.join(output_dir, base + new_ext) |
| 988 | + base = base.name |
| 989 | + return os.path.join(output_dir, base.with_suffix(new_ext)) |
987 | 990 |
|
988 | 991 | @staticmethod
|
989 |
| - def _make_relative(base): |
990 |
| - """ |
991 |
| - In order to ensure that a filename always honors the |
992 |
| - indicated output_dir, make sure it's relative. |
993 |
| - Ref python/cpython#37775. |
994 |
| - """ |
995 |
| - # Chop off the drive |
996 |
| - no_drive = os.path.splitdrive(base)[1] |
997 |
| - # If abs, chop off leading / |
998 |
| - is_abs = ( |
999 |
| - os.path.isabs(no_drive) |
1000 |
| - or sys.platform == 'win32' |
1001 |
| - and no_drive.startswith(('/', "\\")) |
1002 |
| - ) |
1003 |
| - return no_drive[is_abs:] |
| 992 | + def _make_relative(base: pathlib.Path): |
| 993 | + return base.relative_to(base.anchor) |
1004 | 994 |
|
1005 | 995 | def shared_object_filename(self, basename, strip_dir=False, output_dir=''):
|
1006 | 996 | assert output_dir is not None
|
|
0 commit comments