Skip to content

Commit fbab3d0

Browse files
authored
Merge pull request #28 from python-project-templates/fix-ruff-lint
Fix Ruff lint violations
2 parents b8ab1a9 + 2be96b4 commit fbab3d0

4 files changed

Lines changed: 19 additions & 28 deletions

File tree

‎check_dist/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__version__ = "0.1.5"
22

3-
from ._core import ( # noqa: F401
3+
from ._core import (
44
CheckDistError,
55
check_absent,
66
check_dist,

‎check_dist/_core.py‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@
99
import sys
1010
import tarfile
1111
import tempfile
12+
import tomllib
1213
import zipfile
1314
from pathlib import Path
1415

1516
import yaml
1617

17-
if sys.version_info >= (3, 11):
18-
import tomllib
19-
else:
20-
import tomli as tomllib
21-
2218

2319
class CheckDistError(Exception):
2420
"""Error raised when distribution checks fail."""
@@ -351,7 +347,7 @@ def build_dists(source_dir: str, output_dir: str, *, no_isolation: bool = False)
351347
cmd.insert(-1, "--no-isolation")
352348
cmd.append(source_dir)
353349

354-
result = subprocess.run(cmd, capture_output=True, text=True)
350+
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
355351
if result.returncode == 0:
356352
return warnings
357353

@@ -364,7 +360,7 @@ def build_dists(source_dir: str, output_dir: str, *, no_isolation: bool = False)
364360
if no_isolation:
365361
cmd.insert(-1, "--no-isolation")
366362
cmd.append(source_dir)
367-
r = subprocess.run(cmd, capture_output=True, text=True)
363+
r = subprocess.run(cmd, capture_output=True, text=True, check=False)
368364
if r.returncode == 0:
369365
built_any = True
370366
else:
@@ -442,6 +438,7 @@ def get_vcs_files(source_dir: str) -> list[str]:
442438
capture_output=True,
443439
text=True,
444440
cwd=source_dir,
441+
check=False,
445442
)
446443
except FileNotFoundError:
447444
raise CheckDistError("git not found – only git is currently supported for VCS tracking")
@@ -472,10 +469,7 @@ def matches_pattern(filepath: str, pattern: str) -> bool:
472469

473470
if fnmatch.fnmatch(filepath, translated):
474471
return True
475-
if fnmatch.fnmatch(os.path.basename(filepath), translated):
476-
return True
477-
478-
return False
472+
return fnmatch.fnmatch(os.path.basename(filepath), translated)
479473

480474

481475
def _matches_hatch_pattern(filepath: str, pattern: str) -> bool:
@@ -495,9 +489,7 @@ def _matches_hatch_pattern(filepath: str, pattern: str) -> bool:
495489
return True
496490
if fnmatch.fnmatch(filepath, pat):
497491
return True
498-
if fnmatch.fnmatch(os.path.basename(filepath), pat):
499-
return True
500-
return False
492+
return fnmatch.fnmatch(os.path.basename(filepath), pat)
501493

502494

503495
def check_present(files: list[str], patterns: list[str], dist_type: str) -> list[str]:

‎check_dist/tests/test_all.py‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import textwrap
1010
import zipfile
1111
from pathlib import Path
12+
from typing import ClassVar
1213
from unittest.mock import patch
1314

1415
import pytest
@@ -43,9 +44,7 @@
4344
class TestTranslateExtension:
4445
def test_no_change_on_native(self):
4546
"""No translation when extension is already native."""
46-
if sys.platform == "linux":
47-
assert translate_extension("foo.so") == "foo.so"
48-
elif sys.platform == "darwin":
47+
if sys.platform in ("linux", "darwin"):
4948
assert translate_extension("foo.so") == "foo.so"
5049
elif sys.platform == "win32":
5150
assert translate_extension("foo.pyd") == "foo.pyd"
@@ -129,7 +128,7 @@ def test_nested_directory_pattern(self):
129128

130129

131130
class TestCheckPresent:
132-
FILES = [
131+
FILES: ClassVar[list[str]] = [
133132
"check_dist/__init__.py",
134133
"check_dist/_core.py",
135134
"LICENSE",
@@ -170,7 +169,7 @@ def test_cross_platform_missing(self, _mock):
170169

171170

172171
class TestCheckAbsent:
173-
FILES = [
172+
FILES: ClassVar[list[str]] = [
174173
"check_dist/__init__.py",
175174
"Makefile",
176175
".github/workflows/ci.yml",
@@ -357,7 +356,7 @@ class TestSdistExpectedFiles:
357356
"""Covers hatch semantics: packages, include, exclude, only-include,
358357
force-include, sources, and their interactions."""
359358

360-
VCS = [
359+
VCS: ClassVar[list[str]] = [
361360
"pkg/__init__.py",
362361
"pkg/core.py",
363362
"rust/src/lib.rs",
@@ -534,7 +533,7 @@ def test_empty_config(self):
534533
class TestFilterExtrasByHatch:
535534
"""Verify that copier-derived extras are trimmed to match hatch config."""
536535

537-
EXTRAS = ["rust", "src", "Cargo.toml", "Cargo.lock", "target"]
536+
EXTRAS: ClassVar[list[str]] = ["rust", "src", "Cargo.toml", "Cargo.lock", "target"]
538537

539538
def test_no_hatch_config(self):
540539
assert _filter_extras_by_hatch(self.EXTRAS, {}) == self.EXTRAS
@@ -940,8 +939,8 @@ class TestGetVcsFiles:
940939
def test_in_git_repo(self, tmp_path):
941940
"""Integration test: create a real tiny git repo."""
942941
subprocess.run(["git", "init", str(tmp_path)], capture_output=True, check=True)
943-
subprocess.run(["git", "config", "user.email", "test@test.com"], cwd=str(tmp_path), capture_output=True)
944-
subprocess.run(["git", "config", "user.name", "Test"], cwd=str(tmp_path), capture_output=True)
942+
subprocess.run(["git", "config", "user.email", "test@test.com"], cwd=str(tmp_path), capture_output=True, check=False)
943+
subprocess.run(["git", "config", "user.name", "Test"], cwd=str(tmp_path), capture_output=True, check=False)
945944
(tmp_path / "hello.py").write_text("print('hi')\n")
946945
subprocess.run(["git", "add", "hello.py"], cwd=str(tmp_path), capture_output=True, check=True)
947946
subprocess.run(["git", "commit", "-m", "init"], cwd=str(tmp_path), capture_output=True, check=True)
@@ -992,8 +991,8 @@ def _make_project(tmp_path: Path, *, extra_files: dict[str, str] | None = None)
992991

993992
# Set up a git repo so VCS checks work
994993
subprocess.run(["git", "init", str(proj)], capture_output=True, check=True)
995-
subprocess.run(["git", "config", "user.email", "t@t.com"], cwd=str(proj), capture_output=True)
996-
subprocess.run(["git", "config", "user.name", "T"], cwd=str(proj), capture_output=True)
994+
subprocess.run(["git", "config", "user.email", "t@t.com"], cwd=str(proj), capture_output=True, check=False)
995+
subprocess.run(["git", "config", "user.name", "T"], cwd=str(proj), capture_output=True, check=False)
997996
subprocess.run(["git", "add", "."], cwd=str(proj), capture_output=True, check=True)
998997
subprocess.run(["git", "commit", "-m", "init"], cwd=str(proj), capture_output=True, check=True)
999998
return proj
@@ -1027,7 +1026,7 @@ def test_missing_present_pattern(self, tmp_path):
10271026
@pytest.mark.slow
10281027
def test_verbose_lists_files(self, tmp_path):
10291028
proj = _make_project(tmp_path)
1030-
success, messages = check_dist(str(proj), verbose=True)
1029+
_success, messages = check_dist(str(proj), verbose=True)
10311030
combined = "\n".join(messages)
10321031
# Verbose mode should list individual files
10331032
assert "mypkg/__init__.py" in combined
@@ -1039,6 +1038,7 @@ def test_help(self):
10391038
[sys.executable, "-m", "check_dist._cli", "--help"],
10401039
capture_output=True,
10411040
text=True,
1041+
check=False,
10421042
)
10431043
assert result.returncode == 0
10441044
assert "check-dist" in result.stdout.lower() or "Check Python" in result.stdout

‎pyproject.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ classifiers = [
3030

3131
dependencies = [
3232
"pyyaml",
33-
"tomli",
3433
]
3534

3635
[project.optional-dependencies]

0 commit comments

Comments
 (0)