chore(bin): remove ghapi requirement

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
Henry Schreiner
2022-09-16 11:05:35 -04:00
committed by Henry Schreiner
parent 505207c39b
commit 929ecac7f8
3 changed files with 33 additions and 17 deletions
+33 -15
View File
@@ -1,4 +1,17 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""
Check known projects for usage of requires-python.
Usage:
./bin/inspect_all_known_projects.py --online=$GITHUB_TOKEN
This will cache the results to all_known_setup.yaml; you can reprint
the results without the `--online` setting.
"""
from __future__ import annotations from __future__ import annotations
import ast import ast
@@ -7,7 +20,7 @@ from typing import Iterator
import click import click
import yaml import yaml
from ghapi.core import GhApi, HTTP404NotFoundError from github import Github, GithubException
from rich import print from rich import print
from cibuildwheel.projectfiles import Analyzer from cibuildwheel.projectfiles import Analyzer
@@ -47,33 +60,38 @@ def check_repo(name: str, contents: str) -> str:
class MaybeRemote: class MaybeRemote:
def __init__(self, cached_file: Path | str, *, online: bool) -> None: github: Github | None
self.online = online contents: dict[str, dict[str, str | None]]
if self.online:
self.contents: dict[str, dict[str, str | None]] = { def __init__(self, cached_file: Path | str, *, online: str | None) -> None:
if online is not None:
self.github = Github(online)
self.contents = {
"setup.py": {}, "setup.py": {},
"setup.cfg": {}, "setup.cfg": {},
"pyproject.toml": {}, "pyproject.toml": {},
} }
else: else:
self.github = None
with open(cached_file) as f: with open(cached_file) as f:
self.contents = yaml.safe_load(f) self.contents = yaml.safe_load(f)
def get(self, repo: str, filename: str) -> str | None: def get(self, repo: str, filename: str) -> str | None:
if self.online: if self.github:
try: try:
self.contents[filename][repo] = ( gh_file = self.github.get_repo(repo).get_contents(filename)
GhApi(*repo.split("/")).get_content(filename).decode() except GithubException:
)
except HTTP404NotFoundError:
self.contents[filename][repo] = None self.contents[filename][repo] = None
else:
assert not isinstance(gh_file, list)
self.contents[filename][repo] = gh_file.decoded_content.decode(encoding="utf-8")
return self.contents[filename][repo] return self.contents[filename][repo]
elif repo in self.contents[filename]: elif repo in self.contents[filename]:
return self.contents[filename][repo] return self.contents[filename][repo]
else: else:
raise RuntimeError( msg = f"Trying to access {repo}:{filename} and not in cache, rebuild cache"
f"Trying to access {repo}:{filename} and not in cache, rebuild cache" raise RuntimeError(msg)
)
def save(self, filename: Path | str) -> None: def save(self, filename: Path | str) -> None:
with open(filename, "w") as f: with open(filename, "w") as f:
@@ -87,8 +105,8 @@ class MaybeRemote:
@click.command() @click.command()
@click.option("--online", is_flag=True, help="Remember to set GITHUB_TOKEN") @click.option("--online", help="Set to $GITHUB_TOKEN")
def main(online: bool) -> None: def main(online: str | None) -> None:
with open(DIR / "../docs/data/projects.yml") as f: with open(DIR / "../docs/data/projects.yml") as f:
known = yaml.safe_load(f) known = yaml.safe_load(f)
-1
View File
@@ -67,7 +67,6 @@ module = [
"pytest", # ignored in pre-commit to speed up check "pytest", # ignored in pre-commit to speed up check
"bashlex", "bashlex",
"importlib_resources", "importlib_resources",
"ghapi.*",
] ]
ignore_missing_imports = true ignore_missing_imports = true
-1
View File
@@ -20,7 +20,6 @@ extras = {
], ],
"bin": [ "bin": [
"click", "click",
"ghapi",
"pip-tools", "pip-tools",
"pygithub", "pygithub",
"pyyaml", "pyyaml",