-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-138489: Install build-details.json
on Windows
#138490
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
1901e80
dbe1cbd
c80344c
ee39ea7
f5f0548
fdba9f0
6a2cc71
bd9bf46
8d58be4
a927601
d743693
d18f70e
57f3b26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The :pep:`739` :file:`build-details.json` file is now generated and | ||
installed on Windows. | ||
Patch by Adam Turner. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,12 @@ | |
<Message Text="Generating $(OutDir)pybuilddir.txt" /> | ||
<WriteLinesToFile File="$(OutDir)pybuilddir.txt" Lines="%0D%0A" Overwrite="true" /> | ||
</Target> | ||
<Target Name="GenerateBuildDetailsJSON" AfterTargets="Link"> | ||
<Message Text="Generating $(OutDir)build-details.json" /> | ||
<Exec Command='setlocal | ||
set PYTHONPATH=$(PySourcePath)Lib | ||
Comment on lines
+131
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure if these bits are needed, I copied them from the entry slightly further down. |
||
"$(OutDir)$(PyExeName)$(PyDebugExt).exe" "$(PySourcePath)Tools\build\generate-build-details.py" "$(OutDir)build-details.json"' ContinueOnError="true" /> | ||
</Target> | ||
<Target Name="ValidateUcrtbase" AfterTargets="AfterBuild" Condition="$(Configuration) != 'PGInstrument' and $(Platform) != 'ARM' and $(Platform) != 'ARM64'"> | ||
<PropertyGroup> | ||
<UcrtName>ucrtbase</UcrtName> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,13 +55,16 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]: | |
data['language']['version'] = sysconfig.get_python_version() | ||
data['language']['version_info'] = version_info_to_dict(sys.version_info) | ||
|
||
data['implementation'] = vars(sys.implementation) | ||
data['implementation'] = vars(sys.implementation).copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed, currently the script overwrites |
||
data['implementation']['version'] = version_info_to_dict(sys.implementation.version) | ||
# Fix cross-compilation | ||
if '_multiarch' in data['implementation']: | ||
data['implementation']['_multiarch'] = sysconfig.get_config_var('MULTIARCH') | ||
|
||
data['abi']['flags'] = list(sys.abiflags) | ||
if os.name != 'nt': | ||
data['abi']['flags'] = list(sys.abiflags) | ||
else: | ||
data['abi']['flags'] = [] | ||
|
||
data['suffixes']['source'] = importlib.machinery.SOURCE_SUFFIXES | ||
data['suffixes']['bytecode'] = importlib.machinery.BYTECODE_SUFFIXES | ||
|
@@ -104,7 +107,7 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]: | |
data['abi']['extension_suffix'] = sysconfig.get_config_var('EXT_SUFFIX') | ||
|
||
# EXTENSION_SUFFIXES has been constant for a long time, and currently we | ||
# don't have a better information source to find the stable ABI suffix. | ||
# don't have a better information source to find the stable ABI suffix. | ||
for suffix in importlib.machinery.EXTENSION_SUFFIXES: | ||
if suffix.startswith('.abi'): | ||
data['abi']['stable_abi_suffix'] = suffix | ||
|
@@ -133,33 +136,51 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]: | |
def make_paths_relative(data: dict[str, Any], config_path: str | None = None) -> None: | ||
# Make base_prefix relative to the config_path directory | ||
if config_path: | ||
data['base_prefix'] = os.path.relpath(data['base_prefix'], os.path.dirname(config_path)) | ||
data['base_prefix'] = relative_path(data['base_prefix'], | ||
os.path.dirname(config_path)) | ||
base_prefix = data['base_prefix'] | ||
|
||
# Update path values to make them relative to base_prefix | ||
PATH_KEYS = [ | ||
PATH_KEYS = ( | ||
'base_interpreter', | ||
'libpython.dynamic', | ||
'libpython.dynamic_stableabi', | ||
'libpython.static', | ||
'c_api.headers', | ||
'c_api.pkgconfig_path', | ||
] | ||
) | ||
for entry in PATH_KEYS: | ||
parent, _, child = entry.rpartition('.') | ||
*parents, child = entry.split('.') | ||
# Get the key container object | ||
try: | ||
container = data | ||
for part in parent.split('.'): | ||
for part in parents: | ||
container = container[part] | ||
if child not in container: | ||
raise KeyError | ||
current_path = container[child] | ||
except KeyError: | ||
continue | ||
# Get the relative path | ||
new_path = os.path.relpath(current_path, data['base_prefix']) | ||
new_path = relative_path(current_path, base_prefix) | ||
# Join '.' so that the path is formated as './path' instead of 'path' | ||
new_path = os.path.join('.', new_path) | ||
container[child] = new_path | ||
|
||
|
||
def relative_path(path: str, base: str) -> str: | ||
if os.name != 'nt': | ||
return os.path.relpath(path, base) | ||
|
||
# There are no relative paths between drives on Windows. | ||
path_drv, _ = os.path.splitdrive(path) | ||
base_drv, _ = os.path.splitdrive(base) | ||
if path_drv.lower() == base_drv.lower(): | ||
return os.path.relpath(path, base) | ||
|
||
return path | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser(exit_on_error=False) | ||
parser.add_argument('location') | ||
|
@@ -186,8 +207,9 @@ def main() -> None: | |
make_paths_relative(data, args.config_file_path) | ||
|
||
json_output = json.dumps(data, indent=2) | ||
with open(args.location, 'w') as f: | ||
print(json_output, file=f) | ||
with open(args.location, 'w', encoding='utf-8') as f: | ||
f.write(json_output) | ||
f.write('\n') | ||
|
||
|
||
if __name__ == '__main__': | ||
|
Uh oh!
There was an error while loading. Please reload this page.