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
2 changes: 1 addition & 1 deletion check_dist/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__version__ = "0.1.5"

from ._core import ( # noqa: F401
from ._core import (
CheckDistError,
check_absent,
check_dist,
Expand Down
20 changes: 6 additions & 14 deletions check_dist/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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]:
Expand Down
24 changes: 12 additions & 12 deletions check_dist/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import textwrap
import zipfile
from pathlib import Path
from typing import ClassVar
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ classifiers = [

dependencies = [
"pyyaml",
"tomli",
]

[project.optional-dependencies]
Expand Down
Loading