Skip to content

Commit

Permalink
Add html option in coverage report + small fix in invoke tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Oct 2, 2023
1 parent 6f1a53a commit a0bdcdf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- New html option in coverage report

### Fixed
- Small fixes in invoke tasks

### Changed
- Dockerfile: split installation of Python dependencies for more efficiency

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ run = "inv test --args '{args}'"
run-cov = "inv test-cov --args '{args}'"
report-cov = "inv report-cov"
coverage = "inv coverage --args '{args}'"
html = "inv coverage --html --args '{args}'"

[tool.hatch.envs.lint]
template = "lint"
Expand Down
79 changes: 43 additions & 36 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,95 +8,102 @@


@task(optional=["args"], help={"args": "pytest additional arguments"})
def test(ctx: Context, args: str | None = ""):
def test(ctx: Context, args: str = ""):
"""run tests (without coverage)"""
ctx.run(f"pytest {args}", pty=use_pty)


@task(optional=["args"], help={"args": "pytest additional arguments"})
def test_cov(ctx: Context, args: str | None = ""):
def test_cov(ctx: Context, args: str = ""):
"""run test vith coverage"""
ctx.run(f"coverage run -m pytest {args}", pty=use_pty)


@task()
def report_cov(ctx: Context):
@task(optional=["html"], help={"html": "flag to export html report"})
def report_cov(ctx: Context, *, html: bool = False):
"""report coverage"""
ctx.run("coverage combine", warn=True, pty=use_pty)
ctx.run("coverage report --show-missing", pty=use_pty)
if html:
ctx.run("coverage html", pty=use_pty)


@task(optional=["args"], help={"args": "pytest additional arguments"})
def coverage(ctx: Context, args: str | None = ""):
@task(
optional=["args", "html"],
help={
"args": "pytest additional arguments",
"html": "flag to export html report",
},
)
def coverage(ctx: Context, args: str = "", *, html: bool = False):
"""run tests and report coverage"""
test_cov(ctx, args)
report_cov(ctx)
test_cov(ctx, args=args)
report_cov(ctx, html=html)


@task(
optional=["args"], help={"args": "linting tools (black, ruff) additional arguments"}
)
def lint_black(ctx: Context, args: str | None = ""):
args = args or "."
@task(optional=["args"], help={"args": "black additional arguments"})
def lint_black(ctx: Context, args: str = "."):
args = args or "." # needed for hatch script
ctx.run("black --version", pty=use_pty)
ctx.run(f"black --check --diff {args}", pty=use_pty)


@task(
optional=["args"], help={"args": "linting tools (black, ruff) additional arguments"}
)
def lint_ruff(ctx: Context, args: str | None = ""):
args = args or "."
@task(optional=["args"], help={"args": "ruff additional arguments"})
def lint_ruff(ctx: Context, args: str = "."):
args = args or "." # needed for hatch script
ctx.run("ruff --version", pty=use_pty)
ctx.run(f"ruff check {args}", pty=use_pty)


@task(
optional=["args"], help={"args": "linting tools (black, ruff) additional arguments"}
optional=["args"],
help={
"args": "linting tools (black, ruff) additional arguments, typically a path",
},
)
def lintall(ctx: Context, args: str | None = ""):
"""check linting"""
args = args or "."
def lintall(ctx: Context, args: str = "."):
"""Check linting"""
args = args or "." # needed for hatch script
lint_black(ctx, args)
lint_ruff(ctx, args)


@task(optional=["args"], help={"args": "check tools (pyright) additional arguments"})
def check_pyright(ctx: Context, args: str | None = ""):
def check_pyright(ctx: Context, args: str = ""):
"""check static types with pyright"""
args = args or ""
ctx.run("pyright --version")
ctx.run(f"pyright {args}", pty=use_pty)


@task(optional=["args"], help={"args": "check tools (pyright) additional arguments"})
def checkall(ctx: Context, args: str | None = ""):
def checkall(ctx: Context, args: str = ""):
"""check static types"""
args = args or ""
check_pyright(ctx, args)


@task(optional=["args"], help={"args": "black additional arguments"})
def fix_black(ctx: Context, args: str | None = ""):
def fix_black(ctx: Context, args: str = "."):
"""fix black formatting"""
args = args or "."
ctx.run(f"black {args}", pty=use_pty) # type: ignore
args = args or "." # needed for hatch script
ctx.run(f"black {args}", pty=use_pty)


@task(optional=["args"], help={"args": "ruff additional arguments"})
def fix_ruff(ctx: Context, args: str | None = ""):
def fix_ruff(ctx: Context, args: str = "."):
"""fix all ruff rules"""
args = args or "."
ctx.run(f"ruff --fix {args}", pty=use_pty) # type: ignore
args = args or "." # needed for hatch script
ctx.run(f"ruff --fix {args}", pty=use_pty)


@task(
optional=["args"],
help={"args": "linting (fix mode) tools (black, ruff) additional arguments"},
help={
"args": "linting tools (black, ruff) additional arguments, typically a path",
},
)
def fixall(ctx: Context, args: str | None = ""):
"""fix everything automatically"""
args = args or "."
def fixall(ctx: Context, args: str = "."):
"""Fix everything automatically"""
args = args or "." # needed for hatch script
fix_black(ctx, args)
fix_ruff(ctx, args)
lintall(ctx, args)

0 comments on commit a0bdcdf

Please sign in to comment.