9
9
from pathlib import Path
10
10
from typing import TYPE_CHECKING , Iterator
11
11
12
- from duty import duty
13
- from duty .callables import coverage , lazy , mkdocs , mypy , pytest , ruff , safety
12
+ from duty import callables , duty
14
13
15
14
if TYPE_CHECKING :
16
15
from duty .context import Context
@@ -51,10 +50,7 @@ def changelog(ctx: Context, bump: str = "") -> None:
51
50
Parameters:
52
51
bump: Bump option passed to git-changelog.
53
52
"""
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" )
58
54
59
55
60
56
@duty (pre = ["check_quality" , "check_types" , "check_docs" , "check_dependencies" , "check-api" ])
@@ -66,7 +62,7 @@ def check(ctx: Context) -> None: # noqa: ARG001
66
62
def check_quality (ctx : Context ) -> None :
67
63
"""Check the code quality."""
68
64
ctx .run (
69
- ruff .check (* PY_SRC_LIST , config = "config/ruff.toml" ),
65
+ callables . ruff .check (* PY_SRC_LIST , config = "config/ruff.toml" ),
70
66
title = pyprefix ("Checking code quality" ),
71
67
command = f"ruff check --config config/ruff.toml { PY_SRC } " ,
72
68
)
@@ -83,7 +79,7 @@ def check_dependencies(ctx: Context) -> None:
83
79
)
84
80
85
81
ctx .run (
86
- safety .check (requirements ),
82
+ callables . safety .check (requirements ),
87
83
title = "Checking dependencies" ,
88
84
command = "uv pip freeze | safety check --stdin" ,
89
85
)
@@ -96,7 +92,7 @@ def check_docs(ctx: Context) -> None:
96
92
Path ("htmlcov/index.html" ).touch (exist_ok = True )
97
93
with material_insiders ():
98
94
ctx .run (
99
- mkdocs .build (strict = True , verbose = True ),
95
+ callables . mkdocs .build (strict = True , verbose = True ),
100
96
title = pyprefix ("Building documentation" ),
101
97
command = "mkdocs build -vs" ,
102
98
)
@@ -106,7 +102,7 @@ def check_docs(ctx: Context) -> None:
106
102
def check_types (ctx : Context ) -> None :
107
103
"""Check that the code is correctly typed."""
108
104
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" ),
110
106
title = pyprefix ("Type-checking" ),
111
107
command = f"mypy --config-file config/mypy.ini { PY_SRC } " ,
112
108
)
@@ -115,11 +111,8 @@ def check_types(ctx: Context) -> None:
115
111
@duty
116
112
def check_api (ctx : Context ) -> None :
117
113
"""Check for API breaking changes."""
118
- from griffe .cli import check as g_check
119
-
120
- griffe_check = lazy (g_check , name = "griffe.check" )
121
114
ctx .run (
122
- griffe_check ("duty" , search_paths = ["src" ], color = True ),
115
+ callables . griffe . check ("duty" , search = ["src" ], color = True ),
123
116
title = "Checking for API breaking changes" ,
124
117
command = "griffe check -ssrc duty" ,
125
118
nofail = True ,
@@ -136,7 +129,7 @@ def docs(ctx: Context, host: str = "127.0.0.1", port: int = 8000) -> None:
136
129
"""
137
130
with material_insiders ():
138
131
ctx .run (
139
- mkdocs .serve (dev_addr = f"{ host } :{ port } " ),
132
+ callables . mkdocs .serve (dev_addr = f"{ host } :{ port } " ),
140
133
title = "Serving documentation" ,
141
134
capture = False ,
142
135
)
@@ -149,27 +142,24 @@ def docs_deploy(ctx: Context) -> None:
149
142
with material_insiders () as insiders :
150
143
if not insiders :
151
144
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" )
153
146
154
147
155
148
@duty
156
149
def format (ctx : Context ) -> None :
157
150
"""Run formatting tools on the code."""
158
151
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 ),
160
153
title = "Auto-fixing code" ,
161
154
)
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" )
163
156
164
157
165
158
@duty
166
159
def build (ctx : Context ) -> None :
167
160
"""Build source and wheel distributions."""
168
- from build .__main__ import main as pyproject_build
169
-
170
161
ctx .run (
171
- pyproject_build ,
172
- args = [()],
162
+ callables .build .run (),
173
163
title = "Building source and wheel distributions" ,
174
164
command = "pyproject-build" ,
175
165
pty = PTY ,
@@ -179,14 +169,11 @@ def build(ctx: Context) -> None:
179
169
@duty
180
170
def publish (ctx : Context ) -> None :
181
171
"""Publish source and wheel distributions to PyPI."""
182
- from twine .cli import dispatch as twine_upload
183
-
184
172
if not Path ("dist" ).exists ():
185
173
ctx .run ("false" , title = "No distribution files found" )
186
174
dists = [str (dist ) for dist in Path ("dist" ).iterdir ()]
187
175
ctx .run (
188
- twine_upload ,
189
- args = [["upload" , "-r" , "pypi" , "--skip-existing" , * dists ]],
176
+ callables .twine .upload (* dists , skip_existing = True ),
190
177
title = "Publish source and wheel distributions to PyPI" ,
191
178
command = "twine upload -r pypi --skip-existing dist/*" ,
192
179
pty = PTY ,
@@ -212,9 +199,9 @@ def release(ctx: Context, version: str = "") -> None:
212
199
@duty (silent = True , aliases = ["coverage" ])
213
200
def cov (ctx : Context ) -> None :
214
201
"""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" ))
218
205
219
206
220
207
@duty
@@ -227,7 +214,7 @@ def test(ctx: Context, match: str = "") -> None:
227
214
py_version = f"{ sys .version_info .major } { sys .version_info .minor } "
228
215
os .environ ["COVERAGE_FILE" ] = f".coverage.{ py_version } "
229
216
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" ),
231
218
title = pyprefix ("Running tests" ),
232
219
command = f"pytest -c config/pytest.ini -n auto -k{ match !r} --color=yes tests" ,
233
220
)
0 commit comments