1
1
#!/usr/bin/env python3
2
+
3
+ """
4
+ Check known projects for usage of requires-python.
5
+
6
+ Usage:
7
+
8
+ ./bin/inspect_all_known_projects.py --online=$GITHUB_TOKEN
9
+
10
+ This will cache the results to all_known_setup.yaml; you can reprint
11
+ the results without the `--online` setting.
12
+ """
13
+
14
+
2
15
from __future__ import annotations
3
16
4
17
import ast
7
20
8
21
import click
9
22
import yaml
10
- from ghapi . core import GhApi , HTTP404NotFoundError
23
+ from github import Github , GithubException
11
24
from rich import print
12
25
13
26
from cibuildwheel .projectfiles import Analyzer
@@ -47,33 +60,38 @@ def check_repo(name: str, contents: str) -> str:
47
60
48
61
49
62
class MaybeRemote :
50
- def __init__ (self , cached_file : Path | str , * , online : bool ) -> None :
51
- self .online = online
52
- if self .online :
53
- self .contents : dict [str , dict [str , str | None ]] = {
63
+ github : Github | None
64
+ contents : dict [str , dict [str , str | None ]]
65
+
66
+ def __init__ (self , cached_file : Path | str , * , online : str | None ) -> None :
67
+ if online is not None :
68
+ self .github = Github (online )
69
+ self .contents = {
54
70
"setup.py" : {},
55
71
"setup.cfg" : {},
56
72
"pyproject.toml" : {},
57
73
}
58
74
else :
75
+ self .github = None
59
76
with open (cached_file ) as f :
60
77
self .contents = yaml .safe_load (f )
61
78
62
79
def get (self , repo : str , filename : str ) -> str | None :
63
- if self .online :
80
+ if self .github :
64
81
try :
65
- self .contents [filename ][repo ] = (
66
- GhApi (* repo .split ("/" )).get_content (filename ).decode ()
67
- )
68
- except HTTP404NotFoundError :
82
+ gh_file = self .github .get_repo (repo ).get_contents (filename )
83
+ except GithubException :
69
84
self .contents [filename ][repo ] = None
85
+ else :
86
+ assert not isinstance (gh_file , list )
87
+ self .contents [filename ][repo ] = gh_file .decoded_content .decode (encoding = "utf-8" )
88
+
70
89
return self .contents [filename ][repo ]
71
90
elif repo in self .contents [filename ]:
72
91
return self .contents [filename ][repo ]
73
92
else :
74
- raise RuntimeError (
75
- f"Trying to access { repo } :{ filename } and not in cache, rebuild cache"
76
- )
93
+ msg = f"Trying to access { repo } :{ filename } and not in cache, rebuild cache"
94
+ raise RuntimeError (msg )
77
95
78
96
def save (self , filename : Path | str ) -> None :
79
97
with open (filename , "w" ) as f :
@@ -87,8 +105,8 @@ def on_each(self, repos: list[str]) -> Iterator[tuple[str, str, str | None]]:
87
105
88
106
89
107
@click .command ()
90
- @click .option ("--online" , is_flag = True , help = "Remember to set GITHUB_TOKEN" )
91
- def main (online : bool ) -> None :
108
+ @click .option ("--online" , help = "Set to $ GITHUB_TOKEN" )
109
+ def main (online : str | None ) -> None :
92
110
with open (DIR / "../docs/data/projects.yml" ) as f :
93
111
known = yaml .safe_load (f )
94
112
0 commit comments