diff --git a/check_dist/__init__.py b/check_dist/__init__.py index 6b62a79..473f7c3 100644 --- a/check_dist/__init__.py +++ b/check_dist/__init__.py @@ -1,6 +1,6 @@ __version__ = "0.1.5" -from ._core import ( # noqa: F401 +from ._core import ( CheckDistError, check_absent, check_dist, diff --git a/check_dist/_core.py b/check_dist/_core.py index 3ceda52..03c938c 100644 --- a/check_dist/_core.py +++ b/check_dist/_core.py @@ -9,16 +9,12 @@ import sys import tarfile import tempfile +import tomllib import zipfile from pathlib import Path import yaml -if sys.version_info >= (3, 11): - import tomllib -else: - import tomli as tomllib - class CheckDistError(Exception): """Error raised when distribution checks fail.""" @@ -351,7 +347,7 @@ def build_dists(source_dir: str, output_dir: str, *, no_isolation: bool = False) cmd.insert(-1, "--no-isolation") cmd.append(source_dir) - result = subprocess.run(cmd, capture_output=True, text=True) + result = subprocess.run(cmd, capture_output=True, text=True, check=False) if result.returncode == 0: return warnings @@ -364,7 +360,7 @@ def build_dists(source_dir: str, output_dir: str, *, no_isolation: bool = False) if no_isolation: cmd.insert(-1, "--no-isolation") cmd.append(source_dir) - r = subprocess.run(cmd, capture_output=True, text=True) + r = subprocess.run(cmd, capture_output=True, text=True, check=False) if r.returncode == 0: built_any = True else: @@ -442,6 +438,7 @@ def get_vcs_files(source_dir: str) -> list[str]: capture_output=True, text=True, cwd=source_dir, + check=False, ) except FileNotFoundError: 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: if fnmatch.fnmatch(filepath, translated): return True - if fnmatch.fnmatch(os.path.basename(filepath), translated): - return True - - return False + return fnmatch.fnmatch(os.path.basename(filepath), translated) def _matches_hatch_pattern(filepath: str, pattern: str) -> bool: @@ -495,9 +489,7 @@ def _matches_hatch_pattern(filepath: str, pattern: str) -> bool: return True if fnmatch.fnmatch(filepath, pat): return True - if fnmatch.fnmatch(os.path.basename(filepath), pat): - return True - return False + return fnmatch.fnmatch(os.path.basename(filepath), pat) def check_present(files: list[str], patterns: list[str], dist_type: str) -> list[str]: diff --git a/check_dist/tests/test_all.py b/check_dist/tests/test_all.py index ddbe55a..3c1d8ab 100644 --- a/check_dist/tests/test_all.py +++ b/check_dist/tests/test_all.py @@ -9,6 +9,7 @@ import textwrap import zipfile from pathlib import Path +from typing import ClassVar from unittest.mock import patch import pytest @@ -43,9 +44,7 @@ class TestTranslateExtension: def test_no_change_on_native(self): """No translation when extension is already native.""" - if sys.platform == "linux": - assert translate_extension("foo.so") == "foo.so" - elif sys.platform == "darwin": + if sys.platform in ("linux", "darwin"): assert translate_extension("foo.so") == "foo.so" elif sys.platform == "win32": assert translate_extension("foo.pyd") == "foo.pyd" @@ -129,7 +128,7 @@ def test_nested_directory_pattern(self): class TestCheckPresent: - FILES = [ + FILES: ClassVar[list[str]] = [ "check_dist/__init__.py", "check_dist/_core.py", "LICENSE", @@ -170,7 +169,7 @@ def test_cross_platform_missing(self, _mock): class TestCheckAbsent: - FILES = [ + FILES: ClassVar[list[str]] = [ "check_dist/__init__.py", "Makefile", ".github/workflows/ci.yml", @@ -357,7 +356,7 @@ class TestSdistExpectedFiles: """Covers hatch semantics: packages, include, exclude, only-include, force-include, sources, and their interactions.""" - VCS = [ + VCS: ClassVar[list[str]] = [ "pkg/__init__.py", "pkg/core.py", "rust/src/lib.rs", @@ -534,7 +533,7 @@ def test_empty_config(self): class TestFilterExtrasByHatch: """Verify that copier-derived extras are trimmed to match hatch config.""" - EXTRAS = ["rust", "src", "Cargo.toml", "Cargo.lock", "target"] + EXTRAS: ClassVar[list[str]] = ["rust", "src", "Cargo.toml", "Cargo.lock", "target"] def test_no_hatch_config(self): assert _filter_extras_by_hatch(self.EXTRAS, {}) == self.EXTRAS @@ -940,8 +939,8 @@ class TestGetVcsFiles: def test_in_git_repo(self, tmp_path): """Integration test: create a real tiny git repo.""" subprocess.run(["git", "init", str(tmp_path)], capture_output=True, check=True) - subprocess.run(["git", "config", "user.email", "test@test.com"], cwd=str(tmp_path), capture_output=True) - subprocess.run(["git", "config", "user.name", "Test"], cwd=str(tmp_path), capture_output=True) + subprocess.run(["git", "config", "user.email", "test@test.com"], cwd=str(tmp_path), capture_output=True, check=False) + subprocess.run(["git", "config", "user.name", "Test"], cwd=str(tmp_path), capture_output=True, check=False) (tmp_path / "hello.py").write_text("print('hi')\n") subprocess.run(["git", "add", "hello.py"], cwd=str(tmp_path), capture_output=True, check=True) 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) # Set up a git repo so VCS checks work subprocess.run(["git", "init", str(proj)], capture_output=True, check=True) - subprocess.run(["git", "config", "user.email", "t@t.com"], cwd=str(proj), capture_output=True) - subprocess.run(["git", "config", "user.name", "T"], cwd=str(proj), capture_output=True) + subprocess.run(["git", "config", "user.email", "t@t.com"], cwd=str(proj), capture_output=True, check=False) + subprocess.run(["git", "config", "user.name", "T"], cwd=str(proj), capture_output=True, check=False) subprocess.run(["git", "add", "."], cwd=str(proj), capture_output=True, check=True) subprocess.run(["git", "commit", "-m", "init"], cwd=str(proj), capture_output=True, check=True) return proj @@ -1027,7 +1026,7 @@ def test_missing_present_pattern(self, tmp_path): @pytest.mark.slow def test_verbose_lists_files(self, tmp_path): proj = _make_project(tmp_path) - success, messages = check_dist(str(proj), verbose=True) + _success, messages = check_dist(str(proj), verbose=True) combined = "\n".join(messages) # Verbose mode should list individual files assert "mypkg/__init__.py" in combined @@ -1039,6 +1038,7 @@ def test_help(self): [sys.executable, "-m", "check_dist._cli", "--help"], capture_output=True, text=True, + check=False, ) assert result.returncode == 0 assert "check-dist" in result.stdout.lower() or "Check Python" in result.stdout diff --git a/pyproject.toml b/pyproject.toml index 6f7b65a..030768a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,6 @@ classifiers = [ dependencies = [ "pyyaml", - "tomli", ] [project.optional-dependencies]