summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/finalize.py12
-rw-r--r--tools/generate_validation_code.py30
-rw-r--r--tools/msvc-build-launcher-arm64.cmd19
-rw-r--r--tools/msvc-build-launcher.cmd39
-rw-r--r--tools/towncrier_template.rst35
-rw-r--r--tools/vendored.py149
6 files changed, 282 insertions, 2 deletions
diff --git a/tools/finalize.py b/tools/finalize.py
index 516a2fb5..5a4df5df 100644
--- a/tools/finalize.py
+++ b/tools/finalize.py
@@ -42,6 +42,7 @@ def update_changelog():
cmd = [
sys.executable, '-m',
'towncrier',
+ 'build',
'--version', get_version(),
'--yes',
]
@@ -79,11 +80,18 @@ def check_changes():
"""
allowed = 'deprecation', 'breaking', 'change', 'doc', 'misc'
except_ = 'README.rst', '.gitignore'
- assert all(
- any(key in file.name for key in allowed)
+ news_fragments = (
+ file
for file in pathlib.Path('changelog.d').iterdir()
if file.name not in except_
)
+ unrecognized = [
+ str(file)
+ for file in news_fragments
+ if not any(f".{key}" in file.suffixes for key in allowed)
+ ]
+ if unrecognized:
+ raise ValueError(f"Some news fragments have invalid names: {unrecognized}")
if __name__ == '__main__':
diff --git a/tools/generate_validation_code.py b/tools/generate_validation_code.py
new file mode 100644
index 00000000..201d1b70
--- /dev/null
+++ b/tools/generate_validation_code.py
@@ -0,0 +1,30 @@
+import subprocess
+import sys
+
+from pathlib import Path
+
+
+def generate_pyproject_validation(dest: Path):
+ """
+ Generates validation code for ``pyproject.toml`` based on JSON schemas and the
+ ``validate-pyproject`` library.
+ """
+ cmd = [
+ sys.executable,
+ "-m",
+ "validate_pyproject.vendoring",
+ f"--output-dir={dest}",
+ "--enable-plugins",
+ "setuptools",
+ "distutils",
+ "--very-verbose"
+ ]
+ subprocess.check_call(cmd)
+ print(f"Validation code generated at: {dest}")
+
+
+def main():
+ generate_pyproject_validation(Path("setuptools/config/_validate_pyproject"))
+
+
+__name__ == '__main__' and main()
diff --git a/tools/msvc-build-launcher-arm64.cmd b/tools/msvc-build-launcher-arm64.cmd
new file mode 100644
index 00000000..8e63506b
--- /dev/null
+++ b/tools/msvc-build-launcher-arm64.cmd
@@ -0,0 +1,19 @@
+@echo off
+
+REM Build with jaraco/windows Docker image
+
+set PATH_OLD=%PATH%
+set PATH=C:\BuildTools\VC\Auxiliary\Build;%PATH_OLD%
+
+REM now for arm 64-bit
+REM Cross compile for arm64
+call VCVARSx86_arm64
+if "%ERRORLEVEL%"=="0" (
+ cl /D "GUI=0" /D "WIN32_LEAN_AND_MEAN" launcher.c /O2 /link /MACHINE:arm64 /SUBSYSTEM:CONSOLE /out:setuptools/cli-arm64.exe
+ cl /D "GUI=1" /D "WIN32_LEAN_AND_MEAN" launcher.c /O2 /link /MACHINE:arm64 /SUBSYSTEM:WINDOWS /out:setuptools/gui-arm64.exe
+) else (
+ echo Visual Studio 2019 with arm64 toolchain not installed
+)
+
+set PATH=%PATH_OLD%
+
diff --git a/tools/msvc-build-launcher.cmd b/tools/msvc-build-launcher.cmd
new file mode 100644
index 00000000..92da290e
--- /dev/null
+++ b/tools/msvc-build-launcher.cmd
@@ -0,0 +1,39 @@
+@echo off
+
+REM Use old Windows SDK 6.1 so created .exe will be compatible with
+REM old Windows versions.
+REM Windows SDK 6.1 may be downloaded at:
+REM http://www.microsoft.com/en-us/download/details.aspx?id=11310
+set PATH_OLD=%PATH%
+
+REM The SDK creates a false install of Visual Studio at one of these locations
+set PATH=C:\Program Files\Microsoft Visual Studio 9.0\VC\bin;%PATH%
+set PATH=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin;%PATH%
+
+REM set up the environment to compile to x86
+call VCVARS32
+if "%ERRORLEVEL%"=="0" (
+ cl /D "GUI=0" /D "WIN32_LEAN_AND_MEAN" launcher.c /O2 /link /MACHINE:x86 /SUBSYSTEM:CONSOLE /out:setuptools/cli-32.exe
+ cl /D "GUI=1" /D "WIN32_LEAN_AND_MEAN" launcher.c /O2 /link /MACHINE:x86 /SUBSYSTEM:WINDOWS /out:setuptools/gui-32.exe
+) else (
+ echo Windows SDK 6.1 not found to build Windows 32-bit version
+)
+
+REM buildout (and possibly other implementations) currently depend on
+REM the 32-bit launcher scripts without the -32 in the filename, so copy them
+REM there for now.
+copy setuptools/cli-32.exe setuptools/cli.exe
+copy setuptools/gui-32.exe setuptools/gui.exe
+
+REM now for 64-bit
+REM Use the x86_amd64 profile, which is the 32-bit cross compiler for amd64
+call VCVARSx86_amd64
+if "%ERRORLEVEL%"=="0" (
+ cl /D "GUI=0" /D "WIN32_LEAN_AND_MEAN" launcher.c /O2 /link /MACHINE:x64 /SUBSYSTEM:CONSOLE /out:setuptools/cli-64.exe
+ cl /D "GUI=1" /D "WIN32_LEAN_AND_MEAN" launcher.c /O2 /link /MACHINE:x64 /SUBSYSTEM:WINDOWS /out:setuptools/gui-64.exe
+) else (
+ echo Windows SDK 6.1 not found to build Windows 64-bit version
+)
+
+set PATH=%PATH_OLD%
+
diff --git a/tools/towncrier_template.rst b/tools/towncrier_template.rst
new file mode 100644
index 00000000..7f507342
--- /dev/null
+++ b/tools/towncrier_template.rst
@@ -0,0 +1,35 @@
+{% if top_line %}
+{{ top_line }}
+{{ top_underline * ((top_line)|length)}}
+{% endif %}
+{% for section, _ in sections.items() %}
+{% set underline = underlines[0] %}{% if section %}{{section}}
+{{ underline * section|length }}
+{% set underline = underlines[1] %}
+{% endif %}
+
+{% if sections[section] %}
+{% for category, val in definitions.items() if category in sections[section]%}
+
+{{ definitions[category]['name'] }}
+{{ underline * definitions[category]['name']|length }}
+{% if definitions[category]['showcontent'] %}
+{% for text, values in sections[section][category].items() %}
+* {{ values|join(', ') }}: {{ text }}
+{% endfor %}
+{% else %}
+* {{ sections[section][category]['']|join(', ') }}
+
+{% endif %}
+{% if sections[section][category]|length == 0 %}
+No significant changes.
+{% else %}
+{% endif %}
+{% endfor %}
+
+{% else %}
+No significant changes.
+
+
+{% endif %}
+{% endfor %}
diff --git a/tools/vendored.py b/tools/vendored.py
new file mode 100644
index 00000000..cd15adbf
--- /dev/null
+++ b/tools/vendored.py
@@ -0,0 +1,149 @@
+import re
+import sys
+import subprocess
+
+from path import Path
+
+
+def remove_all(paths):
+ for path in paths:
+ path.rmtree() if path.isdir() else path.remove()
+
+
+def update_vendored():
+ update_pkg_resources()
+ update_setuptools()
+
+
+def rewrite_packaging(pkg_files, new_root):
+ """
+ Rewrite imports in packaging to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.text()
+ text = re.sub(r' (pyparsing)', rf' {new_root}.\1', text)
+ text = text.replace(
+ 'from six.moves.urllib import parse',
+ 'from urllib import parse',
+ )
+ file.write_text(text)
+
+
+def rewrite_jaraco_text(pkg_files, new_root):
+ """
+ Rewrite imports in jaraco.text to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text()
+ text = re.sub(r' (jaraco\.)', rf' {new_root}.\1', text)
+ text = re.sub(r' (importlib_resources)', rf' {new_root}.\1', text)
+ # suppress loading of lorem_ipsum; ref #3072
+ text = re.sub(r'^lorem_ipsum.*\n$', '', text, flags=re.M)
+ file.write_text(text)
+
+
+def rewrite_jaraco(pkg_files, new_root):
+ """
+ Rewrite imports in jaraco.functools to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text()
+ text = re.sub(r' (more_itertools)', rf' {new_root}.\1', text)
+ file.write_text(text)
+ # required for zip-packaged setuptools #3084
+ pkg_files.joinpath('__init__.py').write_text('')
+
+
+def rewrite_importlib_resources(pkg_files, new_root):
+ """
+ Rewrite imports in importlib_resources to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text().replace('importlib_resources.abc', '.abc')
+ text = text.replace('zipp', '..zipp')
+ file.write_text(text)
+
+
+def rewrite_importlib_metadata(pkg_files, new_root):
+ """
+ Rewrite imports in importlib_metadata to redirect to vendored copies.
+ """
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text().replace('typing_extensions', '..typing_extensions')
+ text = text.replace('import zipp', 'from .. import zipp')
+ file.write_text(text)
+
+
+def rewrite_more_itertools(pkg_files: Path):
+ """
+ Defer import of concurrent.futures. Workaround for #3090.
+ """
+ more_file = pkg_files.joinpath('more.py')
+ text = more_file.read_text()
+ text = re.sub(r'^.*concurrent.futures.*?\n', '', text, flags=re.MULTILINE)
+ text = re.sub(
+ 'ThreadPoolExecutor',
+ '__import__("concurrent.futures").futures.ThreadPoolExecutor',
+ text,
+ )
+ more_file.write_text(text)
+
+
+def rewrite_nspektr(pkg_files: Path, new_root):
+ for file in pkg_files.glob('*.py'):
+ text = file.read_text()
+ text = re.sub(r' (more_itertools)', rf' {new_root}.\1', text)
+ text = re.sub(r' (jaraco\.\w+)', rf' {new_root}.\1', text)
+ text = re.sub(r' (packaging)', rf' {new_root}.\1', text)
+ text = re.sub(r' (importlib_metadata)', rf' {new_root}.\1', text)
+ file.write_text(text)
+
+
+def clean(vendor):
+ """
+ Remove all files out of the vendor directory except the meta
+ data (as pip uninstall doesn't support -t).
+ """
+ remove_all(
+ path
+ for path in vendor.glob('*')
+ if path.basename() != 'vendored.txt'
+ )
+
+
+def install(vendor):
+ clean(vendor)
+ install_args = [
+ sys.executable,
+ '-m', 'pip',
+ 'install',
+ '-r', str(vendor / 'vendored.txt'),
+ '-t', str(vendor),
+ ]
+ subprocess.check_call(install_args)
+ (vendor / '__init__.py').write_text('')
+
+
+def update_pkg_resources():
+ vendor = Path('pkg_resources/_vendor')
+ install(vendor)
+ rewrite_packaging(vendor / 'packaging', 'pkg_resources.extern')
+ rewrite_jaraco_text(vendor / 'jaraco/text', 'pkg_resources.extern')
+ rewrite_jaraco(vendor / 'jaraco', 'pkg_resources.extern')
+ rewrite_importlib_resources(vendor / 'importlib_resources', 'pkg_resources.extern')
+ rewrite_more_itertools(vendor / "more_itertools")
+
+
+def update_setuptools():
+ vendor = Path('setuptools/_vendor')
+ install(vendor)
+ rewrite_packaging(vendor / 'packaging', 'setuptools.extern')
+ rewrite_jaraco_text(vendor / 'jaraco/text', 'setuptools.extern')
+ rewrite_jaraco(vendor / 'jaraco', 'setuptools.extern')
+ rewrite_importlib_resources(vendor / 'importlib_resources', 'setuptools.extern')
+ rewrite_importlib_metadata(vendor / 'importlib_metadata', 'setuptools.extern')
+ rewrite_more_itertools(vendor / "more_itertools")
+ rewrite_nspektr(vendor / "nspektr", 'setuptools.extern')
+
+
+__name__ == '__main__' and update_vendored()