66import re
77import sys
88import warnings
9- from contextlib import contextmanager
109from functools import partial
11- from importlib .metadata import version as pkgversion
1210from pathlib import Path
1311from random import sample
1412from tempfile import gettempdir
1917from pysource_minimize import minimize
2018
2119if TYPE_CHECKING :
22- from collections .abc import Iterator
23-
2420 from duty .context import Context
2521
2622
3228PTY = not WINDOWS and not CI
3329MULTIRUN = os .environ .get ("MULTIRUN" , "0" ) == "1"
3430PY_VERSION = f"{ sys .version_info .major } { sys .version_info .minor } "
35- PY_DEV = "314 "
31+ PY_DEV = "315 "
3632
3733
3834def _pyprefix (title : str ) -> str :
@@ -42,22 +38,10 @@ def _pyprefix(title: str) -> str:
4238 return title
4339
4440
45- @contextmanager
46- def _material_insiders () -> Iterator [bool ]:
47- if "+insiders" in pkgversion ("mkdocs-material" ):
48- os .environ ["MATERIAL_INSIDERS" ] = "true"
49- try :
50- yield True
51- finally :
52- os .environ .pop ("MATERIAL_INSIDERS" )
53- else :
54- yield False
55-
56-
5741def _get_changelog_version () -> str :
5842 changelog_version_re = re .compile (r"^## \[(\d+\.\d+\.\d+)\].*$" )
5943 with Path (__file__ ).parent .joinpath ("CHANGELOG.md" ).open ("r" , encoding = "utf8" ) as file :
60- return next (filter (bool , map (changelog_version_re .match , file ))).group (1 ) # type : ignore[union-attr ]
44+ return next (filter (bool , map (changelog_version_re .match , file ))).group (1 ) # ty : ignore[invalid-argument-type ]
6145
6246
6347@duty
@@ -209,11 +193,10 @@ def check_docs(ctx: Context) -> None:
209193 Path ("htmlcov/index.html" ).touch (exist_ok = True )
210194 if CI :
211195 os .environ ["DEPLOY" ] = "true"
212- with _material_insiders ():
213- ctx .run (
214- tools .mkdocs .build (strict = True , verbose = True ),
215- title = _pyprefix ("Building documentation" ),
216- )
196+ ctx .run (
197+ tools .mkdocs .build (strict = True , verbose = True ),
198+ title = _pyprefix ("Building documentation" ),
199+ )
217200
218201
219202@duty (nofail = PY_VERSION == PY_DEV )
@@ -224,15 +207,15 @@ def check_types(ctx: Context) -> None:
224207 make check-types
225208 ```
226209
227- Run type-checking on the code with [Mypy ](https://mypy.readthedocs.io /).
210+ Run type-checking on the code with [ty ](https://astral.sh/ty /).
228211
229- The configuration for Mypy is located at `config/mypy.ini `.
212+ The configuration for ty is located at `config/ty.toml `.
230213
231214 If you cannot or don't know how to fix a typing error in your code,
232215 as a last resort you can ignore this specific error with a comment:
233216
234217 ```python title="src/your_package/module.py"
235- print("a code line that triggers a Mypy warning") # type : ignore[ID]
218+ print("a code line that triggers a ty warning") # ty : ignore[ID]
236219 ```
237220
238221 ...where ID is the name of the warning.
@@ -245,24 +228,25 @@ def check_types(ctx: Context) -> None:
245228 ```console
246229 $ make check-types
247230 ✗ Checking types (1)
248- > mypy --config-file =config/mypy.ini src/ tests/ scripts/
249- src/your_package/module .py:2:1: Item "None" of "Data | None" has no attribute "value" [union-attr]
231+ > ty check --config=config/ty.toml src/ tests/ scripts/
232+ t .py:6:10: warning[possibly-missing-attribute] Attribute `value` may be missing on object of type `Data | None`
250233 ```
251234
252235 Now add a comment to ignore this warning.
253236
254237 ```python title="src/your_package/module.py"
255- result = data_dict.get(key, None).value # type : ignore[union-attr ]
238+ result = data_dict.get(key, None).value # ty : ignore[possibly-missing-attribute ]
256239 ```
257240
258241 ```console
259242 $ make check-types
260243 ✓ Checking types
261244 ```
262245 """
263- os .environ ["FORCE_COLOR" ] = "1"
246+ """Check that the code is correctly typed."""
247+ py = f"{ sys .version_info .major } .{ sys .version_info .minor } "
264248 ctx .run (
265- tools .mypy (* PY_SRC_LIST , config_file = "config/mypy.ini" ),
249+ tools .ty . check (* PY_SRC_LIST , color = True , error_on_warning = True , python_version = py ),
266250 title = _pyprefix ("Type-checking" ),
267251 )
268252
@@ -327,12 +311,11 @@ def docs(ctx: Context, *cli_args: str, host: str = "127.0.0.1", port: int = 8000
327311 host: The host to serve the docs from.
328312 port: The port to serve the docs on.
329313 """
330- with _material_insiders ():
331- ctx .run (
332- tools .mkdocs .serve (dev_addr = f"{ host } :{ port } " ).add_args (* cli_args ),
333- title = "Serving documentation" ,
334- capture = False ,
335- )
314+ ctx .run (
315+ tools .mkdocs .serve (dev_addr = f"{ host } :{ port } " ).add_args (* cli_args ),
316+ title = "Serving documentation" ,
317+ capture = False ,
318+ )
336319
337320
338321@duty
@@ -346,10 +329,7 @@ def docs_deploy(ctx: Context) -> None:
346329 Use [MkDocs](https://www.mkdocs.org/) to build and deploy the documentation to GitHub pages.
347330 """
348331 os .environ ["DEPLOY" ] = "true"
349- with _material_insiders () as insiders :
350- if not insiders :
351- ctx .run (lambda : False , title = "Not deploying docs without Material for MkDocs Insiders!" )
352- ctx .run (tools .mkdocs .gh_deploy (force = True ), title = "Deploying documentation" )
332+ ctx .run (tools .mkdocs .gh_deploy (force = True ), title = "Deploying documentation" )
353333
354334
355335@duty
0 commit comments