1""" 2Provides .props file. 3""" 4 5import os 6import sys 7 8from .constants import * 9 10__all__ = ["get_nuspec_layout"] 11 12PYTHON_NUSPEC_NAME = "python.nuspec" 13 14NUSPEC_DATA = { 15 "PYTHON_TAG": VER_DOT, 16 "PYTHON_VERSION": os.getenv("PYTHON_NUSPEC_VERSION"), 17 "FILELIST": r' <file src="**\*" exclude="python.png" target="tools" />', 18 "GIT": sys._git, 19} 20 21NUSPEC_PLATFORM_DATA = dict( 22 _keys=("PYTHON_BITNESS", "PACKAGENAME", "PACKAGETITLE"), 23 win32=("32-bit", "pythonx86", "Python (32-bit)"), 24 amd64=("64-bit", "python", "Python"), 25 arm32=("ARM", "pythonarm", "Python (ARM)"), 26 arm64=("ARM64", "pythonarm64", "Python (ARM64)"), 27 win32t=("32-bit free-threaded", "pythonx86-freethreaded", "Python (32-bit, free-threaded)"), 28 amd64t=("64-bit free-threaded", "python-freethreaded", "Python (free-threaded)"), 29 arm32t=("ARM free-threaded", "pythonarm-freethreaded", "Python (ARM, free-threaded)"), 30 arm64t=("ARM64 free-threaded", "pythonarm64-freethreaded", "Python (ARM64, free-threaded)"), 31) 32 33if not NUSPEC_DATA["PYTHON_VERSION"]: 34 NUSPEC_DATA["PYTHON_VERSION"] = "{}.{}{}{}".format( 35 VER_DOT, VER_MICRO, "-" if VER_SUFFIX else "", VER_SUFFIX 36 ) 37 38FILELIST_WITH_PROPS = r""" <file src="**\*" exclude="python.png;python.props" target="tools" /> 39 <file src="python.props" target="build\native" />""" 40 41NUSPEC_TEMPLATE = r"""<?xml version="1.0"?> 42<package> 43 <metadata> 44 <id>{PACKAGENAME}</id> 45 <title>{PACKAGETITLE}</title> 46 <version>{PYTHON_VERSION}</version> 47 <authors>Python Software Foundation</authors> 48 <license type="file">tools\LICENSE.txt</license> 49 <projectUrl>https://www.python.org/</projectUrl> 50 <description>Installs {PYTHON_BITNESS} Python for use in build scenarios.</description> 51 <icon>images\python.png</icon> 52 <iconUrl>https://www.python.org/static/favicon.ico</iconUrl> 53 <tags>python</tags> 54 <repository type="git" url="https://github.com/Python/CPython.git" commit="{GIT[2]}" /> 55 </metadata> 56 <files> 57 <file src="python.png" target="images" /> 58{FILELIST} 59 </files> 60</package> 61""" 62 63 64def _get_nuspec_data_overrides(ns): 65 arch = ns.arch 66 if ns.include_freethreaded: 67 arch += "t" 68 for k, v in zip(NUSPEC_PLATFORM_DATA["_keys"], NUSPEC_PLATFORM_DATA[arch]): 69 ev = os.getenv("PYTHON_NUSPEC_" + k) 70 if ev: 71 yield k, ev 72 yield k, v 73 74 75def get_nuspec_layout(ns): 76 if ns.include_all or ns.include_nuspec: 77 data = dict(NUSPEC_DATA) 78 for k, v in _get_nuspec_data_overrides(ns): 79 if not data.get(k): 80 data[k] = v 81 if ns.include_all or ns.include_props: 82 data["FILELIST"] = FILELIST_WITH_PROPS 83 nuspec = NUSPEC_TEMPLATE.format_map(data) 84 yield "python.nuspec", ("python.nuspec", nuspec.encode("utf-8")) 85 yield "python.png", ns.source / "PC" / "icons" / "logox128.png" 86