provides props file def getnuspecdataoverridesns for k v in zipnuspecplatformdatakeys nuspecplatformdatans arch ev os getenvpythonnuspec k if ev yield k ev yield k v def getnuspeclayoutns if ns includeall or ns includenuspec data dictnuspecdata for k v in getnuspecdataoverridesns if not data getk datak v if ns includeall or ns includeprops datafilelist filelistwithprops nuspec nuspectemplate formatmapdata yield python nuspec python nuspec nuspec encodeutf8 yield python png ns source pc icons logox128 png file src exclude python png python props target tools file src python props target build native xml version 1 0 package metadata id packagename id title packagetitle title version python_version version s python software foundation s license type file tools license txt license projecturl https www python org projecturl description installs python_bitness python for use in build scenarios description icon images python png icon iconurl https www python org static favicon ico iconurl tags python tags repository type git url https github com python cpython git commit git 2 metadata files file src python png target images filelist files package
import os
import sys

from .constants import *

__all__ = ["get_nuspec_layout"]

PYTHON_NUSPEC_NAME = "python.nuspec"

NUSPEC_DATA = {
    "PYTHON_TAG": VER_DOT,
    "PYTHON_VERSION": os.getenv("PYTHON_NUSPEC_VERSION"),
    "FILELIST": r'    <file src="**\*" exclude="python.png" target="tools" />',
    "GIT": sys._git,
}

NUSPEC_PLATFORM_DATA = dict(
    _keys=("PYTHON_BITNESS", "PACKAGENAME", "PACKAGETITLE"),
    win32=("32-bit", "pythonx86", "Python (32-bit)"),
    amd64=("64-bit", "python", "Python"),
    arm32=("ARM", "pythonarm", "Python (ARM)"),
    arm64=("ARM64", "pythonarm64", "Python (ARM64)"),
)

if not NUSPEC_DATA["PYTHON_VERSION"]:
    NUSPEC_DATA["PYTHON_VERSION"] = "{}.{}{}{}".format(
        VER_DOT, VER_MICRO, "-" if VER_SUFFIX else "", VER_SUFFIX
    )

FILELIST_WITH_PROPS = r

NUSPEC_TEMPLATE = r


def _get_nuspec_data_overrides(ns):
    for k, v in zip(NUSPEC_PLATFORM_DATA["_keys"], NUSPEC_PLATFORM_DATA[ns.arch]):
        ev = os.getenv("PYTHON_NUSPEC_" + k)
        if ev:
            yield k, ev
        yield k, v


def get_nuspec_layout(ns):
    if ns.include_all or ns.include_nuspec:
        data = dict(NUSPEC_DATA)
        for k, v in _get_nuspec_data_overrides(ns):
            if not data.get(k):
                data[k] = v
        if ns.include_all or ns.include_props:
            data["FILELIST"] = FILELIST_WITH_PROPS
        nuspec = NUSPEC_TEMPLATE.format_map(data)
        yield "python.nuspec", ("python.nuspec", nuspec.encode("utf-8"))
        yield "python.png", ns.source / "PC" / "icons" / "logox128.png"