8000 Add type annotations for spin utils (#188) · scientific-python/spin@d3dc916 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3dc916

Browse files
authored
Add type annotations for spin utils (#188)
With this in place, we can progressively add more type annotations. Closes #177
1 parent 423dcd3 commit d3dc916

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ repos:
4040
hooks:
4141
- id: ruff
4242
args: [--fix, --exit-non-zero-on-fix]
43+
44+
- repo: https://github.com/pre-commit/mirrors-mypy
45+
rev: e5ea6670624c24f8321f6328ef3176dbba76db46 # frozen: v1.10.0
46+
hooks:
47+
- id: mypy

example_pkg/doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# -- General configuration ---------------------------------------------------
1414
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
1515

16-
extensions = []
16+
extensions: list[str] = []
1717

1818
templates_path = ["_templates"]
1919
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

spin/cmds/meson.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ def _check_coverage_tool_installation(coverage_type: GcovReportFormat):
215215

216216
# Verify the tools are installed prior to the build
217217
p = _run(["ninja", "-C", build_dir, "-t", "targets", "all"], output=False)
218-
if f"coverage-{coverage_type.value}" not in p.stdout.decode("ascii"):
218+
if f"coverage-{coverage_type}" not in p.stdout.decode("ascii"):
219219
raise click.ClickException(
220-
f"coverage-{coverage_type.value} is not supported... "
220+
f"coverage-{coverage_type} is not supported... "
221221
f"Ensure the following are installed: {', '.join(requirements[coverage_type])} "
222222
"and rerun `spin test --gcov`"
223223
)
@@ -363,7 +363,7 @@ def _get_configured_command(command_name):
363363
)
364364
@click.option(
365365
"--gcov-format",
366-
type=click.Choice(GcovReportFormat),
366+
type=click.Choice([e.name for e in GcovReportFormat]),
367367
default="html",
368368
help=f"Format of the gcov report. Can be one of {', '.join(e.value for e in GcovReportFormat)}.",
369369
)
@@ -512,7 +512,7 @@ def test(
512512

513513
# Generate report
514514
click.secho(
515-
f"Generating {gcov_format.value} coverage report...",
515+
f"Generating {gcov_format} coverage report...",
516516
bold=True,
517517
fg="bright_yellow",
518518
)
@@ -521,7 +521,7 @@ def test(
521521
"ninja",
522522
"-C",
523523
build_dir,
524-
f"coverage-{gcov_format.value.lower()}",
524+
f"coverage-{gcov_format.lower()}",
525525
],
526526
output=False,
527527
)

spin/cmds/util.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
import shlex
33
import subprocess
44
import sys
5+
from typing import Optional
56

67
import click
78

89

910
def run(
10-
cmd, cwd=None, replace=False, sys_exit=True, output=True, echo=True, *args, **kwargs
11-
):
11+
cmd: list[str],
12+
cwd: Optional[str] = None, # in 3.10 and up: str | None
13+
replace: bool = False,
14+
sys_exit: bool = True,
15+
output: bool = True,
16+
echo: bool = True,
17+
*args,
18+
**kwargs,
19+
) -> subprocess.CompletedProcess:
1220
"""Run a shell command.
1321
1422
Parameters

0 commit comments

Comments
 (0)
0