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