Skip to content

Commit 5ef4dc8

Browse files
committed
Resolve absolute path before attempting to calculate a relative path
This better mirrors the bahevior of os.path.relpath. Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent e5040ae commit 5ef4dc8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎Lib/sysconfig/_build_details.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def _relocate(self, obj: SchemaBase, origin: pathlib.Path) -> None:
235235
continue
236236
value = getattr(obj, field.name)
237237
if isinstance(value, pathlib.Path):
238-
changes[field.name] = value.relative_to(origin)
238+
changes[field.name] = value.absolute().relative_to(origin)
239239
elif isinstance(value, SchemaBase):
240240
changes[field.name] = self._relocate(value, origin)
241241
return dataclasses.replace(obj, **changes)
@@ -291,11 +291,13 @@ def from_interpreter(cls) -> BuildDetailsV1:
291291
INCLUDEPY = pathlib.Path(sysconfig.get_config_var('INCLUDEPY'))
292292
PYTHONFRAMEWORKPREFIX = pathlib.Path(sysconfig.get_config_var('PYTHONFRAMEWORKPREFIX'))
293293

294+
installed_base = pathlib.Path(sysconfig.get_config_var('installed_base'))
295+
294296
interpreter_name = 'python' + sysconfig.get_config_var('LDVERSION') + sysconfig.get_config_var('EXE')
295297

296298
data = types.SimpleNamespace()
297299

298-
data.base_prefix = sysconfig.get_config_var('installed_base')
300+
data.base_prefix = installed_base.absolute()
299301
data.base_interpreter = default_scheme_paths.scripts / interpreter_name
300302
data.platform = sysconfig.get_platform()
301303
data.language = LanguageV1(
@@ -410,7 +412,7 @@ def generate(path: _PathType, relative_paths=False) -> None:
410412
if relative_paths:
411413
data = data.as_relocatable()
412414
# If relative_paths is enabled, we also make base_prefix relative.
413-
data.base_prefix = data.base_prefix.relative_to(path)
415+
data.base_prefix = data.base_prefix.relative_to(path.absolute())
414416

415417
with open(path, 'w', encoding='utf-8') as f:
416418
f.write(data.as_json() + '\n')

0 commit comments

Comments
 (0)