Skip to content

Commit 65a22bf

Browse files
committed
chore: Use new callables
1 parent e3357b9 commit 65a22bf

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

duties.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from pathlib import Path
1010
from typing import TYPE_CHECKING, Iterator
1111

12-
from duty import duty
13-
from duty.callables import coverage, lazy, mkdocs, mypy, pytest, ruff, safety
12+
from duty import callables, duty
1413

1514
if TYPE_CHECKING:
1615
from duty.context import Context
@@ -51,10 +50,7 @@ def changelog(ctx: Context, bump: str = "") -> None:
5150
Parameters:
5251
bump: Bump option passed to git-changelog.
5352
"""
54-
from git_changelog.cli import main as git_changelog
55-
56-
args = [f"--bump={bump}"] if bump else []
57-
ctx.run(git_changelog, args=[args], title="Updating changelog", command="git-changelog")
53+
ctx.run(callables.git_changelog.run(bump=bump or None), title="Updating changelog", command="git-changelog")
5854

5955

6056
@duty(pre=["check_quality", "check_types", "check_docs", "check_dependencies", "check-api"])
@@ -66,7 +62,7 @@ def check(ctx: Context) -> None: # noqa: ARG001
6662
def check_quality(ctx: Context) -> None:
6763
"""Check the code quality."""
6864
ctx.run(
69-
ruff.check(*PY_SRC_LIST, config="config/ruff.toml"),
65+
callables.ruff.check(*PY_SRC_LIST, config="config/ruff.toml"),
7066
title=pyprefix("Checking code quality"),
7167
command=f"ruff check --config config/ruff.toml {PY_SRC}",
7268
)
@@ -83,7 +79,7 @@ def check_dependencies(ctx: Context) -> None:
8379
)
8480

8581
ctx.run(
86-
safety.check(requirements),
82+
callables.safety.check(requirements),
8783
title="Checking dependencies",
8884
command="uv pip freeze | safety check --stdin",
8985
)
@@ -96,7 +92,7 @@ def check_docs(ctx: Context) -> None:
9692
Path("htmlcov/index.html").touch(exist_ok=True)
9793
with material_insiders():
9894
ctx.run(
99-
mkdocs.build(strict=True, verbose=True),
95+
callables.mkdocs.build(strict=True, verbose=True),
10096
title=pyprefix("Building documentation"),
10197
command="mkdocs build -vs",
10298
)
@@ -106,7 +102,7 @@ def check_docs(ctx: Context) -> None:
106102
def check_types(ctx: Context) -> None:
107103
"""Check that the code is correctly typed."""
108104
ctx.run(
109-
mypy.run(*PY_SRC_LIST, config_file="config/mypy.ini"),
105+
callables.mypy.run(*PY_SRC_LIST, config_file="config/mypy.ini"),
110106
title=pyprefix("Type-checking"),
111107
command=f"mypy --config-file config/mypy.ini {PY_SRC}",
112108
)
@@ -115,11 +111,8 @@ def check_types(ctx: Context) -> None:
115111
@duty
116112
def check_api(ctx: Context) -> None:
117113
"""Check for API breaking changes."""
118-
from griffe.cli import check as g_check
119-
120-
griffe_check = lazy(g_check, name="griffe.check")
121114
ctx.run(
122-
griffe_check("duty", search_paths=["src"], color=True),
115+
callables.griffe.check("duty", search=["src"], color=True),
123116
title="Checking for API breaking changes",
124117
command="griffe check -ssrc duty",
125118
nofail=True,
@@ -136,7 +129,7 @@ def docs(ctx: Context, host: str = "127.0.0.1", port: int = 8000) -> None:
136129
"""
137130
with material_insiders():
138131
ctx.run(
139-
mkdocs.serve(dev_addr=f"{host}:{port}"),
132+
callables.mkdocs.serve(dev_addr=f"{host}:{port}"),
140133
title="Serving documentation",
141134
capture=False,
142135
)
@@ -149,27 +142,24 @@ def docs_deploy(ctx: Context) -> None:
149142
with material_insiders() as insiders:
150143
if not insiders:
151144
ctx.run(lambda: False, title="Not deploying docs without Material for MkDocs Insiders!")
152-
ctx.run(mkdocs.gh_deploy(), title="Deploying documentation")
145+
ctx.run(callables.mkdocs.gh_deploy(), title="Deploying documentation")
153146

154147

155148
@duty
156149
def format(ctx: Context) -> None:
157150
"""Run formatting tools on the code."""
158151
ctx.run(
159-
ruff.check(*PY_SRC_LIST, config="config/ruff.toml", fix_only=True, exit_zero=True),
152+
callables.ruff.check(*PY_SRC_LIST, config="config/ruff.toml", fix_only=True, exit_zero=True),
160153
title="Auto-fixing code",
161154
)
162-
ctx.run(ruff.format(*PY_SRC_LIST, config="config/ruff.toml"), title="Formatting code")
155+
ctx.run(callables.ruff.format(*PY_SRC_LIST, config="config/ruff.toml"), title="Formatting code")
163156

164157

165158
@duty
166159
def build(ctx: Context) -> None:
167160
"""Build source and wheel distributions."""
168-
from build.__main__ import main as pyproject_build
169-
170161
ctx.run(
171-
pyproject_build,
172-
args=[()],
162+
callables.build.run(),
173163
title="Building source and wheel distributions",
174164
command="pyproject-build",
175165
pty=PTY,
@@ -179,14 +169,11 @@ def build(ctx: Context) -> None:
179169
@duty
180170
def publish(ctx: Context) -> None:
181171
"""Publish source and wheel distributions to PyPI."""
182-
from twine.cli import dispatch as twine_upload
183-
184172
if not Path("dist").exists():
185173
ctx.run("false", title="No distribution files found")
186174
dists = [str(dist) for dist in Path("dist").iterdir()]
187175
ctx.run(
188-
twine_upload,
189-
args=[["upload", "-r", "pypi", "--skip-existing", *dists]],
176+
callables.twine.upload(*dists, skip_existing=True),
190177
title="Publish source and wheel distributions to PyPI",
191178
command="twine upload -r pypi --skip-existing dist/*",
192179
pty=PTY,
@@ -212,9 +199,9 @@ def release(ctx: Context, version: str = "") -> None:
212199
@duty(silent=True, aliases=["coverage"])
213200
def cov(ctx: Context) -> None:
214201
"""Report coverage as text and HTML."""
215-
ctx.run(coverage.combine, nofail=True)
216-
ctx.run(coverage.report(rcfile="config/coverage.ini"), capture=False)
217-
ctx.run(coverage.html(rcfile="config/coverage.ini"))
202+
ctx.run(callables.coverage.combine, nofail=True)
203+
ctx.run(callables.coverage.report(rcfile="config/coverage.ini"), capture=False)
204+
ctx.run(callables.coverage.html(rcfile="config/coverage.ini"))
218205

219206

220207
@duty
@@ -227,7 +214,7 @@ def test(ctx: Context, match: str = "") -> None:
227214
py_version = f"{sys.version_info.major}{sys.version_info.minor}"
228215
os.environ["COVERAGE_FILE"] = f".coverage.{py_version}"
229216
ctx.run(
230-
pytest.run("-n", "auto", "tests", config_file="config/pytest.ini", select=match, color="yes"),
217+
callables.pytest.run("-n", "auto", "tests", config_file="config/pytest.ini", select=match, color="yes"),
231218
title=pyprefix("Running tests"),
232219
command=f"pytest -c config/pytest.ini -n auto -k{match!r} --color=yes tests",
233220
)

0 commit comments

Comments
 (0)