chore: cleanup style in bin (#648)
* chore: cleanup style for bump_version * chore: cleanup style for other bin items
This commit is contained in:
@@ -39,7 +39,13 @@ repos:
|
||||
rev: v2.12.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
name: PyUpgrade 3.6+
|
||||
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
|
||||
rev: 3.9.1
|
||||
|
||||
+26
-23
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
@@ -25,24 +27,26 @@ config = [
|
||||
('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()
|
||||
def bump_version():
|
||||
def bump_version() -> None:
|
||||
current_version = cibuildwheel.__version__
|
||||
|
||||
try:
|
||||
commit_date_str = subprocess.run([
|
||||
'git',
|
||||
'show', '-s', '--pretty=format:%ci',
|
||||
f'v{current_version}^{{commit}}'
|
||||
'show', '--no-patch', '--pretty=format:%ci',
|
||||
f'v{current_version}^{{commit}}',
|
||||
], 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()
|
||||
except subprocess.CalledProcessError as e:
|
||||
@@ -56,8 +60,10 @@ def bump_version():
|
||||
print('error: Uncommitted changes detected.')
|
||||
sys.exit(1)
|
||||
|
||||
# fmt: off
|
||||
print( 'Current version:', current_version) # noqa
|
||||
new_version = input(' New version: ').strip()
|
||||
# fmt: on
|
||||
|
||||
try:
|
||||
Version(new_version)
|
||||
@@ -72,7 +78,7 @@ def bump_version():
|
||||
paths = [Path(p) for p in glob.glob(path_pattern)]
|
||||
|
||||
if not paths:
|
||||
print(f'error: Pattern {path_pattern} didn’t match any files')
|
||||
print(f"error: Pattern {path_pattern} didn't match any files")
|
||||
sys.exit(1)
|
||||
|
||||
find_pattern = version_pattern.format(current_version)
|
||||
@@ -84,11 +90,11 @@ def bump_version():
|
||||
if find_pattern in contents:
|
||||
found_at_least_one_file_needing_update = True
|
||||
actions.append(
|
||||
(path, find_pattern, replace_pattern)
|
||||
(path, find_pattern, replace_pattern,)
|
||||
)
|
||||
|
||||
if not found_at_least_one_file_needing_update:
|
||||
print(f'error: Didn’t 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)
|
||||
|
||||
print()
|
||||
@@ -96,10 +102,8 @@ def bump_version():
|
||||
print()
|
||||
|
||||
for action in actions:
|
||||
print('{} {red}{}{off} → {green}{}{off}'.format(
|
||||
*action,
|
||||
red="\u001b[31m", green="\u001b[32m", off="\u001b[0m"
|
||||
))
|
||||
path, find, replace = action
|
||||
print(f'{path} {RED}{find}{OFF} → {GREEN}{replace}{OFF}')
|
||||
|
||||
print(f'Then commit, and tag as v{new_version}')
|
||||
|
||||
@@ -123,21 +127,20 @@ def bump_version():
|
||||
|
||||
subprocess.run([
|
||||
'git', 'commit',
|
||||
'-a',
|
||||
'-m', f'Bump version: v{new_version}'
|
||||
'--all',
|
||||
f"--message='Bump version: v{new_version}'",
|
||||
], check=True)
|
||||
|
||||
subprocess.run([
|
||||
'git', 'tag',
|
||||
'-a',
|
||||
'-m', f'v{new_version}',
|
||||
f'v{new_version}'
|
||||
'--annotate',
|
||||
f"--message='v{new_version}'",
|
||||
f'v{new_version}',
|
||||
], check=True)
|
||||
|
||||
print('Done.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
os.chdir('..')
|
||||
os.chdir(Path(__file__).parent.parent.resolve())
|
||||
bump_version()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
@@ -49,17 +51,18 @@ def main():
|
||||
return
|
||||
|
||||
shell('git commit -a -m "Update dependencies"', check=True)
|
||||
run(
|
||||
[
|
||||
'gh', 'pr', 'create',
|
||||
'--repo', 'joerick/cibuildwheel',
|
||||
'--base', 'master',
|
||||
'--title', 'Update dependencies',
|
||||
'--body', textwrap.dedent(f'''
|
||||
body = textwrap.dedent(f'''
|
||||
Update the versions of our dependencies.
|
||||
|
||||
PR generated by `{os.path.basename(__file__)}`.
|
||||
''')
|
||||
run(
|
||||
[
|
||||
'gh', 'pr', 'create',
|
||||
'--repo=joerick/cibuildwheel',
|
||||
'--base=master',
|
||||
"--title='Update dependencies'",
|
||||
f"--body='{body}'",
|
||||
],
|
||||
check=True
|
||||
)
|
||||
|
||||
+13
-11
@@ -9,14 +9,17 @@ Suggested usage:
|
||||
git diff
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import builtins
|
||||
import functools
|
||||
import textwrap
|
||||
import urllib.request
|
||||
import xml.dom.minidom
|
||||
from datetime import datetime
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, TextIO
|
||||
from typing import Any, TextIO
|
||||
|
||||
import click
|
||||
import yaml
|
||||
@@ -38,7 +41,7 @@ ICONS = (
|
||||
class Project:
|
||||
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:
|
||||
self.name: str = config["name"]
|
||||
self.gh: str = config["gh"]
|
||||
@@ -48,8 +51,8 @@ class Project:
|
||||
|
||||
self.stars_repo: str = config.get("stars", self.gh)
|
||||
self.notes: str = config.get("notes", "")
|
||||
self.ci: List[str] = config.get("ci", [])
|
||||
self.os: List[str] = config.get("os", [])
|
||||
self.ci: list[str] = config.get("ci", [])
|
||||
self.os: list[str] = config.get("os", [])
|
||||
|
||||
self.online = github is not None
|
||||
if github is not None:
|
||||
@@ -72,7 +75,7 @@ class Project:
|
||||
name_len = len(self.name) + 4
|
||||
self.__class__.NAME = max(self.__class__.NAME, name_len)
|
||||
|
||||
def __lt__(self, other: "Project") -> bool:
|
||||
def __lt__(self, other: Project) -> bool:
|
||||
if self.online:
|
||||
return self.num_stars < other.num_stars
|
||||
else:
|
||||
@@ -80,10 +83,9 @@ class Project:
|
||||
|
||||
@classmethod
|
||||
def header(cls) -> str:
|
||||
return (
|
||||
f"| {'Name':{cls.NAME}} | CI | OS | Notes |\n"
|
||||
f"|{'':-^{cls.NAME+2 }}|----|----|:------|"
|
||||
)
|
||||
return textwrap.dedent(f"""\
|
||||
| {'Name':{cls.NAME}} | CI | OS | Notes |
|
||||
|{'':-^{cls.NAME+2 }}|----|----|:------|""")
|
||||
|
||||
@property
|
||||
def namelink(self) -> str:
|
||||
@@ -140,7 +142,7 @@ def path_for_icon(icon_name: str) -> Path:
|
||||
|
||||
|
||||
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:
|
||||
io = StringIO()
|
||||
print = functools.partial(builtins.print, file=io)
|
||||
@@ -178,7 +180,7 @@ def str_projects(
|
||||
@click.option("--auth", help="GitHub authentication token")
|
||||
@click.option("--readme", type=click.File("r+"), help="Modify a readme file if given")
|
||||
def projects(
|
||||
input: TextIO, online: bool, auth: Optional[str], readme: Optional[TextIO]
|
||||
input: TextIO, online: bool, auth: str | None, readme: TextIO | None
|
||||
) -> None:
|
||||
config = yaml.safe_load(input)
|
||||
output = str_projects(config, online=online, auth=auth)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
@@ -123,13 +125,14 @@ def run_example_ci_configs(config_files=None):
|
||||
shutil.copyfile(src_config_file, dst_config_file)
|
||||
|
||||
run(['git', 'add', example_project], check=True)
|
||||
run(['git', 'commit', '--no-verify', '-m', textwrap.dedent(f'''
|
||||
message = textwrap.dedent(f'''
|
||||
Test example minimal configs
|
||||
|
||||
Testing files: {config_files}
|
||||
Generated from branch: {previous_branch}
|
||||
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)
|
||||
|
||||
print('---')
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import configparser
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
from typing import NamedTuple
|
||||
|
||||
import requests
|
||||
|
||||
@@ -25,7 +26,7 @@ if '--no-docker' in sys.argv:
|
||||
'--allow-unsafe',
|
||||
'--upgrade',
|
||||
'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)
|
||||
else:
|
||||
# latest manylinux2010 image with cpython 2.7 support
|
||||
@@ -47,14 +48,15 @@ else:
|
||||
], check=True)
|
||||
|
||||
# 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 = [
|
||||
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),
|
||||
|
||||
# 2014 images
|
||||
Image('manylinux2014', 'x86_64', 'quay.io/pypa/manylinux2014_x86_64', None),
|
||||
Image('manylinux2014', 'i686', 'quay.io/pypa/manylinux2014_i686', None),
|
||||
Image('manylinux2014', 'aarch64', 'quay.io/pypa/manylinux2014_aarch64', None),
|
||||
Image('manylinux2014', 'ppc64le', 'quay.io/pypa/manylinux2014_ppc64le', 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', 'i686', 'quay.io/pypa/manylinux_2_24_i686', None),
|
||||
Image('manylinux_2_24', 'aarch64', 'quay.io/pypa/manylinux_2_24_aarch64', None),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import difflib
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, Union
|
||||
from typing import Union
|
||||
|
||||
import click
|
||||
import requests
|
||||
@@ -80,7 +82,7 @@ class WindowsVersions:
|
||||
versions = (Version(v) for v in cp_info["versions"])
|
||||
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))
|
||||
if not all(v.is_prerelease for v in versions):
|
||||
versions = [v for v in versions if not v.is_prerelease]
|
||||
@@ -170,7 +172,7 @@ class CPythonVersions:
|
||||
|
||||
releases_info = response.json()
|
||||
|
||||
self.versions_dict: Dict[Version, int] = {}
|
||||
self.versions_dict: dict[Version, int] = {}
|
||||
for release in releases_info:
|
||||
# Removing the prefix, Python 3.9 would use: release["name"].removeprefix("Python ")
|
||||
version = Version(release["name"][7:])
|
||||
@@ -179,7 +181,7 @@ class CPythonVersions:
|
||||
uri = int(release["resource_uri"].rstrip("/").split("/")[-1])
|
||||
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")
|
||||
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_pypy = PyPyVersions("64")
|
||||
|
||||
def update_config(self, config: Dict[str, str]) -> None:
|
||||
def update_config(self, config: dict[str, str]) -> None:
|
||||
identifier = config["identifier"]
|
||||
version = Version(config["version"])
|
||||
spec = Specifier(f"=={version.major}.{version.minor}.*")
|
||||
log.info(f"Reading in '{identifier}' -> {spec} @ {version}")
|
||||
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)
|
||||
if "macos" in identifier:
|
||||
|
||||
Reference in New Issue
Block a user