Skip to content

Commit 9b05532

Browse files
Merge branch 'main' into 1320-enable-reportcallindefaultinitializer-in-basedpyright
2 parents 2b03142 + 36d4e7e commit 9b05532

26 files changed

Lines changed: 201 additions & 60 deletions

File tree

.importlinter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ type = layers
130130
containers =
131131
usethis._ui.interface
132132
layers =
133-
arch | author | badge | browse | ci | doc | docstyle | format_ | init | lint | list | readme | rule | show | spellcheck | status | test | tool | typecheck | version
133+
arch | author | badge | browse | ci | doc | docstyle | format_ | hook | init | lint | list | readme | rule | show | spellcheck | status | test | tool | typecheck | version
134134
exhaustive = true
135135

136136
[importlinter:contract:pipeweld]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Additionally, the command line reference documentation can be viewed with `useth
7373
- [`usethis arch`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-arch) — Add/Configure recommended architecture analysis tools (namely, [Import Linter](https://import-linter.readthedocs.io/en/stable/)).
7474
- [`usethis doc`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-doc) — Add/Configure recommended documentation tools (namely, [MkDocs](https://www.mkdocs.org/)).
7575
- [`usethis format`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-format) — Add/Configure recommended formatters (namely, [Ruff](https://docs.astral.sh/ruff/formatter/) and [pyproject-fmt](https://pyproject-fmt.readthedocs.io/en/latest/)).
76+
- [`usethis hook`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-hook) — Add/Configure a recommended git hook framework (namely, [pre-commit](https://github.com/pre-commit/pre-commit)).
7677
- [`usethis lint`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-lint) — Add/Configure recommended linters (namely, [Ruff](https://docs.astral.sh/ruff/linter) and [deptry](https://github.com/fpgmaas/deptry)).
7778
- [`usethis spellcheck`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-spellcheck) — Add/Configure recommended spellcheckers (namely, [codespell](https://github.com/codespell-project/codespell)).
7879
- [`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)).

docs/cli/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [`usethis arch`](reference.md#usethis-arch) — Add/Configure recommended architecture analysis tools (namely, [Import Linter](https://import-linter.readthedocs.io/en/stable/)).
1010
- [`usethis doc`](reference.md#usethis-doc) — Add/Configure recommended documentation tools (namely, [MkDocs](https://www.mkdocs.org/)).
1111
- [`usethis format`](reference.md#usethis-format) — Add/Configure recommended formatters (namely, [Ruff](https://docs.astral.sh/ruff/formatter/) and [pyproject-fmt](https://pyproject-fmt.readthedocs.io/en/latest/)).
12+
- [`usethis hook`](reference.md#usethis-hook) — Add/Configure a recommended git hook framework (namely, [pre-commit](https://github.com/pre-commit/pre-commit)).
1213
- [`usethis lint`](reference.md#usethis-lint) — Add/Configure recommended linters (namely, [Ruff](https://docs.astral.sh/ruff/linter) and [deptry](https://github.com/fpgmaas/deptry)).
1314
- [`usethis spellcheck`](reference.md#usethis-spellcheck) — Add/Configure recommended spellcheckers (namely, [codespell](https://github.com/codespell-project/codespell)).
1415
- [`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)).

docs/cli/reference.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Initialize a new Python project with recommended defaults, including:
77
- a `pyproject.toml` file and relevant configuration,
88
- recommended linters, formatters, spellcheckers, type checkers, and test frameworks (all opt-out),
99
- docstring style enforcement (opt-in),
10-
- the pre-commit framework (opt-in),
10+
- a recommended git hook framework (opt-in),
1111
- CI services (opt-in),
1212
- declared & installed dependencies via `uv add`, and
1313
- any other relevant directories or tool-bespoke configuration files.
@@ -21,7 +21,7 @@ Supported options:
2121
- `--spellcheck` to add a recommended spellchecker (default; or `--no-spellcheck` to opt-out)
2222
- `--test` to add a recommended testing framework (default; or `--no-test` to opt-out)
2323
- `--typecheck` to add a recommended type checker (default; or `--no-typecheck` to opt-out)
24-
- `--pre-commit` to add the pre-commit framework for git hooks (but the default is `--no-pre-commit`)
24+
- `--hook` to add a recommended git hook framework (but the default is `--no-hook`)
2525
- `--ci` to add a CI service configuration
2626

2727
Possible values:
@@ -124,6 +124,32 @@ Supported options:
124124

125125
See [`usethis tool`](#usethis-tool) for more information.
126126

127+
## `usethis hook`
128+
129+
Add a recommended git hook framework to the project (namely, [pre-commit](https://github.com/pre-commit/pre-commit)), including:
130+
131+
- declared & installed dependencies via `uv add`,
132+
- relevant configuration, and
133+
- any other relevant directories or tool-bespoke configuration files.
134+
135+
Note if `pyproject.toml` is not present, it will be created, since this is required for declaring dependencies via `uv add`.
136+
137+
Supported options:
138+
139+
- `--remove` to remove the tool instead of adding it
140+
- `--how` to only print how to use the tool, with no other side effects
141+
- `--offline` to disable network access and rely on caches
142+
- `--frozen` to leave the virtual environment and lockfile unchanged
143+
- `--quiet` to suppress output
144+
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
145+
146+
Possible values:
147+
- `auto` to auto-detect the backend (default)
148+
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
149+
- `none` to not use a package manager backend and display messages for some operations.
150+
151+
See [`usethis tool`](#usethis-tool) for more information.
152+
127153
## `usethis lint`
128154

129155
Add recommended linters to the project (namely, [Ruff](https://docs.astral.sh/ruff/linter) and [deptry](https://github.com/fpgmaas/deptry)), including:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ reportExplicitAny = false
213213
reportImplicitStringConcatenation = false
214214
reportMissingParameterType = false
215215
reportMissingTypeArgument = false
216-
reportPrivateUsage = false
217216
reportUnknownArgumentType = false
218217
reportUnknownMemberType = false
219218
reportUnknownVariableType = false
@@ -222,6 +221,7 @@ reportUnusedCallResult = false
222221

223222
[[tool.basedpyright.executionEnvironments]]
224223
root = "tests"
224+
reportPrivateUsage = false
225225
reportUnannotatedClassAttribute = false
226226
reportUnknownLambdaType = false
227227
reportUnknownParameterType = false

src/usethis/_backend/uv/call.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ def _prepare_pyproject_write() -> None:
8282
if is_pyproject_toml and is_locked:
8383
ensure_pyproject_validity()
8484
PyprojectTOMLManager().write_file()
85-
PyprojectTOMLManager()._content = None # Basically a cache clear
85+
PyprojectTOMLManager().revert()
8686
elif not is_pyproject_toml and is_locked:
87-
# Similarly; cache clear
88-
PyprojectTOMLManager()._content = None
87+
PyprojectTOMLManager().revert()
8988
elif is_pyproject_toml:
9089
with PyprojectTOMLManager():
9190
ensure_pyproject_validity()

src/usethis/_core/tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _add_bitbucket_linter_steps_to_default() -> None:
244244
tools: list[Tool] = [PyprojectFmtTool(), DeptryTool(), RuffTool()]
245245
for tool in tools:
246246
if tool.is_used():
247-
tool._unconditional_update_bitbucket_steps()
247+
tool.unconditional_update_bitbucket_steps()
248248

249249

250250
def _remove_bitbucket_linter_steps_from_default() -> None:
@@ -441,7 +441,7 @@ def use_ruff(
441441
# See docstring. Basically, `usethis docstyle` manages the pydocstyle rules,
442442
# so we want to allow the user to subsequently call `usethis tool ruff` and
443443
# still get non-minimal default rules.
444-
all(tool._is_pydocstyle_rule(rule) for rule in tool.selected_rules())
444+
all(tool.is_pydocstyle_rule(rule) for rule in tool.selected_rules())
445445
# Another situation where we add default rules is when there are no rules
446446
# selected yet (and we haven't explicitly been requested to add minimal config).
447447
or not tool.selected_rules()

src/usethis/_file/manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ def commit(self, document: DocumentT) -> None:
109109
self._validate_lock()
110110
self._content = document
111111

112+
def revert(self) -> None:
113+
"""Clear the stored document without writing to disk."""
114+
self._content = None
115+
112116
def write_file(self) -> None:
113117
"""Write the stored document to disk if there are changes."""
114118
self._validate_lock()

src/usethis/_file/merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
T = TypeVar("T", bound=MutableMapping[Any, Any])
77

88

9-
def _deep_merge(target: T, source: MutableMapping[Any, Any]) -> T:
9+
def deep_merge(target: T, source: MutableMapping[Any, Any]) -> T:
1010
"""Recursively merge source into target in place, returning target.
1111
1212
For keys present in both mappings, if both values are mappings the merge is
@@ -18,7 +18,7 @@ def _deep_merge(target: T, source: MutableMapping[Any, Any]) -> T:
1818
and isinstance(target[key], MutableMapping)
1919
and isinstance(value, MutableMapping)
2020
):
21-
_deep_merge(target[key], value)
21+
deep_merge(target[key], value)
2222
else:
2323
target[key] = value
2424
return target

src/usethis/_file/pyproject_toml/valid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _ensure_project_name(project: Table) -> None:
6363
name = get_project_name_from_dir()
6464

6565
tick_print(f"Setting project name to '{name}' in 'pyproject.toml'.")
66-
if project._value:
67-
project._value._insert_at(0, "name", name)
66+
if project.value:
67+
project._value._insert_at(0, "name", name) # pyright: ignore[reportPrivateUsage]
6868
else:
6969
project["name"] = name

0 commit comments

Comments
 (0)