Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/PC/layout/support/props.py
12 views
1
"""
2
Provides .props file.
3
"""
4
5
import os
6
7
from .constants import *
8
9
__all__ = ["get_props_layout"]
10
11
PYTHON_PROPS_NAME = "python.props"
12
13
PROPS_DATA = {
14
"PYTHON_TAG": VER_DOT,
15
"PYTHON_VERSION": os.getenv("PYTHON_NUSPEC_VERSION"),
16
"PYTHON_PLATFORM": os.getenv("PYTHON_PROPS_PLATFORM"),
17
"PYTHON_TARGET": "",
18
}
19
20
if not PROPS_DATA["PYTHON_VERSION"]:
21
PROPS_DATA["PYTHON_VERSION"] = "{}.{}{}{}".format(
22
VER_DOT, VER_MICRO, "-" if VER_SUFFIX else "", VER_SUFFIX
23
)
24
25
PROPS_DATA["PYTHON_TARGET"] = "_GetPythonRuntimeFilesDependsOn{}{}_{}".format(
26
VER_MAJOR, VER_MINOR, PROPS_DATA["PYTHON_PLATFORM"]
27
)
28
29
PROPS_TEMPLATE = r"""<?xml version="1.0" encoding="utf-8"?>
30
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
31
<PropertyGroup Condition="$(Platform) == '{PYTHON_PLATFORM}'">
32
<PythonHome Condition="$(PythonHome) == ''">$([System.IO.Path]::GetFullPath("$(MSBuildThisFileDirectory)\..\..\tools"))</PythonHome>
33
<PythonInclude>$(PythonHome)\include</PythonInclude>
34
<PythonLibs>$(PythonHome)\libs</PythonLibs>
35
<PythonTag>{PYTHON_TAG}</PythonTag>
36
<PythonVersion>{PYTHON_VERSION}</PythonVersion>
37
38
<IncludePythonExe Condition="$(IncludePythonExe) == ''">true</IncludePythonExe>
39
<IncludeVEnv Condition="$(IncludeVEnv) == ''">false</IncludeVEnv>
40
41
<GetPythonRuntimeFilesDependsOn>{PYTHON_TARGET};$(GetPythonRuntimeFilesDependsOn)</GetPythonRuntimeFilesDependsOn>
42
</PropertyGroup>
43
44
<ItemDefinitionGroup Condition="$(Platform) == '{PYTHON_PLATFORM}'">
45
<ClCompile>
46
<AdditionalIncludeDirectories>$(PythonInclude);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
47
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
48
</ClCompile>
49
<Link>
50
<AdditionalLibraryDirectories>$(PythonLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
51
</Link>
52
</ItemDefinitionGroup>
53
54
<Target Name="GetPythonRuntimeFiles" Returns="@(PythonRuntime)" DependsOnTargets="$(GetPythonRuntimeFilesDependsOn)" />
55
56
<Target Name="{PYTHON_TARGET}" Returns="@(PythonRuntime)">
57
<ItemGroup>
58
<_PythonRuntimeExe Include="$(PythonHome)\python*.dll" />
59
<_PythonRuntimeExe Include="$(PythonHome)\python*.exe" Condition="$(IncludePythonExe) == 'true'" />
60
<_PythonRuntimeExe>
61
<Link>%(Filename)%(Extension)</Link>
62
</_PythonRuntimeExe>
63
<_PythonRuntimeDlls Include="$(PythonHome)\DLLs\*.pyd" />
64
<_PythonRuntimeDlls Include="$(PythonHome)\DLLs\*.dll" />
65
<_PythonRuntimeDlls>
66
<Link>DLLs\%(Filename)%(Extension)</Link>
67
</_PythonRuntimeDlls>
68
<_PythonRuntimeLib Include="$(PythonHome)\Lib\**\*" Exclude="$(PythonHome)\Lib\**\*.pyc;$(PythonHome)\Lib\site-packages\**\*" />
69
<_PythonRuntimeLib Remove="$(PythonHome)\Lib\ensurepip\**\*" Condition="$(IncludeVEnv) != 'true'" />
70
<_PythonRuntimeLib Remove="$(PythonHome)\Lib\venv\**\*" Condition="$(IncludeVEnv) != 'true'" />
71
<_PythonRuntimeLib>
72
<Link>Lib\%(RecursiveDir)%(Filename)%(Extension)</Link>
73
</_PythonRuntimeLib>
74
<PythonRuntime Include="@(_PythonRuntimeExe);@(_PythonRuntimeDlls);@(_PythonRuntimeLib)" />
75
</ItemGroup>
76
77
<Message Importance="low" Text="Collected Python runtime from $(PythonHome):%0D%0A@(PythonRuntime->' %(Link)','%0D%0A')" />
78
</Target>
79
</Project>
80
"""
81
82
83
def get_props_layout(ns):
84
if ns.include_all or ns.include_props:
85
# TODO: Filter contents of props file according to included/excluded items
86
d = dict(PROPS_DATA)
87
if not d.get("PYTHON_PLATFORM"):
88
d["PYTHON_PLATFORM"] = {
89
"win32": "Win32",
90
"amd64": "X64",
91
"arm32": "ARM",
92
"arm64": "ARM64",
93
}[ns.arch]
94
props = PROPS_TEMPLATE.format_map(d)
95
yield "python.props", ("python.props", props.encode("utf-8"))
96
97