diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2020-05-24 16:40:40 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-05-24 16:40:40 -0400 |
| commit | 7306811598b51bfe726850ce4b061a6e389d5b80 (patch) | |
| tree | 907882aecc017d26f925f70d003371124a507d0f /tools | |
| parent | 8f1f09b7f93f2fa86bafcd6502ec51d4680b4499 (diff) | |
| parent | 52c394c1e87b863aec92949e4b494ab01a7cd234 (diff) | |
| download | python-setuptools-git-7306811598b51bfe726850ce4b061a6e389d5b80.tar.gz | |
Merge branch 'master' into docs_ci
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/finalize.py | 81 | ||||
| -rw-r--r-- | tools/tox_pip.py | 82 |
2 files changed, 163 insertions, 0 deletions
diff --git a/tools/finalize.py b/tools/finalize.py new file mode 100644 index 00000000..98b06c07 --- /dev/null +++ b/tools/finalize.py @@ -0,0 +1,81 @@ +""" +Finalize the repo for a release. Invokes towncrier and bumpversion. +""" + +__requires__ = ['bump2version', 'towncrier'] + + +import subprocess +import pathlib +import re +import sys + + +def release_kind(): + """ + Determine which release to make based on the files in the + changelog. + """ + # use min here as 'major' < 'minor' < 'patch' + return min( + 'major' if 'breaking' in file.name else + 'minor' if 'change' in file.name else + 'patch' + for file in pathlib.Path('changelog.d').iterdir() + ) + + +bump_version_command = [ + sys.executable, + '-m', 'bumpversion', + release_kind(), +] + + +def get_version(): + cmd = bump_version_command + ['--dry-run', '--verbose'] + out = subprocess.check_output(cmd, text=True) + return re.search('^new_version=(.*)', out, re.MULTILINE).group(1) + + +def update_changelog(): + cmd = [ + sys.executable, '-m', + 'towncrier', + '--version', get_version(), + '--yes', + ] + subprocess.check_call(cmd) + + +def bump_version(): + cmd = bump_version_command + ['--allow-dirty'] + subprocess.check_call(cmd) + + +def ensure_config(): + """ + Double-check that Git has an e-mail configured. + """ + subprocess.check_output(['git', 'config', 'user.email']) + + +def check_changes(): + """ + Verify that all of the files in changelog.d have the appropriate + names. + """ + allowed = 'deprecation', 'breaking', 'change', 'doc', 'misc' + assert all( + any(key in file.name for key in allowed) + for file in pathlib.Path('changelog.d').iterdir() + if file.name != '.gitignore' + ) + + +if __name__ == '__main__': + print("Cutting release at", get_version()) + ensure_config() + check_changes() + update_changelog() + bump_version() diff --git a/tools/tox_pip.py b/tools/tox_pip.py new file mode 100644 index 00000000..9fe4f905 --- /dev/null +++ b/tools/tox_pip.py @@ -0,0 +1,82 @@ +import os +import subprocess +import sys +import re + + +def remove_setuptools(): + """ + Remove setuptools from the current environment. + """ + print("Removing setuptools") + cmd = [sys.executable, '-m', 'pip', 'uninstall', '-y', 'setuptools'] + # set cwd to something other than '.' to avoid detecting + # '.' as the installed package. + subprocess.check_call(cmd, cwd='.tox') + + +def bootstrap(): + print("Running bootstrap") + cmd = [sys.executable, '-m', 'bootstrap'] + subprocess.check_call(cmd) + + +def is_install_self(args): + """ + Do the args represent an install of .? + """ + def strip_extras(arg): + match = re.match(r'(.*)?\[.*\]$', arg) + return match.group(1) if match else arg + + return ( + 'install' in args + and any( + arg in ['.', os.getcwd()] + for arg in map(strip_extras, args) + ) + ) + + +def pip(*args): + cmd = [sys.executable, '-m', 'pip'] + list(args) + return subprocess.check_call(cmd) + + +def test_dependencies(): + from ConfigParser import ConfigParser + + def clean(dep): + spec, _, _ = dep.partition('#') + return spec.strip() + + parser = ConfigParser() + parser.read('setup.cfg') + raw = parser.get('options.extras_require', 'tests').split('\n') + return filter(None, map(clean, raw)) + + +def disable_python_requires(): + """ + On Python 2, install the dependencies that are selective + on Python version while honoring REQUIRES_PYTHON, then + disable REQUIRES_PYTHON so that pip can install this + checkout of setuptools. + """ + pip('install', *test_dependencies()) + os.environ['PIP_IGNORE_REQUIRES_PYTHON'] = 'true' + + +def run(args): + os.environ['PIP_USE_PEP517'] = 'true' + + if is_install_self(args): + remove_setuptools() + bootstrap() + sys.version_info > (3,) or disable_python_requires() + + pip(*args) + + +if __name__ == '__main__': + run(sys.argv[1:]) |
