Skip to content

Commit 7da47cb

Browse files
authored
chore: enable more ruff using config (#1179)
Using settings in config to enable more. - **chore: use config setting for RUF009** - **chore: enable builtin-shadow with config** --------- Signed-off-by: Henry Schreiner <[email protected]> Signed-off-by: Henry Schreiner <[email protected]>
1 parent 7a1b783 commit 7da47cb

File tree

8 files changed

+29
-24
lines changed

8 files changed

+29
-24
lines changed

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ ignore = ["W002"] # Triggers on __init__.py's
256256

257257

258258
[tool.ruff]
259+
show-fixes = true
259260
exclude = ["src/scikit_build_core/_vendor/*"]
260261

261262
[tool.ruff.lint]
262263
select = ["ALL"]
263264
ignore = [
264-
"A", # Okay to shadow builtins
265265
"ANN401", # Disallow Any
266266
"C90", # Complexity
267267
"COM", # Trailing commas teach the formatter
@@ -274,7 +274,6 @@ ignore = [
274274
"PLR09", # Too many ...
275275
"PLR2004", # Magic value used in comparison
276276
"PT013", # It's correct to import classes for typing!
277-
"RUF009", # Too easy to get a false positive (function call in dataclass defaults)
278277
"S101", # Use of assert detected
279278
"S404", # subprocess module is possibly insecure
280279
"S603", # subprocess untrusted input
@@ -284,12 +283,16 @@ ignore = [
284283
"TID252", # Relative imports are fine
285284
]
286285
typing-modules = ["scikit_build_core._compat.typing"]
286+
isort.known-local-folder = ["pathutils"]
287+
flake8-bugbear.extend-immutable-calls = [
288+
"packaging.version.Version",
289+
"packaging.specifiers.SpecifierSet",
290+
]
291+
flake8-builtins.ignorelist = ["copyright", "license", "__doc__"]
287292

288293
[tool.ruff.format]
289294
docstring-code-format = true
290295

291-
[tool.ruff.lint.isort]
292-
known-local-folder = ["pathutils"]
293296

294297
[tool.ruff.lint.flake8-tidy-imports.banned-api]
295298
"typing.Callable".msg = "Use collections.abc.Callable instead."

src/scikit_build_core/file_api/model/toolchains.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ class Toolchain:
3838
@dataclasses.dataclass(frozen=True)
3939
class Toolchains:
4040
kind: str = "toolchains"
41-
version: APIVersion = APIVersion(1, 0)
41+
version: APIVersion = APIVersion(1, 0) # noqa: RUF009
4242
toolchains: List[Toolchain] = dataclasses.field(default_factory=list)

src/scikit_build_core/resources/_editable_redirect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(
8787
verbose: bool,
8888
build_options: list[str],
8989
install_options: list[str],
90-
dir: str,
90+
dir: str, # noqa: A002
9191
install_dir: str,
9292
) -> None:
9393
self.known_source_files = known_source_files

tests/test_dynamic_metadata_unit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_regex() -> None:
7272

7373

7474
@pytest.mark.parametrize(
75-
("field", "input", "output"),
75+
("field", "input_", "output"),
7676
[
7777
pytest.param("version", "{sub}", "42", id="str"),
7878
pytest.param("classifiers", ["a", "{sub}"], ["a", "42"], id="list-str"),
@@ -100,6 +100,6 @@ def test_regex() -> None:
100100
),
101101
],
102102
)
103-
def test_actions(field: str, input: Any, output: Any) -> None:
104-
result = _process_dynamic_metadata(field, lambda x: x.format(sub=42), input)
103+
def test_actions(field: str, input_: Any, output: Any) -> None:
104+
result = _process_dynamic_metadata(field, lambda x: x.format(sub=42), input_)
105105
assert output == result

tests/test_file_processor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ def test_on_each_with_symlink(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -
7676
gitignore = Path(".gitignore")
7777
gitignore.write_text("/hidden_dir")
7878
# Create a directory with a symlink to a file in the same directory
79-
dir = Path("dir")
80-
dir.mkdir()
81-
file1 = dir / "file"
79+
pkg_dir = Path("pkg")
80+
pkg_dir.mkdir()
81+
file1 = pkg_dir / "file"
8282
file1.write_text("content")
83-
file2 = dir / "link"
83+
file2 = pkg_dir / "link"
8484
file2.symlink_to("file")
8585
hidden_dir = Path("hidden_dir")
8686
hidden_dir.mkdir()
8787
hidden_file = hidden_dir / "file2"
8888
hidden_file.write_text("content2")
89-
exposed_symlink = dir / "exposed_symlink"
89+
exposed_symlink = pkg_dir / "exposed_symlink"
9090
exposed_symlink.symlink_to("../hidden_dir")
9191

9292
local_ignored_file = Path("local_ignored_file.txt")

tests/test_pyproject_pep517.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def test_pep517_sdist_hash(monkeypatch, package_simple_pyproject_ext, tmp_path:
8989
dist = tmp_path / "dist"
9090
out = build_sdist(str(dist))
9191
sdist = dist / out
92-
hash = compute_uncompressed_hash(sdist)
93-
assert hash == package_simple_pyproject_ext.sdist_hash
92+
sdist_hash = compute_uncompressed_hash(sdist)
93+
assert sdist_hash == package_simple_pyproject_ext.sdist_hash
9494
mode = sdist.stat().st_mode
9595
assert mode == 33188
9696
with gzip.open(sdist, "rb") as f:
@@ -160,8 +160,8 @@ def each_unignored_file_ordered(*args, **kwargs):
160160

161161
out = build_sdist(str(dist), {"sdist.reproducible": "true"})
162162
sdist = dist / out
163-
hash = compute_uncompressed_hash(sdist)
164-
assert hash == package_simple_pyproject_ext.sdist_dated_hash
163+
sdist_hash = compute_uncompressed_hash(sdist)
164+
assert sdist_hash == package_simple_pyproject_ext.sdist_dated_hash
165165

166166

167167
@pytest.mark.compile

tests/test_pyproject_pep518.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def test_pep518_sdist(isolated, package_simple_pyproject_ext, tmp_path: Path):
4545
assert sdist.name == "cmake_example-0.0.1.tar.gz"
4646

4747
if not sys.platform.startswith(("win", "cygwin")):
48-
hash = compute_uncompressed_hash(sdist)
49-
assert hash == package_simple_pyproject_ext.sdist_hash
48+
sdist_hash = compute_uncompressed_hash(sdist)
49+
assert sdist_hash == package_simple_pyproject_ext.sdist_hash
5050

5151
with tarfile.open(sdist) as f:
5252
file_names = set(f.getnames())

tests/test_settings_overrides.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,14 @@ def test_skbuild_env_negative_bool(
446446

447447
@pytest.mark.parametrize("foo", ["true", "false"])
448448
@pytest.mark.parametrize("bar", ["true", "false"])
449-
@pytest.mark.parametrize("any", [True, False])
449+
@pytest.mark.parametrize("use_any", [True, False])
450450
def test_skbuild_env_bool_all_any(
451-
foo: str, bar: str, any: bool, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
451+
foo: str, bar: str, use_any: bool, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
452452
):
453453
monkeypatch.setenv("FOO", foo)
454454
monkeypatch.setenv("BAR", bar)
455455

456-
any_str = ".any" if any else ""
456+
any_str = ".any" if use_any else ""
457457
pyproject_toml = tmp_path / "pyproject.toml"
458458
pyproject_toml.write_text(
459459
dedent(
@@ -470,7 +470,9 @@ def test_skbuild_env_bool_all_any(
470470
settings_reader = SettingsReader.from_file(pyproject_toml)
471471
settings = settings_reader.settings
472472

473-
if (foo == "true" and bar == "true") or (any and (foo == "true" or bar == "true")):
473+
if (foo == "true" and bar == "true") or (
474+
use_any and (foo == "true" or bar == "true")
475+
):
474476
assert settings.sdist.cmake
475477
else:
476478
assert not settings.sdist.cmake

0 commit comments

Comments
 (0)