You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement usethis tool ty and usethis typecheck (#1446)
* Implement `usethis tool ty` and `usethis typecheck`
* Bump uv fallback version
* Update `TestGetUsageTable` to include ty
* Include ty in `OTHER_TOOLS`
* Elaborate on required updates in `CONTRIBUTING.md`
* Remove `ty` from the benchmark `test_several_tools_add_and_remove`
Add `--typecheck` support to `usethis init`
* Use default ty config to analyze `src` and `tests`
* Update failing test
* Strengthen test in tests/usethis/_core/test_core_tool.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -162,9 +162,14 @@ Tool implementations are defined in classes in the `usethis._tool.impl` module.
162
162
163
163
- You should write tests in `tests/usethis/_core/test_core_tool` for the `use_*` function, following the pattern of the other tests in that module for other tools.
164
164
165
-
#### Pass tests
165
+
#### Register the tool as a peer in `PyprojectTOMLTool`
166
166
167
-
- Some tests may break as a result of new test registration, for example the `TestGetUsageTable` tests for the `usethis list` command. You should run the test suite (via CI if you like) and address any failing tests.
167
+
- Add your `Tool` subclass instance to the `OTHER_TOOLS` list in `usethis._tool.impl.base.pyproject_toml`. This list tracks all tools other than `pyproject.toml` itself, and is used by `PyprojectTOMLTool` to detect active configuration. A corresponding test `test_in_sync_with_all_tools` will fail if this step is missed.
168
+
169
+
#### Update tests
170
+
171
+
- Some tests may need updating as a result of new tool registration. In particular:
172
+
-`TestGetUsageTable` tests in `tests/usethis/_core/test_list.py` — these enumerate all tools and their statuses. Add a `UsageRow` for your new tool.
-[`usethis test`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-test) — Add/Configure a recommended testing framework (namely, [pytest](https://github.com/pytest-dev/pytest) with [Coverage.py](https://github.com/nedbat/coveragepy)).
78
+
-[`usethis typecheck`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-typecheck) — Add/Configure a recommended type checker (namely, [ty](https://docs.astral.sh/ty/)).
78
79
-[`usethis tool`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-tool) — Add/Configure specific tools individually.
79
80
-[`usethis tool codespell`](https://usethis.readthedocs.io/en/stable/cli/reference#code-quality-tools) - Use the [codespell spellchecker](https://github.com/codespell-project/codespell): detect common spelling mistakes.
80
81
-[`usethis tool deptry`](https://usethis.readthedocs.io/en/stable/cli/reference#code-quality-tools) - Use the [deptry linter](https://github.com/fpgmaas/deptry): avoid missing or superfluous dependency declarations.
81
82
-[`usethis tool import-linter`](https://usethis.readthedocs.io/en/stable/cli/reference#code-quality-tools) - Use [Import Linter](https://import-linter.readthedocs.io/en/stable/): enforce a self-imposed architecture on imports.
82
83
-[`usethis tool pre-commit`](https://usethis.readthedocs.io/en/stable/cli/reference#code-quality-tools) - Use the [pre-commit](https://github.com/pre-commit/pre-commit) framework to manage and maintain Git hooks. Note that this will also install all the hooks to Git.
83
84
-[`usethis tool pyproject-fmt`](https://usethis.readthedocs.io/en/stable/cli/reference#code-quality-tools) - Use the [pyproject-fmt formatter](https://github.com/tox-dev/toml-fmt/tree/main/pyproject-fmt): opinionated formatting of 'pyproject.toml' files.
84
85
-[`usethis tool ruff`](https://usethis.readthedocs.io/en/stable/cli/reference#code-quality-tools) - Use [Ruff](https://github.com/astral-sh/ruff): an extremely fast Python linter and code formatter.
86
+
-[`usethis tool ty`](https://usethis.readthedocs.io/en/stable/cli/reference#code-quality-tools) - Use [ty](https://docs.astral.sh/ty/): an extremely fast Python type checker.
85
87
-[`usethis tool coverage.py`](https://usethis.readthedocs.io/en/stable/cli/reference#testing) - Use [Coverage.py](https://github.com/nedbat/coveragepy): a code coverage measurement tool.
86
88
-[`usethis tool pytest`](https://usethis.readthedocs.io/en/stable/cli/reference#testing) - Use the [pytest](https://github.com/pytest-dev/pytest) testing framework.
87
89
-[`usethis tool mkdocs`](https://usethis.readthedocs.io/en/stable/cli/reference#documentation) - Use [MkDocs](https://www.mkdocs.org/): Generate project documentation sites with Markdown.
@@ -173,13 +175,7 @@ If you're not interested in templating automations, then [configurator](https://
-[`usethis test`](reference.md#usethis-test) — Add/Configure a recommended testing framework (namely, [pytest](https://github.com/pytest-dev/pytest) with [Coverage.py](https://github.com/nedbat/coveragepy)).
14
+
-[`usethis typecheck`](reference.md#usethis-typecheck) — Add/Configure a recommended type checker (namely, [ty](https://docs.astral.sh/ty/)).
14
15
-[`usethis tool`](reference.md#usethis-tool) — Add/Configure specific tools individually.
15
16
-[`usethis tool codespell`](reference.md#code-quality-tools) - Use the [codespell spellchecker](https://github.com/codespell-project/codespell): detect common spelling mistakes.
16
17
-[`usethis tool deptry`](reference.md#code-quality-tools) - Use the [deptry linter](https://github.com/fpgmaas/deptry): avoid missing or superfluous dependency declarations.
17
18
-[`usethis tool import-linter`](reference.md#code-quality-tools) - Use [Import Linter](https://import-linter.readthedocs.io/en/stable/): enforce a self-imposed architecture on imports.
18
19
-[`usethis tool pre-commit`](reference.md#code-quality-tools) - Use the [pre-commit](https://github.com/pre-commit/pre-commit) framework to manage and maintain Git hooks. Note that this will also install all the hooks to Git.
19
20
-[`usethis tool pyproject-fmt`](reference.md#code-quality-tools) - Use the [pyproject-fmt formatter](https://github.com/tox-dev/toml-fmt/tree/main/pyproject-fmt): opinionated formatting of 'pyproject.toml' files.
20
21
-[`usethis tool ruff`](reference.md#code-quality-tools) - Use [Ruff](https://github.com/astral-sh/ruff): an extremely fast Python linter and code formatter.
22
+
-[`usethis tool ty`](reference.md#code-quality-tools) - Use [ty](https://docs.astral.sh/ty/): an extremely fast Python type checker.
21
23
-[`usethis tool coverage.py`](reference.md#testing) - Use [Coverage.py](https://github.com/nedbat/coveragepy): a code coverage measurement tool.
22
24
-[`usethis tool pytest`](reference.md#testing) - Use the [pytest](https://github.com/pytest-dev/pytest) testing framework.
23
25
-[`usethis tool mkdocs`](reference.md#documentation) - Use [MkDocs](https://www.mkdocs.org/): Generate project documentation sites with Markdown.
Copy file name to clipboardExpand all lines: docs/cli/reference.md
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
Initialize a new Python project with recommended defaults, including:
6
6
7
7
- a `pyproject.toml` file and relevant configuration,
8
-
- recommended linters, formatters, spellcheckers, and test frameworks (all opt-out),
8
+
- recommended linters, formatters, spellcheckers, type checkers, and test frameworks (all opt-out),
9
9
- docstring style enforcement (opt-in),
10
10
- the pre-commit framework (opt-in),
11
11
- CI services (opt-in),
@@ -19,6 +19,7 @@ Supported options:
19
19
-`--lint` to add recommended linters (default; or `--no-lint` to opt-out)
20
20
-`--spellcheck` to add a recommended spellchecker (default; or `--no-spellcheck` to opt-out)
21
21
-`--test` to add a recommended testing framework (default; or `--no-test` to opt-out)
22
+
-`--typecheck` to add a recommended type checker (default; or `--no-typecheck` to opt-out)
22
23
-`--pre-commit` to add the pre-commit framework for git hooks (but the default is `--no-pre-commit`)
23
24
-`--ci` to add a CI service configuration
24
25
@@ -172,6 +173,32 @@ Possible values:
172
173
173
174
See [`usethis tool`](#usethis-tool) for more information.
174
175
176
+
## `usethis typecheck`
177
+
178
+
Add a recommended type checker to the project (namely, [ty](https://docs.astral.sh/ty/)), including:
179
+
180
+
- declared & installed dependencies with `uv add`,
181
+
- relevant configuration, and
182
+
- any other relevant directories or tool-bespoke configuration files.
183
+
184
+
Note if `pyproject.toml` is not present, it will be created, since this is required for declaring dependencies with `uv add`.
185
+
186
+
Supported options:
187
+
188
+
-`--remove` to remove the tool instead of adding it
189
+
-`--how` to only print how to use the tool, with no other side effects
190
+
-`--offline` to disable network access and rely on caches
191
+
-`--frozen` to leave the virtual environment and lockfile unchanged
192
+
-`--quiet` to suppress output
193
+
-`--backend` to specify a package manager backend to use. The default is to auto-detect.
194
+
195
+
Possible values:
196
+
-`auto` to auto-detect the backend (default)
197
+
-`uv` to use the [uv](https://docs.astral.sh/uv) package manager
198
+
-`none` to not use a package manager backend and display messages for some operations.
199
+
200
+
See [`usethis tool`](#usethis-tool) for more information.
201
+
175
202
## `usethis tool`
176
203
177
204
Add a new tool to a Python project, including:
@@ -192,6 +219,7 @@ declaring dependencies with `uv add`.
192
219
-`usethis tool pre-commit` - Use the [pre-commit](https://github.com/pre-commit/pre-commit) framework to manage and maintain Git hooks. Note that this will also install all the hooks to Git.
193
220
-`usethis tool pyproject-fmt` - Use the [pyproject-fmt formatter](https://github.com/tox-dev/toml-fmt/tree/main/pyproject-fmt): opinionated formatting of 'pyproject.toml' files.
194
221
-`usethis tool ruff` - Use [Ruff](https://github.com/astral-sh/ruff): an extremely fast Python linter and code formatter.
222
+
-`usethis tool ty` - Use [ty](https://docs.astral.sh/ty/): an extremely fast Python type checker.
0 commit comments