Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup style in bin #648

Merged
merged 2 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ repos:
rev: v2.11.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.0
Expand Down
49 changes: 26 additions & 23 deletions bin/bump_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3


from __future__ import annotations

import glob
import os
import subprocess
Expand All @@ -25,24 +27,26 @@
('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:
Expand All @@ -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)
Expand All @@ -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} didnt match any files')
print(f"error: Pattern {path_pattern} didn't match any files")
sys.exit(1)

find_pattern = version_pattern.format(current_version)
Expand All @@ -84,22 +90,20 @@ 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: 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)

print()
print("Here's the plan:")
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}')

Expand All @@ -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()
17 changes: 10 additions & 7 deletions bin/make_dependency_update_pr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import os
import sys
import textwrap
Expand Down Expand Up @@ -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
)
Expand Down
24 changes: 13 additions & 11 deletions bin/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
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
Expand All @@ -38,7 +41,7 @@
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"]
Expand All @@ -48,8 +51,8 @@ def __init__(self, config: Dict[str, Any], github: Optional[Github] = None):

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:
Expand All @@ -72,18 +75,17 @@ def __init__(self, config: Dict[str, Any], github: Optional[Github] = None):
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:
return self.name < other.name

@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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions bin/run_example_ci_configs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import os
import shutil
import sys
Expand Down Expand Up @@ -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('---')
Expand Down
2 changes: 2 additions & 0 deletions bin/sample_build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import argparse
import os
import subprocess
Expand Down
22 changes: 13 additions & 9 deletions bin/update_dependencies.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -25,7 +26,7 @@
'--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
Expand All @@ -47,14 +48,15 @@
], 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),
Expand All @@ -66,12 +68,14 @@

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),
Expand Down
14 changes: 8 additions & 6 deletions bin/update_pythons.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -80,7 +82,7 @@ def __init__(self, arch_str: ArchStr) -> None:
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]
Expand Down Expand Up @@ -170,7 +172,7 @@ def __init__(self) -> None:

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:])
Expand All @@ -179,7 +181,7 @@ def __init__(self) -> None:
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))

Expand Down Expand Up @@ -215,13 +217,13 @@ def __init__(self) -> None:
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:
Expand Down
Loading