chore: cleanup style in bin (#648)

* chore: cleanup style for bump_version

* chore: cleanup style for other bin items
This commit is contained in:
Henry Schreiner
2021-04-25 03:45:27 -04:00
committed by GitHub
parent 22d473acc0
commit 2f47e64225
9 changed files with 86 additions and 58 deletions
+6
View File
@@ -39,7 +39,13 @@ repos:
rev: v2.12.0 rev: v2.12.0
hooks: hooks:
- id: pyupgrade - id: pyupgrade
name: PyUpgrade 3.6+
args: ["--py36-plus"] args: ["--py36-plus"]
exclude: ^bin/
- id: pyupgrade
name: PyUpgrade 3.7+ on bin
exclude: ^(cibuildwheel|unit_test|test)/
args: ["--py37-plus"]
- repo: https://github.com/PyCQA/flake8 - repo: https://github.com/PyCQA/flake8
rev: 3.9.1 rev: 3.9.1
+26 -23
View File
@@ -1,6 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import annotations
import glob import glob
import os import os
import subprocess import subprocess
@@ -25,24 +27,26 @@ config = [
('setup.cfg', "version = {}"), ('setup.cfg', "version = {}"),
] ]
RED = "\u001b[31m"
GREEN = "\u001b[32m"
OFF = "\u001b[0m"
# This file requires Python 3.7
# Setting -> None will cause MyPy to notice this.
@click.command() @click.command()
def bump_version(): def bump_version() -> None:
current_version = cibuildwheel.__version__ current_version = cibuildwheel.__version__
try: try:
commit_date_str = subprocess.run([ commit_date_str = subprocess.run([
'git', 'git',
'show', '-s', '--pretty=format:%ci', 'show', '--no-patch', '--pretty=format:%ci',
f'v{current_version}^{{commit}}' f'v{current_version}^{{commit}}',
], check=True, capture_output=True, encoding='utf8').stdout ], check=True, capture_output=True, encoding='utf8').stdout
commit_date_parts = commit_date_str.split(' ') cd_date, cd_time, cd_tz = commit_date_str.split(' ')
url_opts = urllib.parse.urlencode({'q': f'is:pr merged:>{cd_date}T{cd_time}{cd_tz}'})
url = f'https://github.com/joerick/cibuildwheel/pulls?{url_opts}'
url = 'https://github.com/joerick/cibuildwheel/pulls?' + urllib.parse.urlencode({
'q': f'is:pr merged:>{commit_date_parts[0]}T{commit_date_parts[1]}{commit_date_parts[2]}',
})
print(f'PRs merged since last release:\n {url}') print(f'PRs merged since last release:\n {url}')
print() print()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
@@ -56,8 +60,10 @@ def bump_version():
print('error: Uncommitted changes detected.') print('error: Uncommitted changes detected.')
sys.exit(1) sys.exit(1)
# fmt: off
print( 'Current version:', current_version) # noqa print( 'Current version:', current_version) # noqa
new_version = input(' New version: ').strip() new_version = input(' New version: ').strip()
# fmt: on
try: try:
Version(new_version) Version(new_version)
@@ -72,7 +78,7 @@ def bump_version():
paths = [Path(p) for p in glob.glob(path_pattern)] paths = [Path(p) for p in glob.glob(path_pattern)]
if not paths: if not paths:
print(f'error: Pattern {path_pattern} didnt match any files') print(f"error: Pattern {path_pattern} didn't match any files")
sys.exit(1) sys.exit(1)
find_pattern = version_pattern.format(current_version) find_pattern = version_pattern.format(current_version)
@@ -84,11 +90,11 @@ def bump_version():
if find_pattern in contents: if find_pattern in contents:
found_at_least_one_file_needing_update = True found_at_least_one_file_needing_update = True
actions.append( actions.append(
(path, find_pattern, replace_pattern) (path, find_pattern, replace_pattern,)
) )
if not found_at_least_one_file_needing_update: if not found_at_least_one_file_needing_update:
print(f'error: Didnt find any occurrences of {find_pattern} in {path_pattern}') print(f'''error: Didn't find any occurrences of "{find_pattern}" in "{path_pattern}"''')
sys.exit(1) sys.exit(1)
print() print()
@@ -96,10 +102,8 @@ def bump_version():
print() print()
for action in actions: for action in actions:
print('{} {red}{}{off}{green}{}{off}'.format( path, find, replace = action
*action, print(f'{path} {RED}{find}{OFF}{GREEN}{replace}{OFF}')
red="\u001b[31m", green="\u001b[32m", off="\u001b[0m"
))
print(f'Then commit, and tag as v{new_version}') print(f'Then commit, and tag as v{new_version}')
@@ -123,21 +127,20 @@ def bump_version():
subprocess.run([ subprocess.run([
'git', 'commit', 'git', 'commit',
'-a', '--all',
'-m', f'Bump version: v{new_version}' f"--message='Bump version: v{new_version}'",
], check=True) ], check=True)
subprocess.run([ subprocess.run([
'git', 'tag', 'git', 'tag',
'-a', '--annotate',
'-m', f'v{new_version}', f"--message='v{new_version}'",
f'v{new_version}' f'v{new_version}',
], check=True) ], check=True)
print('Done.') print('Done.')
if __name__ == '__main__': if __name__ == '__main__':
os.chdir(os.path.dirname(__file__)) os.chdir(Path(__file__).parent.parent.resolve())
os.chdir('..')
bump_version() bump_version()
+10 -7
View File
@@ -1,5 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import annotations
import os import os
import sys import sys
import textwrap import textwrap
@@ -49,17 +51,18 @@ def main():
return return
shell('git commit -a -m "Update dependencies"', check=True) shell('git commit -a -m "Update dependencies"', check=True)
run( body = textwrap.dedent(f'''
[
'gh', 'pr', 'create',
'--repo', 'joerick/cibuildwheel',
'--base', 'master',
'--title', 'Update dependencies',
'--body', textwrap.dedent(f'''
Update the versions of our dependencies. Update the versions of our dependencies.
PR generated by `{os.path.basename(__file__)}`. PR generated by `{os.path.basename(__file__)}`.
''') ''')
run(
[
'gh', 'pr', 'create',
'--repo=joerick/cibuildwheel',
'--base=master',
"--title='Update dependencies'",
f"--body='{body}'",
], ],
check=True check=True
) )
+13 -11
View File
@@ -9,14 +9,17 @@ Suggested usage:
git diff git diff
""" """
from __future__ import annotations
import builtins import builtins
import functools import functools
import textwrap
import urllib.request import urllib.request
import xml.dom.minidom import xml.dom.minidom
from datetime import datetime from datetime import datetime
from io import StringIO from io import StringIO
from pathlib import Path from pathlib import Path
from typing import Any, Dict, List, Optional, TextIO from typing import Any, TextIO
import click import click
import yaml import yaml
@@ -38,7 +41,7 @@ ICONS = (
class Project: class Project:
NAME: int = 0 NAME: int = 0
def __init__(self, config: Dict[str, Any], github: Optional[Github] = None): def __init__(self, config: dict[str, Any], github: Github | None = None):
try: try:
self.name: str = config["name"] self.name: str = config["name"]
self.gh: str = config["gh"] self.gh: str = config["gh"]
@@ -48,8 +51,8 @@ class Project:
self.stars_repo: str = config.get("stars", self.gh) self.stars_repo: str = config.get("stars", self.gh)
self.notes: str = config.get("notes", "") self.notes: str = config.get("notes", "")
self.ci: List[str] = config.get("ci", []) self.ci: list[str] = config.get("ci", [])
self.os: List[str] = config.get("os", []) self.os: list[str] = config.get("os", [])
self.online = github is not None self.online = github is not None
if github is not None: if github is not None:
@@ -72,7 +75,7 @@ class Project:
name_len = len(self.name) + 4 name_len = len(self.name) + 4
self.__class__.NAME = max(self.__class__.NAME, name_len) self.__class__.NAME = max(self.__class__.NAME, name_len)
def __lt__(self, other: "Project") -> bool: def __lt__(self, other: Project) -> bool:
if self.online: if self.online:
return self.num_stars < other.num_stars return self.num_stars < other.num_stars
else: else:
@@ -80,10 +83,9 @@ class Project:
@classmethod @classmethod
def header(cls) -> str: def header(cls) -> str:
return ( return textwrap.dedent(f"""\
f"| {'Name':{cls.NAME}} | CI | OS | Notes |\n" | {'Name':{cls.NAME}} | CI | OS | Notes |
f"|{'':-^{cls.NAME+2 }}|----|----|:------|" |{'':-^{cls.NAME+2 }}|----|----|:------|""")
)
@property @property
def namelink(self) -> str: def namelink(self) -> str:
@@ -140,7 +142,7 @@ def path_for_icon(icon_name: str) -> Path:
def str_projects( def str_projects(
config: List[Dict[str, Any]], *, online: bool = True, auth: Optional[str] = None config: list[dict[str, Any]], *, online: bool = True, auth: str | None = None,
) -> str: ) -> str:
io = StringIO() io = StringIO()
print = functools.partial(builtins.print, file=io) print = functools.partial(builtins.print, file=io)
@@ -178,7 +180,7 @@ def str_projects(
@click.option("--auth", help="GitHub authentication token") @click.option("--auth", help="GitHub authentication token")
@click.option("--readme", type=click.File("r+"), help="Modify a readme file if given") @click.option("--readme", type=click.File("r+"), help="Modify a readme file if given")
def projects( def projects(
input: TextIO, online: bool, auth: Optional[str], readme: Optional[TextIO] input: TextIO, online: bool, auth: str | None, readme: TextIO | None
) -> None: ) -> None:
config = yaml.safe_load(input) config = yaml.safe_load(input)
output = str_projects(config, online=online, auth=auth) output = str_projects(config, online=online, auth=auth)
+5 -2
View File
@@ -1,5 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import annotations
import os import os
import shutil import shutil
import sys import sys
@@ -123,13 +125,14 @@ def run_example_ci_configs(config_files=None):
shutil.copyfile(src_config_file, dst_config_file) shutil.copyfile(src_config_file, dst_config_file)
run(['git', 'add', example_project], check=True) run(['git', 'add', example_project], check=True)
run(['git', 'commit', '--no-verify', '-m', textwrap.dedent(f''' message = textwrap.dedent(f'''
Test example minimal configs Test example minimal configs
Testing files: {config_files} Testing files: {config_files}
Generated from branch: {previous_branch} Generated from branch: {previous_branch}
Time: {timestamp} Time: {timestamp}
''')], check=True) ''')
run(['git', 'commit', '--no-verify', '--message', message], check=True)
shell(f'git subtree --prefix={example_project} push origin {branch_name}', check=True) shell(f'git subtree --prefix={example_project} push origin {branch_name}', check=True)
print('---') print('---')
+2
View File
@@ -1,5 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import annotations
import argparse import argparse
import os import os
import subprocess import subprocess
+13 -9
View File
@@ -1,11 +1,12 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import annotations
import configparser import configparser
import os import os
import shutil import shutil
import subprocess import subprocess
import sys import sys
from collections import namedtuple from typing import NamedTuple
import requests import requests
@@ -25,7 +26,7 @@ if '--no-docker' in sys.argv:
'--allow-unsafe', '--allow-unsafe',
'--upgrade', '--upgrade',
'cibuildwheel/resources/constraints.in', 'cibuildwheel/resources/constraints.in',
'--output-file', f'cibuildwheel/resources/constraints-python{python_version}.txt' '--output-file=cibuildwheel/resources/constraints-python{python_version}.txt',
], check=True) ], check=True)
else: else:
# latest manylinux2010 image with cpython 2.7 support # latest manylinux2010 image with cpython 2.7 support
@@ -47,14 +48,15 @@ else:
], check=True) ], check=True)
# default constraints.txt # default constraints.txt
shutil.copyfile(f'cibuildwheel/resources/constraints-python{PYTHON_VERSIONS[-1]}.txt', 'cibuildwheel/resources/constraints.txt') shutil.copyfile(f'cibuildwheel/resources/constraints-python{PYTHON_VERSIONS[-1]}.txt', 'cibuildwheel/resources/constraints.txt',)
class Image(NamedTuple):
manylinux_version: str
platform: str
image_name: str
tag: str | None
Image = namedtuple('Image', [
'manylinux_version',
'platform',
'image_name',
'tag',
])
images = [ images = [
Image('manylinux1', 'x86_64', 'quay.io/pypa/manylinux1_x86_64', None), Image('manylinux1', 'x86_64', 'quay.io/pypa/manylinux1_x86_64', None),
@@ -66,12 +68,14 @@ images = [
Image('manylinux2010', 'pypy_x86_64', 'pypywheels/manylinux2010-pypy_x86_64', None), Image('manylinux2010', 'pypy_x86_64', 'pypywheels/manylinux2010-pypy_x86_64', None),
# 2014 images
Image('manylinux2014', 'x86_64', 'quay.io/pypa/manylinux2014_x86_64', None), Image('manylinux2014', 'x86_64', 'quay.io/pypa/manylinux2014_x86_64', None),
Image('manylinux2014', 'i686', 'quay.io/pypa/manylinux2014_i686', None), Image('manylinux2014', 'i686', 'quay.io/pypa/manylinux2014_i686', None),
Image('manylinux2014', 'aarch64', 'quay.io/pypa/manylinux2014_aarch64', None), Image('manylinux2014', 'aarch64', 'quay.io/pypa/manylinux2014_aarch64', None),
Image('manylinux2014', 'ppc64le', 'quay.io/pypa/manylinux2014_ppc64le', None), Image('manylinux2014', 'ppc64le', 'quay.io/pypa/manylinux2014_ppc64le', None),
Image('manylinux2014', 's390x', 'quay.io/pypa/manylinux2014_s390x', None), Image('manylinux2014', 's390x', 'quay.io/pypa/manylinux2014_s390x', None),
# 2_24 images
Image('manylinux_2_24', 'x86_64', 'quay.io/pypa/manylinux_2_24_x86_64', None), Image('manylinux_2_24', 'x86_64', 'quay.io/pypa/manylinux_2_24_x86_64', None),
Image('manylinux_2_24', 'i686', 'quay.io/pypa/manylinux_2_24_i686', None), Image('manylinux_2_24', 'i686', 'quay.io/pypa/manylinux_2_24_i686', None),
Image('manylinux_2_24', 'aarch64', 'quay.io/pypa/manylinux_2_24_aarch64', None), Image('manylinux_2_24', 'aarch64', 'quay.io/pypa/manylinux_2_24_aarch64', None),
+8 -6
View File
@@ -1,10 +1,12 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import annotations
import copy import copy
import difflib import difflib
import logging import logging
from pathlib import Path from pathlib import Path
from typing import Dict, Optional, Union from typing import Union
import click import click
import requests import requests
@@ -80,7 +82,7 @@ class WindowsVersions:
versions = (Version(v) for v in cp_info["versions"]) versions = (Version(v) for v in cp_info["versions"])
self.versions = sorted(v for v in versions if not v.is_devrelease) self.versions = sorted(v for v in versions if not v.is_devrelease)
def update_version_windows(self, spec: Specifier) -> Optional[ConfigWinCP]: def update_version_windows(self, spec: Specifier) -> ConfigWinCP | None:
versions = sorted(v for v in self.versions if spec.contains(v)) versions = sorted(v for v in self.versions if spec.contains(v))
if not all(v.is_prerelease for v in versions): if not all(v.is_prerelease for v in versions):
versions = [v for v in versions if not v.is_prerelease] versions = [v for v in versions if not v.is_prerelease]
@@ -170,7 +172,7 @@ class CPythonVersions:
releases_info = response.json() releases_info = response.json()
self.versions_dict: Dict[Version, int] = {} self.versions_dict: dict[Version, int] = {}
for release in releases_info: for release in releases_info:
# Removing the prefix, Python 3.9 would use: release["name"].removeprefix("Python ") # Removing the prefix, Python 3.9 would use: release["name"].removeprefix("Python ")
version = Version(release["name"][7:]) version = Version(release["name"][7:])
@@ -179,7 +181,7 @@ class CPythonVersions:
uri = int(release["resource_uri"].rstrip("/").split("/")[-1]) uri = int(release["resource_uri"].rstrip("/").split("/")[-1])
self.versions_dict[version] = uri self.versions_dict[version] = uri
def update_version_macos(self, identifier: str, spec: Specifier) -> Optional[ConfigMacOS]: def update_version_macos(self, identifier: str, spec: Specifier) -> ConfigMacOS | None:
file_idents = ("macos11.pkg", "macosx10.9.pkg", "macosx10.6.pkg") file_idents = ("macos11.pkg", "macosx10.9.pkg", "macosx10.6.pkg")
sorted_versions = sorted(v for v in self.versions_dict if spec.contains(v)) sorted_versions = sorted(v for v in self.versions_dict if spec.contains(v))
@@ -215,13 +217,13 @@ class AllVersions:
self.macos_cpython = CPythonVersions() self.macos_cpython = CPythonVersions()
self.macos_pypy = PyPyVersions("64") self.macos_pypy = PyPyVersions("64")
def update_config(self, config: Dict[str, str]) -> None: def update_config(self, config: dict[str, str]) -> None:
identifier = config["identifier"] identifier = config["identifier"]
version = Version(config["version"]) version = Version(config["version"])
spec = Specifier(f"=={version.major}.{version.minor}.*") spec = Specifier(f"=={version.major}.{version.minor}.*")
log.info(f"Reading in '{identifier}' -> {spec} @ {version}") log.info(f"Reading in '{identifier}' -> {spec} @ {version}")
orig_config = copy.copy(config) orig_config = copy.copy(config)
config_update: Optional[AnyConfig] config_update: AnyConfig | None
# We need to use ** in update due to MyPy (probably a bug) # We need to use ** in update due to MyPy (probably a bug)
if "macos" in identifier: if "macos" in identifier:
+3
View File
@@ -64,6 +64,9 @@ exclude =
[tool:pytest] [tool:pytest]
junit_family=xunit2 junit_family=xunit2
testpaths =
test
unit_test
[mypy] [mypy]
python_version = 3.7 python_version = 3.7