Skip to content

Commit cd89644

Browse files
Migrate to Ruff 0.14.3 (#1094)
* Migrate to Ruff 0.14.3 Tweak newline writing logic in `use_requirements_txt` per FURB122 Make some lazy-loading expectations in the UI layer explicit via a `ruff.toml` extending config from `pyproject.toml`. Exclude this via hatch config from builds. Comply with RUF 043 via raw-strings in pytest `match=` arguments Migrate to new recommended `ruff-check` hook name in `ruff-pre-commit` instead of just `ruff` simpliciter * Move `from usethis._config import usethis_config` imports to the module level in the UI layer
1 parent 9a9a663 commit cd89644

32 files changed

Lines changed: 122 additions & 113 deletions

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ repos:
5555
- id: pyproject-fmt
5656
args: [--max-supported-python=3.14]
5757
- repo: https://github.com/astral-sh/ruff-pre-commit
58-
rev: v0.11.5
58+
rev: v0.14.3
5959
hooks:
60-
- id: ruff
60+
- id: ruff-check
6161
args: [ --fix ]
6262
- id: ruff-format
6363
- repo: local

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dev = [
6060
"jinja2>=3.1.6",
6161
"prek>=0.2.4",
6262
"pyright[nodejs]>=1.1.399",
63-
"ruff>=0.11.5",
63+
"ruff>=0.14.3",
6464
]
6565
test = [
6666
"click>=8.1.8",
@@ -80,6 +80,11 @@ doc = [
8080
[tool.hatch.version]
8181
source = "vcs"
8282

83+
[tool.hatch.build.targets.sdist]
84+
exclude = [
85+
"ruff.toml",
86+
]
87+
8388
[tool.hatch.metadata.hooks.vcs.urls]
8489
"Source Code" = "https://github.com/usethis-python/usethis-python"
8590
"Documentation" = "https://usethis.readthedocs.io/en/stable/"
@@ -112,6 +117,7 @@ lint.select = [
112117
"FURB",
113118
"I",
114119
"INP",
120+
"PLC0415",
115121
"PLE",
116122
"PLR",
117123
"PT",
@@ -123,7 +129,7 @@ lint.select = [
123129
"UP",
124130
]
125131
lint.ignore = [ "PLR2004", "S101", "SIM108" ]
126-
lint.per-file-ignores."!tests/**/*.py" = [ "ARG002" ]
132+
lint.per-file-ignores."!tests/**/*.py" = [ "ARG002", "PT" ]
127133
lint.per-file-ignores."tests/**/*.py" = [ "D", "INP", "S603", "TC" ]
128134
lint.flake8-bugbear.extend-immutable-calls = [ "typer.Argument", "typer.Option" ]
129135

requirements.txt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -836,25 +836,26 @@ ruamel-yaml-clib==0.2.12 ; python_full_version < '3.14' and platform_python_impl
836836
--hash=sha256:f66efbc1caa63c088dead1c4170d148eabc9b80d95fb75b6c92ac0aad2437d76 \
837837
--hash=sha256:fd5415dded15c3822597455bc02bcd66e81ef8b7a48cb71a33628fc9fdde39df
838838
# via ruamel-yaml
839-
ruff==0.11.5 \
840-
--hash=sha256:0947c0a1afa75dcb5db4b34b070ec2bccee869d40e6cc8ab25aca11a7d527794 \
841-
--hash=sha256:2561294e108eb648e50f210671cc56aee590fb6167b594144401532138c66c7b \
842-
--hash=sha256:3068befab73620b8a0cc2431bd46b3cd619bc17d6f7695a3e1bb166b652c382a \
843-
--hash=sha256:4bfd80a6ec559a5eeb96c33f832418bf0fb96752de0539905cf7b0cc1d31d779 \
844-
--hash=sha256:56145ee1478582f61c08f21076dc59153310d606ad663acc00ea3ab5b2125f82 \
845-
--hash=sha256:67e241b4314f4eacf14a601d586026a962f4002a475aa702c69980a38087aa4e \
846-
--hash=sha256:6c6dc38af3cfe2863213ea25b6dc616d679205732dc0fb673356c2d69608f800 \
847-
--hash=sha256:80b4df4d335a80315ab9afc81ed1cff62be112bd165e162b5eed8ac55bfc8470 \
848-
--hash=sha256:81be52e7519f3d1a0beadcf8e974715b2dfc808ae8ec729ecfc79bddf8dbb783 \
849-
--hash=sha256:ac12884b9e005c12d0bd121f56ccf8033e1614f736f766c118ad60780882a077 \
850-
--hash=sha256:ad871ff74b5ec9caa66cb725b85d4ef89b53f8170f47c3406e32ef040400b038 \
851-
--hash=sha256:b2a7cedf47244f431fd11aa5a7e2806dda2e0c365873bda7834e8f7d785ae159 \
852-
--hash=sha256:cae2e2439cb88853e421901ec040a758960b576126dab520fa08e9de431d1bef \
853-
--hash=sha256:e268da7b40f56e3eca571508a7e567e794f9bfcc0f412c4b607931d3af9c4afe \
854-
--hash=sha256:e5f66f8f1e8c9fc594cbd66fbc5f246a8d91f916cb9667e80208663ec3728304 \
855-
--hash=sha256:e6cf918390cfe46d240732d4d72fa6e18e528ca1f60e318a10835cf2fa3dc19f \
856-
--hash=sha256:ef39f19cb8ec98cbc762344921e216f3857a06c47412030374fffd413fb8fd3a \
857-
--hash=sha256:f5da2e710a9641828e09aa98b92c9ebbc60518fdf3921241326ca3e8f8e55b8b
839+
ruff==0.14.3 \
840+
--hash=sha256:0e2f8a0bbcffcfd895df39c9a4ecd59bb80dca03dc43f7fb63e647ed176b741e \
841+
--hash=sha256:1ec1ac071e7e37e0221d2f2dbaf90897a988c531a8592a6a5959f0603a1ecf5e \
842+
--hash=sha256:26eb477ede6d399d898791d01961e16b86f02bc2486d0d1a7a9bb2379d055dc1 \
843+
--hash=sha256:3d6bc90307c469cb9d28b7cfad90aaa600b10d67c6e22026869f585e1e8a2db0 \
844+
--hash=sha256:469e35872a09c0e45fecf48dd960bfbce056b5db2d5e6b50eca329b4f853ae20 \
845+
--hash=sha256:4ff876d2ab2b161b6de0aa1f5bd714e8e9b4033dc122ee006925fbacc4f62153 \
846+
--hash=sha256:678fdd7c7d2d94851597c23ee6336d25f9930b460b55f8598e011b57c74fd8c5 \
847+
--hash=sha256:71ff6edca490c308f083156938c0c1a66907151263c4abdcb588602c6e696a14 \
848+
--hash=sha256:786ee3ce6139772ff9272aaf43296d975c0217ee1b97538a98171bf0d21f87ed \
849+
--hash=sha256:7bfc42f81862749a7136267a343990f865e71fe2f99cf8d2958f684d23ce3dfa \
850+
--hash=sha256:876b21e6c824f519446715c1342b8e60f97f93264012de9d8d10314f8a79c371 \
851+
--hash=sha256:a497ec0c3d2c88561b6d90f9c29f5ae68221ac00d471f306fa21fa4264ce5fcd \
852+
--hash=sha256:a65e448cfd7e9c59fae8cf37f9221585d3354febaad9a07f29158af1528e165f \
853+
--hash=sha256:afcdc4b5335ef440d19e7df9e8ae2ad9f749352190e96d481dc501b753f0733e \
854+
--hash=sha256:b6fd8c79b457bedd2abf2702b9b472147cd860ed7855c73a5247fa55c9117654 \
855+
--hash=sha256:cd6291d0061811c52b8e392f946889916757610d45d004e41140d81fb6cd5ddc \
856+
--hash=sha256:d7b7006ac0756306db212fd37116cce2bd307e1e109375e1c6c106002df0ae5f \
857+
--hash=sha256:e231e1be58fc568950a04fbe6887c8e4b85310e7889727e2b81db205c45059eb \
858+
--hash=sha256:f3d91857d023ba93e14ed2d462ab62c3428f9bbf2b4fbac50a03ca66d31991f7
858859
shellingham==1.5.4 \
859860
--hash=sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686 \
860861
--hash=sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de

src/usethis/_core/tool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,9 @@ def use_requirements_txt(*, remove: bool = False, how: bool = False) -> None:
395395
tick_print("Writing 'requirements.txt'.")
396396
with open(path, "w", encoding="utf-8") as f:
397397
f.write("-e .\n")
398-
for dep in get_project_deps():
399-
f.write(dep.to_requirement_string() + "\n")
398+
f.writelines(
399+
dep.to_requirement_string() + "\n" for dep in get_project_deps()
400+
)
400401
else:
401402
assert_never(backend)
402403

src/usethis/_tool/impl/coverage_py.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def name(self) -> str:
3131
return "Coverage.py"
3232

3333
def print_how_to_use(self) -> None:
34-
from usethis._tool.impl.pytest import PytestTool
34+
from usethis._tool.impl.pytest import ( # to avoid circularity; # noqa: PLC0415
35+
PytestTool,
36+
)
3537

3638
backend = get_backend()
3739

@@ -52,7 +54,9 @@ def print_how_to_use(self) -> None:
5254
how_print(f"Run 'coverage help' to see available {self.name} commands.")
5355

5456
def get_test_deps(self, *, unconditional: bool = False) -> list[Dependency]:
55-
from usethis._tool.impl.pytest import PytestTool
57+
from usethis._tool.impl.pytest import ( # to avoid circularity; # noqa: PLC0415
58+
PytestTool,
59+
)
5660

5761
deps = [Dependency(name="coverage", extras=frozenset({"toml"}))]
5862
if unconditional or PytestTool().is_used():

src/usethis/_tool/impl/pytest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def print_how_to_use(self) -> None:
5656
how_print("Run 'pytest' to run the tests.")
5757

5858
def get_test_deps(self, *, unconditional: bool = False) -> list[Dependency]:
59-
from usethis._tool.impl.coverage_py import CoveragePyTool
59+
from usethis._tool.impl.coverage_py import ( # to avoid circularity; # noqa: PLC0415
60+
CoveragePyTool,
61+
)
6062

6163
deps = [Dependency(name="pytest")]
6264
if unconditional or CoveragePyTool().is_used():

src/usethis/_ui/interface/author.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import typer
44

5+
from usethis._config import usethis_config
56
from usethis._types.backend import BackendEnum
67
from usethis._ui.options import backend_opt, quiet_opt
78

@@ -15,7 +16,6 @@ def author(
1516
quiet: bool = quiet_opt,
1617
backend: BackendEnum = backend_opt,
1718
) -> None:
18-
from usethis._config import usethis_config
1919
from usethis._config_file import files_manager
2020
from usethis._console import err_print
2121
from usethis._core.author import add_author

src/usethis/_ui/interface/badge.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import typer
66

7+
from usethis._config import usethis_config
78
from usethis._ui.options import offline_opt, quiet_opt
89

910
if TYPE_CHECKING:
@@ -27,7 +28,6 @@ def pypi(
2728
quiet: bool = quiet_opt,
2829
show: bool = show_opt,
2930
) -> None:
30-
from usethis._config import usethis_config
3131
from usethis._config_file import files_manager
3232
from usethis._core.badge import get_pypi_badge
3333

@@ -42,7 +42,6 @@ def ruff(
4242
quiet: bool = quiet_opt,
4343
show: bool = show_opt,
4444
) -> None:
45-
from usethis._config import usethis_config
4645
from usethis._config_file import files_manager
4746
from usethis._core.badge import get_ruff_badge
4847

@@ -57,7 +56,6 @@ def pre_commit(
5756
quiet: bool = quiet_opt,
5857
show: bool = show_opt,
5958
) -> None:
60-
from usethis._config import usethis_config
6159
from usethis._config_file import files_manager
6260
from usethis._core.badge import get_pre_commit_badge
6361

@@ -74,7 +72,6 @@ def socket(
7472
quiet: bool = quiet_opt,
7573
show: bool = show_opt,
7674
) -> None:
77-
from usethis._config import usethis_config
7875
from usethis._config_file import files_manager
7976
from usethis._core.badge import get_socket_badge
8077

@@ -89,7 +86,6 @@ def usethis(
8986
quiet: bool = quiet_opt,
9087
show: bool = show_opt,
9188
) -> None:
92-
from usethis._config import usethis_config
9389
from usethis._config_file import files_manager
9490
from usethis._core.badge import get_usethis_badge
9591

@@ -104,7 +100,6 @@ def uv(
104100
quiet: bool = quiet_opt,
105101
show: bool = show_opt,
106102
) -> None:
107-
from usethis._config import usethis_config
108103
from usethis._config_file import files_manager
109104
from usethis._core.badge import get_uv_badge
110105

src/usethis/_ui/interface/browse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typer
22

3+
from usethis._config import usethis_config
34
from usethis._ui.options import offline_opt, quiet_opt
45

56
app = typer.Typer(
@@ -17,7 +18,6 @@ def pypi(
1718
offline: bool = offline_opt,
1819
quiet: bool = quiet_opt,
1920
) -> None:
20-
from usethis._config import usethis_config
2121
from usethis._console import err_print
2222
from usethis._core.browse import browse_pypi
2323
from usethis.errors import UsethisError

src/usethis/_ui/interface/ci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typer
22

3+
from usethis._config import usethis_config
34
from usethis._types.backend import BackendEnum
45
from usethis._ui.options import backend_opt, frozen_opt, offline_opt, quiet_opt
56

@@ -18,7 +19,6 @@ def bitbucket(
1819
frozen: bool = frozen_opt,
1920
backend: BackendEnum = backend_opt,
2021
) -> None:
21-
from usethis._config import usethis_config
2222
from usethis._config_file import files_manager
2323
from usethis._console import err_print
2424
from usethis._core.ci import use_ci_bitbucket

0 commit comments

Comments
 (0)