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

feat: update python versions as part of update_dependencies #496

Merged
merged 9 commits into from
Jan 15, 2021
20 changes: 11 additions & 9 deletions bin/update_pythons.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class ConfigMacOS(TypedDict):
AnyConfig = Union[ConfigWinCP, ConfigWinPP, ConfigMacOS]


# The following set of "Versions" classes allow the initial call to the APIs to
# be cached and reused in the `update_version_*` methods.


class WindowsVersions:
def __init__(self, arch_str: ArchStr) -> None:

Expand Down Expand Up @@ -159,10 +163,6 @@ def update_version_macos(self, spec: Specifier) -> ConfigMacOS:
)


def _get_id(resource_uri: str) -> int:
return int(resource_uri.rstrip("/").split("/")[-1])


class CPythonVersions:
def __init__(self, plat_arch: str, file_ident: str) -> None:

Expand Down Expand Up @@ -205,6 +205,10 @@ def update_version_macos(self, spec: Specifier) -> Optional[ConfigMacOS]:
return None


# This is a universal interface to all the above Versions classes. Given an
# identifier, it updates a config dict.


class AllVersions:
def __init__(self) -> None:
self.windows_32 = WindowsVersions("32")
Expand All @@ -213,10 +217,7 @@ def __init__(self) -> None:

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_u2 = CPythonVersions(plat_arch="macosx_universal2", file_ident="macos11.0.pkg")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the "magic" comma in Black, which lets you force multiline. I didn't want to do that here, so I removed it.

PS: I originally tried to write this without Black, but the first time a ran I had 20 or so Flake8 errors; I had no interest in waisting time trying to fix them by hand, so I ran black bin/update_python.py, and they all went away. So this is our one Black'ed file. :)

self.macos_pypy = PyPyVersions("64")

def update_config(self, config: Dict[str, str]) -> None:
Expand All @@ -227,6 +228,7 @@ def update_config(self, config: Dict[str, str]) -> None:
orig_config = copy.copy(config)
config_update: Optional[AnyConfig]

# We need to use ** in update due to MyPy (probably a bug)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyPy's handling of TypedDict's is pretty buggy. I had to do this, and I also don't know how to type narrow on a Union of TypedDicts, as assert isinstance is not allowed, so this takes a normal Dict for now. 🤷

if "macosx_x86_64" in identifier:
if identifier.startswith("pp"):
config_update = self.macos_pypy.update_version_macos(spec)
Expand Down Expand Up @@ -281,7 +283,7 @@ def update_pythons(force: bool, level: str) -> None:

if original_toml == result_toml:
rich.print("[green]Check complete, Python configurations unchanged.")
exit()
return
joerick marked this conversation as resolved.
Show resolved Hide resolved

rich.print("Python configurations updated.")
rich.print("Changes:")
Expand Down