Skip to content

Commit

Permalink
Add type annotations for spin utils (#188)
Browse files Browse the repository at this point in the history
With this in place, we can progressively add more type annotations.

Closes #177
  • Loading branch information
stefanv authored May 23, 2024
1 parent 423dcd3 commit d3dc916
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ repos:
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: e5ea6670624c24f8321f6328ef3176dbba76db46 # frozen: v1.10.0
hooks:
- id: mypy
2 changes: 1 addition & 1 deletion example_pkg/doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []
extensions: list[str] = []

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
Expand Down
10 changes: 5 additions & 5 deletions spin/cmds/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ def _check_coverage_tool_installation(coverage_type: GcovReportFormat):

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

# Generate report
click.secho(
f"Generating {gcov_format.value} coverage report...",
f"Generating {gcov_format} coverage report...",
bold=True,
fg="bright_yellow",
)
Expand All @@ -521,7 +521,7 @@ def test(
"ninja",
"-C",
build_dir,
f"coverage-{gcov_format.value.lower()}",
f"coverage-{gcov_format.lower()}",
],
output=False,
)
Expand Down
12 changes: 10 additions & 2 deletions spin/cmds/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
import shlex
import subprocess
import sys
from typing import Optional

import click


def run(
cmd, cwd=None, replace=False, sys_exit=True, output=True, echo=True, *args, **kwargs
):
cmd: list[str],
cwd: Optional[str] = None, # in 3.10 and up: str | None
replace: bool = False,
sys_exit: bool = True,
output: bool = True,
echo: bool = True,
*args,
**kwargs,
) -> subprocess.CompletedProcess:
"""Run a shell command.
Parameters
Expand Down

0 comments on commit d3dc916

Please sign in to comment.