Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/usethis/_core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def use_deptry(*, remove: bool = False, how: bool = False) -> None:
else:
tool.update_bitbucket_steps()

tool.add_configs()
tool.print_how_to_use()
else:
tool.remove_pre_commit_repo_configs()
Expand Down
11 changes: 10 additions & 1 deletion src/usethis/_tool/impl/deptry.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ def get_config_spec(self) -> ConfigSpec:
ConfigItem(
description="Overall config",
root={Path("pyproject.toml"): ConfigEntry(keys=["tool", "deptry"])},
)
),
ConfigItem(
description="Ignore notebooks",
root={
Path("pyproject.toml"): ConfigEntry(
keys=["tool", "deptry", "ignore_notebooks"],
get_value=lambda: False,
)
},
),
],
)

Expand Down
3 changes: 2 additions & 1 deletion src/usethis/_toolset/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@


def use_linters(remove: bool = False, how: bool = False):
use_ruff(linter=True, formatter=False, remove=remove, how=how)
# Use deptry first since it determines that we use 'pyproject.toml' for Ruff.
use_deptry(remove=remove, how=how)
use_ruff(linter=True, formatter=False, remove=remove, how=how)
17 changes: 17 additions & 0 deletions tests/usethis/_core/test_core_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,18 @@ def test_dependency_added(self, uv_init_dir: Path):
(dev_dep,) = get_deps_from_group("dev")
assert dev_dep == Dependency(name="deptry")

@pytest.mark.usefixtures("_vary_network_conn")
def test_ignore_notebooks(self, uv_init_dir: Path):
# Act
with change_cwd(uv_init_dir), PyprojectTOMLManager():
use_deptry()

# Assert
assert (
PyprojectTOMLManager()[["tool", "deptry", "ignore_notebooks"]]
is False
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_stdout(
self,
Expand All @@ -569,6 +581,7 @@ def test_stdout(
assert out == (
"✔ Adding dependency 'deptry' to the 'dev' group in 'pyproject.toml'.\n"
"☐ Install the dependency 'deptry'.\n"
"✔ Adding deptry config to 'pyproject.toml'.\n"
"☐ Run 'uv run deptry src' to run deptry.\n"
)

Expand All @@ -592,6 +605,7 @@ def test_stdout_unfrozen(
out, _ = capfd.readouterr()
assert out == (
"✔ Adding dependency 'deptry' to the 'dev' group in 'pyproject.toml'.\n"
"✔ Adding deptry config to 'pyproject.toml'.\n"
"☐ Run 'uv run deptry src' to run deptry.\n"
)

Expand Down Expand Up @@ -668,6 +682,7 @@ def test_pre_commit_after(
assert out == (
"✔ Adding dependency 'deptry' to the 'dev' group in 'pyproject.toml'.\n"
"☐ Install the dependency 'deptry'.\n"
"✔ Adding deptry config to 'pyproject.toml'.\n"
"☐ Run 'uv run deptry src' to run deptry.\n"
"✔ Adding dependency 'pre-commit' to the 'dev' group in 'pyproject.toml'.\n"
"☐ Install the dependency 'pre-commit'.\n"
Expand Down Expand Up @@ -829,6 +844,7 @@ def test_pre_commit_first(
"✔ Adding dependency 'deptry' to the 'dev' group in 'pyproject.toml'.\n"
"☐ Install the dependency 'deptry'.\n"
"✔ Adding hook 'deptry' to '.pre-commit-config.yaml'.\n"
"✔ Adding deptry config to 'pyproject.toml'.\n"
"☐ Run 'uv run deptry src' to run deptry.\n"
)

Expand Down Expand Up @@ -861,6 +877,7 @@ def test_placeholder_removed(
"✔ Adding dependency 'deptry' to the 'dev' group in 'pyproject.toml'.\n"
"☐ Install the dependency 'deptry'.\n"
"✔ Adding hook 'deptry' to '.pre-commit-config.yaml'.\n"
"✔ Adding deptry config to 'pyproject.toml'.\n"
"☐ Run 'uv run deptry src' to run deptry.\n"
)

Expand Down
1 change: 1 addition & 0 deletions tests/usethis/_core/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_deptry_rule_selected(
assert out == (
"✔ Adding dependency 'deptry' to the 'dev' group in 'pyproject.toml'.\n"
"☐ Install the dependency 'deptry'.\n"
"✔ Adding deptry config to 'pyproject.toml'.\n"
"☐ Run 'uv run deptry src' to run deptry.\n"
"ℹ All deptry rules are always implicitly selected.\n" # noqa: RUF001
)
Expand Down
6 changes: 3 additions & 3 deletions tests/usethis/_tool/impl/test_deptry.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def test_get_pyproject_id_keys(self):
result = tool.get_config_spec()

# Assert
(config_item,) = result.config_items
config_item: ConfigItem
config_item, *_ = result.config_items
assert isinstance(config_item, ConfigItem)
assert config_item.root[Path("pyproject.toml")] == ConfigEntry(
keys=["tool", "deptry"]
)
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_empty_dir(self, tmp_path: Path):
DeptryTool().add_configs()

# Assert
assert not (tmp_path / "pyproject.toml").exists()
assert (tmp_path / "pyproject.toml").exists()

def test_pyproject_toml_exists(self, tmp_path: Path):
# Arrange
Expand Down
8 changes: 4 additions & 4 deletions tests/usethis/_ui/interface/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def test_pre_commit_included(self, tmp_path: Path):
"☐ Run 'uv run mkdocs build' to build the documentation.\n"
"☐ Run 'uv run mkdocs serve' to serve the documentation locally.\n"
"✔ Adding recommended linters.\n"
"☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.\n"
"☐ Run 'uv run deptry src' to run deptry.\n"
"☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.\n"
"✔ Adding recommended formatters.\n"
"☐ Run 'uv run ruff format' to run the Ruff formatter.\n"
"☐ Run 'uv run pre-commit run pyproject-fmt --all-files' to run pyproject-fmt.\n"
Expand Down Expand Up @@ -91,8 +91,8 @@ def test_readme_example(self, tmp_path: Path):
☐ Run 'uv run mkdocs build' to build the documentation.
☐ Run 'uv run mkdocs serve' to serve the documentation locally.
✔ Adding recommended linters.
☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.
☐ Run 'uv run deptry src' to run deptry.
☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.
✔ Adding recommended formatters.
☐ Run 'uv run ruff format' to run the Ruff formatter.
☐ Run 'uv run pyproject-fmt pyproject.toml' to run pyproject-fmt.
Expand Down Expand Up @@ -162,8 +162,8 @@ def test_bitbucket_docstyle_and_status(self, tmp_path: Path):
"☐ Run 'uv run mkdocs build' to build the documentation.\n"
"☐ Run 'uv run mkdocs serve' to serve the documentation locally.\n"
"✔ Adding recommended linters.\n"
"☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.\n"
"☐ Run 'uv run deptry src' to run deptry.\n"
"☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.\n"
"✔ Adding recommended formatters.\n"
"☐ Run 'uv run ruff format' to run the Ruff formatter.\n"
"☐ Run 'uv run pre-commit run pyproject-fmt --all-files' to run pyproject-fmt.\n"
Expand Down Expand Up @@ -198,8 +198,8 @@ def test_none_backend(self, tmp_path: Path):
"☐ Run 'mkdocs build' to build the documentation.\n"
"☐ Run 'mkdocs serve' to serve the documentation locally.\n"
"✔ Adding recommended linters.\n"
"☐ Run 'ruff check --fix' to run the Ruff linter with autofixes.\n"
"☐ Run 'deptry src' to run deptry.\n"
"☐ Run 'ruff check --fix' to run the Ruff linter with autofixes.\n"
"✔ Adding recommended formatters.\n"
"☐ Run 'ruff format' to run the Ruff formatter.\n"
"☐ Run 'pyproject-fmt pyproject.toml' to run pyproject-fmt.\n"
Expand Down
20 changes: 11 additions & 9 deletions tests/usethis/_ui/interface/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ def test_none_backend_no_pyproject_toml(self, tmp_path: Path):

# Assert
assert result.exit_code == 0, result.output
assert not (tmp_path / "pyproject.toml").exists()
assert (tmp_path / "pyproject.toml").exists() # from deptry config
assert result.output.replace("\n", "") == (
"☐ Add the dev dependency 'ruff'.\n"
"✔ Writing 'ruff.toml'.\n"
"✔ Adding Ruff config to 'ruff.toml'.\n"
"✔ Selecting Ruff rules 'A', 'C4', 'E4', 'E7', 'E9', 'F', 'FLY', 'FURB', 'I', 'PLE', 'PLR', 'RUF', 'SIM', 'UP' in 'ruff.toml'.\n"
"✔ Ignoring Ruff rules 'PLR2004', 'SIM108' in 'ruff.toml'.\n"
"☐ Run 'ruff check --fix' to run the Ruff linter with autofixes.\n"
"☐ Add the dev dependency 'deptry'.\n"
"✔ Writing 'pyproject.toml'.\n"
"✔ Adding deptry config to 'pyproject.toml'.\n"
"☐ Run 'deptry .' to run deptry.\n"
"☐ Add the dev dependency 'ruff'.\n"
"✔ Adding Ruff config to 'pyproject.toml'.\n"
"✔ Selecting Ruff rules 'A', 'C4', 'E4', 'E7', 'E9', 'F', 'FLY', 'FURB', 'I', 'PLE', 'PLR', 'RUF', 'SIM', 'UP' in 'pyproject.toml'.\n"
"✔ Ignoring Ruff rules 'PLR2004', 'SIM108' in 'pyproject.toml'.\n"
"☐ Run 'ruff check --fix' to run the Ruff linter with autofixes.\n"
).replace("\n", "")

def test_none_backend_pyproject_toml(self, tmp_path: Path):
Expand All @@ -60,11 +61,12 @@ def test_none_backend_pyproject_toml(self, tmp_path: Path):
assert result.exit_code == 0, result.output
assert (tmp_path / "pyproject.toml").exists()
assert result.output.replace("\n", "") == (
"☐ Add the dev dependency 'deptry'.\n"
"✔ Adding deptry config to 'pyproject.toml'.\n"
"☐ Run 'deptry .' to run deptry.\n"
"☐ Add the dev dependency 'ruff'.\n"
"✔ Adding Ruff config to 'pyproject.toml'.\n"
"✔ Selecting Ruff rules 'A', 'C4', 'E4', 'E7', 'E9', 'F', 'FLY', 'FURB', 'I', 'PLE', 'PLR', 'RUF', 'SIM', 'UP' in 'pyproject.toml'.\n"
"✔ Ignoring Ruff rules 'PLR2004', 'SIM108' in 'pyproject.toml'.\n"
"☐ Run 'ruff check --fix' to run the Ruff linter with autofixes.\n"
"☐ Add the dev dependency 'deptry'.\n"
"☐ Run 'deptry .' to run deptry.\n"
).replace("\n", "")