Skip to content

Commit

Permalink
chore: cleanup style for other bin items
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Apr 22, 2021
1 parent 9a6866b commit f932a9c
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 35 deletions.
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
2 changes: 2 additions & 0 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 Down
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
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ exclude =

[tool:pytest]
junit_family=xunit2
testpaths =
test
unit_test

[mypy]
python_version = 3.7
Expand Down

0 comments on commit f932a9c

Please sign in to comment.