From f953acc65ad16b6236de3a8d2728328b1fe5bc11 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 2 Feb 2021 16:30:50 -0500 Subject: [PATCH] fix: updates should include universal2 Pythons (#573) * fix: updates should include universal2 Pythons * refactor: rename to macos_cpython --- .pre-commit-config.yaml | 2 +- bin/update_pythons.py | 33 +++++++++++++++------------------ pyproject.toml | 4 ++++ setup.cfg | 4 ++-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c5e16e891..4e4c9a143 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,6 @@ repos: hooks: - id: black files: ^bin/update_pythons.py$ - args: ["--line-length=120"] - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.800 @@ -29,6 +28,7 @@ repos: - id: mypy exclude: ^(bin/|cibuildwheel/resources/).*py$ additional_dependencies: [packaging] + args: ["--python-version=3.6", "--ignore-missing-imports", "--scripts-are-modules"] - id: mypy name: mypy 3.7+ on bin/ files: ^bin/.*py$ diff --git a/bin/update_pythons.py b/bin/update_pythons.py index 04f075de6..f787a2b9e 100755 --- a/bin/update_pythons.py +++ b/bin/update_pythons.py @@ -164,7 +164,7 @@ def update_version_macos(self, spec: Specifier) -> ConfigMacOS: class CPythonVersions: - def __init__(self, plat_arch: str, file_ident: str) -> None: + def __init__(self) -> None: response = requests.get("https://www.python.org/api/v2/downloads/release/?is_published=true") response.raise_for_status() @@ -180,11 +180,8 @@ def __init__(self, plat_arch: str, file_ident: str) -> None: uri = int(release["resource_uri"].rstrip("/").split("/")[-1]) self.versions_dict[version] = uri - self.file_ident = file_ident - self.plat_arch = plat_arch - - def update_version_macos(self, spec: Specifier) -> Optional[ConfigMacOS]: - + def update_version_macos(self, identifier: str, spec: Specifier) -> Optional[ConfigMacOS]: + file_idents = ("macos11.0.pkg", "macosx10.9.pkg", "macosx10.6.pkg") sorted_versions = sorted(v for v in self.versions_dict if spec.contains(v)) for version in reversed(sorted_versions): @@ -194,13 +191,14 @@ def update_version_macos(self, spec: Specifier) -> Optional[ConfigMacOS]: response.raise_for_status() file_info = response.json() - urls = [rf["url"] for rf in file_info if self.file_ident in rf["url"]] - if urls: - return ConfigMacOS( - identifier=f"cp{version.major}{version.minor}-{self.plat_arch}", - version=f"{version.major}.{version.minor}", - url=urls[0], - ) + for file_ident in file_idents: + urls = [rf["url"] for rf in file_info if file_ident in rf["url"]] + if urls: + return ConfigMacOS( + identifier=identifier, + version=f"{version.major}.{version.minor}", + url=urls[0], + ) return None @@ -215,9 +213,7 @@ def __init__(self) -> None: self.windows_64 = WindowsVersions("64") self.windows_pypy = PyPyVersions("32") - self.macos_6 = CPythonVersions(plat_arch="macosx_x86_64", file_ident="macosx10.6.pkg") - self.macos_9 = CPythonVersions(plat_arch="macosx_x86_64", file_ident="macosx10.9.pkg") - self.macos_u2 = CPythonVersions(plat_arch="macosx_universal2", file_ident="macos11.0.pkg") + self.macos_cpython = CPythonVersions() self.macos_pypy = PyPyVersions("64") def update_config(self, config: Dict[str, str]) -> None: @@ -229,11 +225,12 @@ def update_config(self, config: Dict[str, str]) -> None: config_update: Optional[AnyConfig] # We need to use ** in update due to MyPy (probably a bug) - if "macosx_x86_64" in identifier: + if "macos" in identifier: if identifier.startswith("pp"): config_update = self.macos_pypy.update_version_macos(spec) else: - config_update = self.macos_9.update_version_macos(spec) or self.macos_6.update_version_macos(spec) + config_update = self.macos_cpython.update_version_macos(identifier, spec) + assert config_update is not None, f"MacOS {spec} not found!" config.update(**config_update) elif "win32" in identifier: diff --git a/pyproject.toml b/pyproject.toml index 285367ae3..6e9a2f333 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,3 +5,7 @@ requires = [ ] build-backend = "setuptools.build_meta" + +[tool.black] +line-length = 120 +target-version = ['py36'] diff --git a/setup.cfg b/setup.cfg index a8815a044..9f8602b12 100644 --- a/setup.cfg +++ b/setup.cfg @@ -83,8 +83,8 @@ exclude = junit_family=xunit2 [mypy] -python_version = 3.6 -files = cibuildwheel/*.py,test/**/*.py,unit_test/**/*.py +python_version = 3.7 +files = cibuildwheel/*.py,test/**/*.py,unit_test/**/*.py,bin/*.py warn_unused_configs = True warn_redundant_casts = True