Skip to content
Open
13 changes: 8 additions & 5 deletions Lib/test/test_build_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,27 @@ def test_implementation(self):
)


@unittest.skipIf(os.name != 'posix', 'Feature only implemented on POSIX right now')
@unittest.skipIf(is_wasm32, 'Feature not available on WebAssembly builds')
class CPythonBuildDetailsTests(unittest.TestCase, FormatTestsBase):
"""Test CPython's install details file implementation."""

@property
def location(self):
if sysconfig.is_python_build():
projectdir = sysconfig.get_config_var('projectbase')
with open(os.path.join(projectdir, 'pybuilddir.txt')) as f:
dirname = os.path.join(projectdir, f.read())
if sys.platform == 'win32':
dirname = sysconfig.get_config_var('BINDIR')
else:
projectdir = sysconfig.get_config_var('projectbase')
pybuilddir = os.path.join(projectdir, 'pybuilddir.txt')
with open(pybuilddir, encoding='utf-8') as f:
dirname = os.path.join(projectdir, f.read())
else:
dirname = sysconfig.get_path('stdlib')
return os.path.join(dirname, 'build-details.json')

@property
def contents(self):
with open(self.location, 'r') as f:
with open(self.location, 'r', encoding='utf-8') as f:
return f.read()

@needs_installed_python
Expand Down
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.
6 changes: 6 additions & 0 deletions PCbuild/python.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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>
Expand Down
3 changes: 3 additions & 0 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,7 @@
<Target Name="_DeletePyBuildDirTxt" BeforeTargets="PrepareForBuild">
<Delete Files="$(OutDir)pybuilddir.txt" />
</Target>
<Target Name="_DeleteBuildDetailsJson" BeforeTargets="PrepareForBuild">
<Delete Files="$(OutDir)build-details.json" />
</Target>
</Project>
14 changes: 9 additions & 5 deletions Tools/build/generate-build-details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed, currently the script overwrites sys.implementation.version in the running interpreter.

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -186,8 +189,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__':
Expand Down
Loading