Import Upstream version 2.7.18
This commit is contained in:
64
Tools/nuget/build.bat
Normal file
64
Tools/nuget/build.bat
Normal file
@@ -0,0 +1,64 @@
|
||||
@echo off
|
||||
setlocal
|
||||
set D=%~dp0
|
||||
set PCBUILD=%D%..\..\PCBuild\
|
||||
|
||||
set BUILDX86=
|
||||
set BUILDX64=
|
||||
set REBUILD=
|
||||
set OUTPUT=
|
||||
set PACKAGES=
|
||||
|
||||
:CheckOpts
|
||||
if "%~1" EQU "-h" goto Help
|
||||
if "%~1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts
|
||||
if "%~1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts
|
||||
if "%~1" EQU "-r" (set REBUILD=-r) && shift && goto CheckOpts
|
||||
if "%~1" EQU "-o" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts
|
||||
if "%~1" EQU "--out" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts
|
||||
if "%~1" EQU "-p" (set PACKAGES=%PACKAGES% %~2) && shift && shift && goto CheckOpts
|
||||
|
||||
if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1)
|
||||
|
||||
if not defined NUGET where nuget -q || echo Cannot find nuget.exe on PATH and NUGET is not set. && exit /B 1
|
||||
call "%PCBUILD%find_msbuild.bat" %MSBUILD%
|
||||
if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2)
|
||||
if not defined PYTHON set PYTHON=py -3
|
||||
|
||||
@%PYTHON% -c "" >nul 2>nul
|
||||
@if errorlevel 1 (
|
||||
%NUGET% install python -OutputDirectory "%D%obj" -ExcludeVersion -NonInteractive
|
||||
set PYTHON="%D%obj\python\tools\python.exe"
|
||||
)
|
||||
|
||||
|
||||
if defined PACKAGES set PACKAGES="/p:Packages=%PACKAGES%"
|
||||
|
||||
if defined BUILDX86 (
|
||||
if defined REBUILD ( call "%PCBUILD%build.bat" -e -r
|
||||
) else if not exist "%PCBUILD%python.exe" call "%PCBUILD%build.bat" -e
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
%MSBUILD% "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x86 %OUTPUT% %PACKAGES%
|
||||
if errorlevel 1 goto :eof
|
||||
)
|
||||
|
||||
if defined BUILDX64 (
|
||||
if defined REBUILD ( call "%PCBUILD%build.bat" -p x64 -e -r
|
||||
) else if not exist "%PCBUILD%amd64\python.exe" call "%PCBUILD%build.bat" -p x64 -e
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
%MSBUILD% "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x64 %OUTPUT% %PACKAGES%
|
||||
if errorlevel 1 goto :eof
|
||||
)
|
||||
|
||||
exit /B 0
|
||||
|
||||
:Help
|
||||
echo build.bat [-x86] [-x64] [--out DIR] [-r] [-h]
|
||||
echo.
|
||||
echo -x86 Build x86 installers
|
||||
echo -x64 Build x64 installers
|
||||
echo -r Rebuild rather than incremental build
|
||||
echo --out [DIR] Override output directory
|
||||
echo -h Show usage
|
||||
20
Tools/nuget/distutils.command.bdist_wininst.py
Normal file
20
Tools/nuget/distutils.command.bdist_wininst.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""distutils.command.bdist_wininst
|
||||
|
||||
Suppresses the 'bdist_wininst' command, while still allowing
|
||||
setuptools to import it without breaking."""
|
||||
|
||||
from distutils.core import Command
|
||||
from distutils.errors import DistutilsPlatformError
|
||||
|
||||
class bdist_wininst(Command):
|
||||
description = "create an executable installer for MS Windows"
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
raise DistutilsPlatformError("bdist_wininst is not supported "
|
||||
"in this Python distribution")
|
||||
54
Tools/nuget/make_pkg.proj
Normal file
54
Tools/nuget/make_pkg.proj
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{6BA7092C-0093-47F0-9ED2-282AEE981E14}</ProjectGuid>
|
||||
<OutputName>python2</OutputName>
|
||||
<OutputName Condition="$(Platform) == 'x86' or $(Platform) == 'Win32' or $(Platform) == ''">$(OutputName)x86</OutputName>
|
||||
<OutputPath Condition="$(OutputPath) == ''">$(MSBuildThisFileDirectory)</OutputPath>
|
||||
<OutputSuffix></OutputSuffix>
|
||||
<SupportSigning>false</SupportSigning>
|
||||
<BuildForRelease Condition="$(BuildForRelease) == ''">true</BuildForRelease>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\..\PCBuild\python.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<NuspecVersion>$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber)</NuspecVersion>
|
||||
<NuspecVersion Condition="$(ReleaseLevelName) != ''">$(NuspecVersion)-$(ReleaseLevelName)</NuspecVersion>
|
||||
<SignOutput>false</SignOutput>
|
||||
<TargetName>$(OutputName).$(NuspecVersion)</TargetName>
|
||||
<TargetExt>.nupkg</TargetExt>
|
||||
<TargetPath>$(OutputPath)\$(TargetName)$(TargetExt)</TargetPath>
|
||||
<IntermediateOutputPath>$(MSBuildThisFileDirectory)\obj_$(ArchName)</IntermediateOutputPath>
|
||||
|
||||
<CleanCommand>rmdir /q/s "$(IntermediateOutputPath)"</CleanCommand>
|
||||
|
||||
<Python Condition="$(Python) == ''">py</Python>
|
||||
<PythonArguments>"$(Python)" "$(MSBuildThisFileDirectory)\make_zip.py"</PythonArguments>
|
||||
<PythonArguments>$(PythonArguments) -s "$(PySourcePath.Trim('\'))" -t "$(IntermediateOutputPath)" -a $(ArchName)</PythonArguments>
|
||||
|
||||
<PipArguments>"$(IntermediateOutputPath)\python.exe" -B -c "import sys; sys.path.append(r'$(PySourcePath)\Lib'); import ensurepip; ensurepip._main()"</PipArguments>
|
||||
<PackageArguments Condition="$(Packages) != ''">"$(IntermediateOutputPath)\python.exe" -B -m pip install -U $(Packages)</PackageArguments>
|
||||
|
||||
<NugetArguments>"$(Nuget)" pack "$(MSBuildThisFileDirectory)\$(OutputName).nuspec"</NugetArguments>
|
||||
<NugetArguments>$(NugetArguments) -BasePath "$(IntermediateOutputPath)"</NugetArguments>
|
||||
<NugetArguments>$(NugetArguments) -OutputDirectory "$(OutputPath.Trim(`\`))"</NugetArguments>
|
||||
<NugetArguments>$(NugetArguments) -Version "$(NuspecVersion)"</NugetArguments>
|
||||
<NugetArguments>$(NugetArguments) -NoPackageAnalysis -NonInteractive</NugetArguments>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="_NugetMissing" BeforeTargets="_Build" Condition="!Exists($(Nuget))">
|
||||
<Error Text="$$(Nuget) could not be found. Specify a valid path on the command line." />
|
||||
</Target>
|
||||
|
||||
<Target Name="_Build">
|
||||
<Exec Command="$(CleanCommand)" />
|
||||
<Exec Command="$(PythonArguments)" />
|
||||
<Exec Command="$(PipArguments)" />
|
||||
<Exec Command="$(PackageArguments)" Condition="$(PackageArguments) != ''" />
|
||||
<Exec Command="$(NugetArguments)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="AfterBuild" />
|
||||
<Target Name="Build" DependsOnTargets="_Build;AfterBuild" />
|
||||
</Project>
|
||||
228
Tools/nuget/make_zip.py
Normal file
228
Tools/nuget/make_zip.py
Normal file
@@ -0,0 +1,228 @@
|
||||
#! /usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import py_compile
|
||||
import re
|
||||
import sys
|
||||
import shutil
|
||||
import stat
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from itertools import chain
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile, ZIP_DEFLATED
|
||||
import subprocess
|
||||
|
||||
TKTCL_RE = re.compile(r'^(_?tk|tcl).+\.(pyd|dll)', re.IGNORECASE)
|
||||
DEBUG_RE = re.compile(r'_d\.(pyd|dll|exe|pdb|lib)$', re.IGNORECASE)
|
||||
PYTHON_DLL_RE = re.compile(r'python\d\d?\.dll$', re.IGNORECASE)
|
||||
|
||||
DEBUG_FILES = {
|
||||
'_ctypes_test',
|
||||
'_testbuffer',
|
||||
'_testcapi',
|
||||
'_testimportmultiple',
|
||||
'_testmultiphase',
|
||||
'xxlimited',
|
||||
'python3_dstub',
|
||||
}
|
||||
|
||||
EXCLUDE_FROM_LIBRARY = {
|
||||
'__pycache__',
|
||||
'ensurepip',
|
||||
'idlelib',
|
||||
'pydoc_data',
|
||||
'site-packages',
|
||||
'tkinter',
|
||||
'turtledemo',
|
||||
'venv',
|
||||
}
|
||||
|
||||
EXCLUDE_FILE_FROM_LIBRARY = {
|
||||
'bdist_wininst.py',
|
||||
}
|
||||
|
||||
EXCLUDE_FILE_FROM_LIBS = {
|
||||
'ssleay',
|
||||
'libeay',
|
||||
'python3stub',
|
||||
}
|
||||
|
||||
def is_not_debug(p):
|
||||
if DEBUG_RE.search(p.name):
|
||||
return False
|
||||
|
||||
if TKTCL_RE.search(p.name):
|
||||
return False
|
||||
|
||||
return p.stem.lower() not in DEBUG_FILES
|
||||
|
||||
def is_not_debug_or_python(p):
|
||||
return is_not_debug(p) and not PYTHON_DLL_RE.search(p.name)
|
||||
|
||||
def include_in_lib(p):
|
||||
name = p.name.lower()
|
||||
if p.is_dir():
|
||||
if name in EXCLUDE_FROM_LIBRARY:
|
||||
return False
|
||||
if name.startswith('plat-'):
|
||||
return False
|
||||
if name == 'test' and p.parts[-2].lower() == 'lib':
|
||||
return False
|
||||
if name in {'test', 'tests'} and p.parts[-3].lower() == 'lib':
|
||||
return False
|
||||
return True
|
||||
|
||||
if name in EXCLUDE_FILE_FROM_LIBRARY:
|
||||
return False
|
||||
|
||||
suffix = p.suffix.lower()
|
||||
return suffix not in {'.pyc', '.pyo', '.exe'}
|
||||
|
||||
def include_in_libs(p):
|
||||
if not is_not_debug(p):
|
||||
return False
|
||||
|
||||
return p.stem.lower() not in EXCLUDE_FILE_FROM_LIBS
|
||||
|
||||
def include_in_tools(p):
|
||||
if p.is_dir() and p.name.lower() in {'scripts', 'i18n', 'pynche', 'demo', 'parser'}:
|
||||
return True
|
||||
|
||||
return p.suffix.lower() in {'.py', '.pyw', '.txt'}
|
||||
|
||||
FULL_LAYOUT = [
|
||||
('/', 'PCBuild/$arch', 'python.exe', is_not_debug),
|
||||
('/', 'PCBuild/$arch', 'pythonw.exe', is_not_debug),
|
||||
('/', 'PCBuild/$arch', 'python27.dll', None),
|
||||
('DLLs/', 'PCBuild/$arch', '*.pyd', is_not_debug),
|
||||
('DLLs/', 'PCBuild/$arch', '*.dll', is_not_debug_or_python),
|
||||
('include/', 'include', '*.h', None),
|
||||
('include/', 'PC', 'pyconfig.h', None),
|
||||
('Lib/', 'Lib', '**/*', include_in_lib),
|
||||
('libs/', 'PCBuild/$arch', '*.lib', include_in_libs),
|
||||
('Tools/', 'Tools', '**/*', include_in_tools),
|
||||
('/', '', 'LICENSE*', None),
|
||||
]
|
||||
|
||||
EMBED_LAYOUT = [
|
||||
('/', 'PCBuild/$arch', 'python*.exe', is_not_debug),
|
||||
('/', 'PCBuild/$arch', '*.pyd', is_not_debug),
|
||||
('/', 'PCBuild/$arch', '*.dll', is_not_debug),
|
||||
('python{0.major}{0.minor}.zip'.format(sys.version_info), 'Lib', '**/*', include_in_lib),
|
||||
]
|
||||
|
||||
if os.getenv('DOC_FILENAME'):
|
||||
FULL_LAYOUT.append(('Doc/', 'Doc/build/htmlhelp', os.getenv('DOC_FILENAME'), None))
|
||||
if os.getenv('VCREDIST_PATH'):
|
||||
FULL_LAYOUT.append(('/', os.getenv('VCREDIST_PATH'), 'vcruntime*.dll', None))
|
||||
EMBED_LAYOUT.append(('/', os.getenv('VCREDIST_PATH'), 'vcruntime*.dll', None))
|
||||
|
||||
def copy_to_layout(target, rel_sources):
|
||||
count = 0
|
||||
|
||||
if target.suffix.lower() == '.zip':
|
||||
if target.exists():
|
||||
target.unlink()
|
||||
|
||||
with ZipFile(str(target), 'w', ZIP_DEFLATED) as f:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
for s, rel in rel_sources:
|
||||
if rel.suffix.lower() == '.py':
|
||||
pyc = Path(tmpdir) / rel.with_suffix('.pyc').name
|
||||
try:
|
||||
py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2)
|
||||
except py_compile.PyCompileError:
|
||||
f.write(str(s), str(rel))
|
||||
else:
|
||||
f.write(str(pyc), str(rel.with_suffix('.pyc')))
|
||||
else:
|
||||
f.write(str(s), str(rel))
|
||||
count += 1
|
||||
|
||||
else:
|
||||
for s, rel in rel_sources:
|
||||
dest = target / rel
|
||||
try:
|
||||
dest.parent.mkdir(parents=True)
|
||||
except FileExistsError:
|
||||
pass
|
||||
if dest.is_file():
|
||||
dest.chmod(stat.S_IWRITE)
|
||||
shutil.copy(str(s), str(dest))
|
||||
if dest.is_file():
|
||||
dest.chmod(stat.S_IWRITE)
|
||||
count += 1
|
||||
|
||||
return count
|
||||
|
||||
def rglob(root, pattern, condition):
|
||||
dirs = [root]
|
||||
recurse = pattern[:3] in {'**/', '**\\'}
|
||||
while dirs:
|
||||
d = dirs.pop(0)
|
||||
for f in d.glob(pattern[3:] if recurse else pattern):
|
||||
if recurse and f.is_dir() and (not condition or condition(f)):
|
||||
dirs.append(f)
|
||||
elif f.is_file() and (not condition or condition(f)):
|
||||
yield f, f.relative_to(root)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-s', '--source', metavar='dir', help='The directory containing the repository root', type=Path)
|
||||
parser.add_argument('-o', '--out', metavar='file', help='The name of the output self-extracting archive', type=Path, default=None)
|
||||
parser.add_argument('-t', '--temp', metavar='dir', help='A directory to temporarily extract files into', type=Path, default=None)
|
||||
parser.add_argument('-e', '--embed', help='Create an embedding layout', action='store_true', default=False)
|
||||
parser.add_argument('-a', '--arch', help='Specify the architecture to use (win32/amd64)', type=str, default="win32")
|
||||
ns = parser.parse_args()
|
||||
|
||||
source = ns.source or (Path(__file__).resolve().parent.parent.parent)
|
||||
out = ns.out
|
||||
arch = '' if ns.arch == 'win32' else ns.arch
|
||||
assert isinstance(source, Path)
|
||||
assert not out or isinstance(out, Path)
|
||||
assert isinstance(arch, str)
|
||||
|
||||
if ns.temp:
|
||||
temp = ns.temp
|
||||
delete_temp = False
|
||||
else:
|
||||
temp = Path(tempfile.mkdtemp())
|
||||
delete_temp = True
|
||||
|
||||
if out:
|
||||
try:
|
||||
out.parent.mkdir(parents=True)
|
||||
except FileExistsError:
|
||||
pass
|
||||
try:
|
||||
temp.mkdir(parents=True)
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
layout = EMBED_LAYOUT if ns.embed else FULL_LAYOUT
|
||||
|
||||
try:
|
||||
for t, s, p, c in layout:
|
||||
fs = source / s.replace("$arch", arch)
|
||||
files = rglob(fs, p, c)
|
||||
extra_files = []
|
||||
if s == 'Lib' and p == '**/*':
|
||||
extra_files.append((
|
||||
source / 'tools' / 'nuget' / 'distutils.command.bdist_wininst.py',
|
||||
Path('distutils') / 'command' / 'bdist_wininst.py'
|
||||
))
|
||||
copied = copy_to_layout(temp / t.rstrip('/'), chain(files, extra_files))
|
||||
print('Copied {} files'.format(copied))
|
||||
|
||||
if out:
|
||||
total = copy_to_layout(out, rglob(temp, '**/*', None))
|
||||
print('Wrote {} files to {}'.format(total, out))
|
||||
finally:
|
||||
if delete_temp:
|
||||
shutil.rmtree(temp, True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(int(main() or 0))
|
||||
17
Tools/nuget/python2.nuspec
Normal file
17
Tools/nuget/python2.nuspec
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<package >
|
||||
<metadata>
|
||||
<id>python2</id>
|
||||
<title>Python 2.7</title>
|
||||
<version>0.0.0.0</version>
|
||||
<authors>Python Software Foundation</authors>
|
||||
<license type="file">tools\LICENSE</license>
|
||||
<projectUrl>https://www.python.org/</projectUrl>
|
||||
<description>Installs 64-bit Python 2.7 for use in build scenarios.</description>
|
||||
<iconUrl>https://www.python.org/static/favicon.ico</iconUrl>
|
||||
<tags>python</tags>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="**\*" target="tools" />
|
||||
</files>
|
||||
</package>
|
||||
17
Tools/nuget/python2x86.nuspec
Normal file
17
Tools/nuget/python2x86.nuspec
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<package >
|
||||
<metadata>
|
||||
<id>python2x86</id>
|
||||
<title>Python 2.7 (32-bit)</title>
|
||||
<authors>Python Software Foundation</authors>
|
||||
<version>0.0.0.0</version>
|
||||
<license type="file">tools\LICENSE</license>
|
||||
<projectUrl>https://www.python.org/</projectUrl>
|
||||
<description>Installs 32-bit Python 2.7 for use in build scenarios.</description>
|
||||
<iconUrl>https://www.python.org/static/favicon.ico</iconUrl>
|
||||
<tags>python</tags>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="**\*" target="tools" />
|
||||
</files>
|
||||
</package>
|
||||
Reference in New Issue
Block a user