Skip to content

Commit c8b2292

Browse files
committed
refactor: introduce importable token rotator package
1 parent 52d2080 commit c8b2292

6 files changed

Lines changed: 580 additions & 495 deletions

File tree

.github/workflows/quality.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,36 @@ jobs:
121121
with:
122122
python-version: ${{ matrix.python-version }}
123123

124-
- name: Confirm production script uses only standard-library imports
124+
- name: Confirm production code uses only standard-library or local imports
125125
run: |
126126
python - <<'PY'
127127
import ast
128128
import pathlib
129129
import sys
130130
131-
source = pathlib.Path("token-rotate/gitlab_project_token_rotator.py")
132-
tree = ast.parse(source.read_text(encoding="utf-8"), filename=str(source))
133-
allowed_local = {"__future__"}
131+
sources = [pathlib.Path("token-rotate/gitlab_project_token_rotator.py")]
132+
sources.extend(pathlib.Path("token-rotate/token_rotate").glob("*.py"))
133+
allowed_local = {"__future__", "token_rotate"}
134134
stdlib = set(getattr(sys, "stdlib_module_names", ())) | allowed_local
135-
imported = set()
136-
for node in ast.walk(tree):
137-
if isinstance(node, ast.Import):
138-
imported.update(alias.name.split(".")[0] for alias in node.names)
139-
elif isinstance(node, ast.ImportFrom) and node.module:
140-
imported.add(node.module.split(".")[0])
141-
third_party = sorted(name for name in imported if name not in stdlib)
142-
if third_party:
143-
print("Non-standard-library imports found in production script:", third_party)
135+
failures = []
136+
for source in sources:
137+
tree = ast.parse(source.read_text(encoding="utf-8"), filename=str(source))
138+
imported = set()
139+
for node in ast.walk(tree):
140+
if isinstance(node, ast.Import):
141+
imported.update(alias.name.split(".")[0] for alias in node.names)
142+
elif isinstance(node, ast.ImportFrom) and node.module:
143+
if node.level:
144+
continue
145+
imported.add(node.module.split(".")[0])
146+
third_party = sorted(name for name in imported if name not in stdlib)
147+
if third_party:
148+
failures.append(f"{source}: {third_party}")
149+
if failures:
150+
print("Non-standard-library imports found in production code:")
151+
print("\n".join(failures))
144152
sys.exit(1)
145-
print("Production script imports are standard-library only.")
153+
print("Production code imports are standard-library or local package only.")
146154
PY
147155
148156
- name: Compile every tracked Python file

0 commit comments

Comments
 (0)