Skip to content

Commit a01feb4

Browse files
committed
Add scan-headers devtool
1 parent c14a487 commit a01feb4

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

devtools/__main__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ def develop(ctx: Context, package: str):
6161
project.develop()
6262

6363

64+
@main.command()
65+
@click.pass_obj
66+
def scan_headers(ctx: Context):
67+
"""Run scan-headers on all projects"""
68+
ok = True
69+
for project in ctx.subprojects.values():
70+
if project.is_semiwrap_project():
71+
with ctx.handle_exception(f"scan-headers {project.name}"):
72+
if not project.scan_headers():
73+
print(
74+
"- ERROR:",
75+
project.pyproject_path,
76+
"does not wrap/ignore every header!",
77+
)
78+
ok = False
79+
80+
if not ok:
81+
sys.exit(1)
82+
83+
6484
@main.command
6585
@click.argument("package", required=False)
6686
@click.pass_obj

devtools/subproject.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ def develop(self):
4848
def uninstall(self):
4949
run_pip("uninstall", "-y", self.pyproject_name)
5050

51+
def scan_headers(self):
52+
"""Returns True if no headers found or False if missing headers were found"""
53+
result = run_cmd(
54+
sys.executable,
55+
"-m",
56+
"semiwrap",
57+
"scan-headers",
58+
"--check",
59+
cwd=self.path,
60+
check=False,
61+
)
62+
return result.returncode == 0
63+
5164
def update_init(self):
5265
run_cmd(
5366
sys.executable,

devtools/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def parse_input(value: typing.Any, spec: typing.Type[T], fname) -> T:
4444
raise _convert_validation_error(fname, ve) from None
4545

4646

47-
def run_cmd(*args: str, cwd=None):
47+
def run_cmd(*args: str, cwd=None, check=True):
4848
print("+", shlex.join(args))
49-
subprocess.check_call(args, cwd=cwd)
49+
return subprocess.run(args, cwd=cwd, check=check)
5050

5151

5252
def run_pip(*args: str, cwd=None):

0 commit comments

Comments
 (0)