Skip to content

Commit

Permalink
chore: Template upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed May 24, 2024
1 parent d687a80 commit 531fbad
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 1.2.4
_commit: 1.2.7
_src_path: gh:pawamoy/copier-uv
author_email: dev@pawamoy.fr
author_fullname: Timothée Mazzucotelli
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ jobs:
- name: Check if the code is correctly typed
run: make check-types

- name: Check for vulnerabilities in dependencies
run: make check-dependencies

- name: Check for breaking changes in the API
run: make check-api

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ actions = \
changelog \
check \
check-api \
check-dependencies \
check-docs \
check-quality \
check-types \
Expand Down
2 changes: 0 additions & 2 deletions config/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[pytest]
python_files =
test_*.py
*_test.py
tests.py
addopts =
--cov
--cov-append
Expand Down
6 changes: 0 additions & 6 deletions config/vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
"command": "scripts/make",
"args": ["check-docs"]
},
{
"label": "check-dependencies",
"type": "process",
"command": "scripts/make",
"args": ["check-dependencies"]
},
{
"label": "check-api",
"type": "process",
Expand Down
39 changes: 19 additions & 20 deletions devdeps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@
editables>=0.5

# maintenance
build>=1.0
git-changelog>=2.3
twine>=5.0
build>=1.2
git-changelog>=2.5
twine>=5.1; python_version < '3.13'

# ci
duty>=0.10
ruff>=0.0
duty>=1.4
ruff>=0.4
pygments>=2.16
pymdown-extensions>=10.0
pytest>=7.4
pytest-cov>=4.1
pytest>=8.2
pytest-cov>=5.0
pytest-randomly>=3.15
pytest-xdist>=3.3
mypy>=1.5
types-markdown>=3.5
pytest-xdist>=3.6
mypy>=1.10
types-markdown>=3.6
types-pyyaml>=6.0
safety>=2.3

# docs
black>=23.9
markdown-callouts>=0.3
markdown-exec>=1.7
mkdocs>=1.5
black>=24.4
markdown-callouts>=0.4
markdown-exec>=1.8
mkdocs>=1.6
mkdocs-coverage>=1.0
mkdocs-gen-files>=0.5
mkdocs-git-committers-plugin-2>=1.2
mkdocs-git-committers-plugin-2>=2.3
mkdocs-literate-nav>=0.6
mkdocs-material>=9.4
mkdocs-minify-plugin>=0.7
mkdocstrings[python]>=0.23
tomli>=2.0; python_version < '3.11'
mkdocs-material>=9.5
mkdocs-minify-plugin>=0.8
mkdocstrings[python]>=0.25
tomli>=2.0; python_version < '3.11'
88 changes: 28 additions & 60 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Iterator

from duty import duty
from duty.callables import coverage, lazy, mkdocs, mypy, pytest, ruff, safety
from duty import duty, tools

if TYPE_CHECKING:
from duty.context import Context
Expand Down Expand Up @@ -51,10 +50,7 @@ def changelog(ctx: Context, bump: str = "") -> None:
Parameters:
bump: Bump option passed to git-changelog.
"""
from git_changelog.cli import main as git_changelog

args = [f"--bump={bump}"] if bump else []
ctx.run(git_changelog, args=[args], title="Updating changelog", command="git-changelog")
ctx.run(tools.git_changelog(bump=bump or None), title="Updating changelog")


@duty(pre=["check_quality", "check_types", "check_docs", "check_dependencies", "check-api"])
Expand All @@ -66,26 +62,8 @@ def check(ctx: Context) -> None: # noqa: ARG001
def check_quality(ctx: Context) -> None:
"""Check the code quality."""
ctx.run(
ruff.check(*PY_SRC_LIST, config="config/ruff.toml"),
tools.ruff.check(*PY_SRC_LIST, config="config/ruff.toml"),
title=pyprefix("Checking code quality"),
command=f"ruff check --config config/ruff.toml {PY_SRC}",
)


@duty
def check_dependencies(ctx: Context) -> None:
"""Check for vulnerabilities in dependencies."""
# retrieve the list of dependencies
requirements = ctx.run(
["uv", "pip", "freeze"],
silent=True,
allow_overrides=False,
)

ctx.run(
safety.check(requirements),
title="Checking dependencies",
command="uv pip freeze | safety check --stdin",
)


Expand All @@ -96,38 +74,32 @@ def check_docs(ctx: Context) -> None:
Path("htmlcov/index.html").touch(exist_ok=True)
with material_insiders():
ctx.run(
mkdocs.build(strict=True, verbose=True),
tools.mkdocs.build(strict=True, verbose=True),
title=pyprefix("Building documentation"),
command="mkdocs build -vs",
)


@duty
def check_types(ctx: Context) -> None:
"""Check that the code is correctly typed."""
ctx.run(
mypy.run(*PY_SRC_LIST, config_file="config/mypy.ini"),
tools.mypy(*PY_SRC_LIST, config_file="config/mypy.ini"),
title=pyprefix("Type-checking"),
command=f"mypy --config-file config/mypy.ini {PY_SRC}",
)


@duty
def check_api(ctx: Context) -> None:
def check_api(ctx: Context, *cli_args: str) -> None:
"""Check for API breaking changes."""
from griffe.cli import check as g_check

griffe_check = lazy(g_check, name="griffe.check")
ctx.run(
griffe_check("mkdocs_autorefs", search_paths=["src"], color=True),
tools.griffe.check("mkdocs_autorefs", search=["src"], color=True).add_args(*cli_args),
title="Checking for API breaking changes",
command="griffe check -ssrc mkdocs_autorefs",
nofail=True,
)


@duty
def docs(ctx: Context, host: str = "127.0.0.1", port: int = 8000) -> None:
def docs(ctx: Context, *cli_args: str, host: str = "127.0.0.1", port: int = 8000) -> None:
"""Serve the documentation (localhost:8000).
Parameters:
Expand All @@ -136,59 +108,51 @@ def docs(ctx: Context, host: str = "127.0.0.1", port: int = 8000) -> None:
"""
with material_insiders():
ctx.run(
mkdocs.serve(dev_addr=f"{host}:{port}"),
tools.mkdocs.serve(dev_addr=f"{host}:{port}").add_args(*cli_args),
title="Serving documentation",
capture=False,
)


@duty
def docs_deploy(ctx: Context) -> None:
"""Deploy the documentation on GitHub pages."""
"""Deploy the documentation to GitHub pages."""
os.environ["DEPLOY"] = "true"
with material_insiders() as insiders:
if not insiders:
ctx.run(lambda: False, title="Not deploying docs without Material for MkDocs Insiders!")
ctx.run(mkdocs.gh_deploy(), title="Deploying documentation")
ctx.run(tools.mkdocs.gh_deploy(), title="Deploying documentation")


@duty
def format(ctx: Context) -> None:
"""Run formatting tools on the code."""
ctx.run(
ruff.check(*PY_SRC_LIST, config="config/ruff.toml", fix_only=True, exit_zero=True),
tools.ruff.check(*PY_SRC_LIST, config="config/ruff.toml", fix_only=True, exit_zero=True),
title="Auto-fixing code",
)
ctx.run(ruff.format(*PY_SRC_LIST, config="config/ruff.toml"), title="Formatting code")
ctx.run(tools.ruff.format(*PY_SRC_LIST, config="config/ruff.toml"), title="Formatting code")


@duty
def build(ctx: Context) -> None:
"""Build source and wheel distributions."""
from build.__main__ import main as pyproject_build

ctx.run(
pyproject_build,
args=[()],
tools.build(),
title="Building source and wheel distributions",
command="pyproject-build",
pty=PTY,
)


@duty
def publish(ctx: Context) -> None:
"""Publish source and wheel distributions to PyPI."""
from twine.cli import dispatch as twine_upload

if not Path("dist").exists():
ctx.run("false", title="No distribution files found")
dists = [str(dist) for dist in Path("dist").iterdir()]
ctx.run(
twine_upload,
args=[["upload", "-r", "pypi", "--skip-existing", *dists]],
title="Publish source and wheel distributions to PyPI",
command="twine upload -r pypi --skip-existing dist/*",
tools.twine.upload(*dists, skip_existing=True),
title="Publishing source and wheel distributions to PyPI",
pty=PTY,
)

Expand All @@ -209,16 +173,16 @@ def release(ctx: Context, version: str = "") -> None:
ctx.run("git push --tags", title="Pushing tags", pty=False)


@duty(silent=True, aliases=["coverage"])
def cov(ctx: Context) -> None:
@duty(silent=True, aliases=["cov"])
def coverage(ctx: Context) -> None:
"""Report coverage as text and HTML."""
ctx.run(coverage.combine, nofail=True)
ctx.run(coverage.report(rcfile="config/coverage.ini"), capture=False)
ctx.run(coverage.html(rcfile="config/coverage.ini"))
ctx.run(tools.coverage.combine(), nofail=True)
ctx.run(tools.coverage.report(rcfile="config/coverage.ini"), capture=False)
ctx.run(tools.coverage.html(rcfile="config/coverage.ini"))


@duty
def test(ctx: Context, match: str = "") -> None:
def test(ctx: Context, *cli_args: str, match: str = "") -> None:
"""Run the test suite.
Parameters:
Expand All @@ -227,7 +191,11 @@ def test(ctx: Context, match: str = "") -> None:
py_version = f"{sys.version_info.major}{sys.version_info.minor}"
os.environ["COVERAGE_FILE"] = f".coverage.{py_version}"
ctx.run(
pytest.run("-n", "auto", "tests", config_file="config/pytest.ini", select=match, color="yes"),
tools.pytest(
"tests",
config_file="config/pytest.ini",
select=match,
color="yes",
).add_args("-n", "auto", *cli_args),
title=pyprefix("Running tests"),
command=f"pytest -c config/pytest.ini -n auto -k{match!r} --color=yes tests",
)
Loading

0 comments on commit 531fbad

Please sign in to comment.