Skip to content

Commit

Permalink
fix: updates should include universal2 Pythons (#573)
Browse files Browse the repository at this point in the history
* fix: updates should include universal2 Pythons

* refactor: rename to macos_cpython
  • Loading branch information
henryiii authored Feb 2, 2021
1 parent cdfab24 commit f953acc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ repos:
hooks:
- id: black
files: ^bin/update_pythons.py$
args: ["--line-length=120"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.800
hooks:
- 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$
Expand Down
33 changes: 15 additions & 18 deletions bin/update_pythons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ requires = [
]

build-backend = "setuptools.build_meta"

[tool.black]
line-length = 120
target-version = ['py36']
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f953acc

Please sign in to comment.