Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add recurse-submodules option #36

Merged
merged 5 commits into from
Apr 20, 2024
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ To configure, these options are supported in your `pyproject.toml` file:
sdist-only = []
git-only = []
default-ignore = true
recurse-submodules = true
```

You can add `.gitignore` style lines here, and you can turn off the default
ignore list, which adds some default git-only files.

By default, check-sdist recursively scans the contents of Git submodules, but
you can disable this behavior (e.g. to support older Git versions that don't
have this capability).

### See also

- [check-manifest](https://github.com/mgedmin/check-manifest): A (currently)
Expand Down
7 changes: 4 additions & 3 deletions src/check_sdist/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ def compare(source_dir: Path, *, isolated: bool, verbose: bool = False) -> int:
conditions are true.
"""

sdist = sdist_files(source_dir, isolated) - {"PKG-INFO"}
git = git_files(source_dir)

config = {}
pyproject_toml = source_dir.joinpath("pyproject.toml")
with contextlib.suppress(FileNotFoundError), pyproject_toml.open("rb") as f:
Expand All @@ -39,6 +36,10 @@ def compare(source_dir: Path, *, isolated: bool, verbose: bool = False) -> int:
sdist_only_patterns = config.get("sdist-only", [])
git_only_patterns = config.get("git-only", [])
default_ignore = config.get("default-ignore", True)
recurse_submodules = config.get("recurse-submodules", True)

sdist = sdist_files(source_dir, isolated) - {"PKG-INFO"}
git = git_files(source_dir, recurse_submodules=recurse_submodules)

if default_ignore:
with resources.joinpath("default-ignore.txt").open("r", encoding="utf-8") as f:
Expand Down
4 changes: 3 additions & 1 deletion src/check_sdist/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from pathlib import Path


def git_files(source_dir: Path) -> frozenset[str]:
def git_files(source_dir: Path, recurse_submodules: bool = True) -> frozenset[str]:
"""Return the files that are tracked by git in the source directory."""

cmd = ["git", "ls-files", "--cached"]
if recurse_submodules:
cmd.append("--recurse-submodules")
return frozenset(
subprocess.run(
cmd,
Expand Down
4 changes: 4 additions & 0 deletions tests/downstream.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ ref = "0.17.0"
repo = "pybind/pybind11"
ref = "v2.10.3"
fail = 2

[[packages]]
repo = "isce-framework/snaphu-py"
ref = "v0.3.0"
12 changes: 9 additions & 3 deletions tests/test_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
)
def test_packages(repo, ref, fail, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
subprocess.run(
["git", "clone", f"https://github.com/{repo}", "--branch", ref], check=True
)
cmd = [
"git",
"clone",
f"https://github.com/{repo}",
"--branch",
ref,
"--recurse-submodules",
]
subprocess.run(cmd, check=True)
package_path = tmp_path / repo.split("/")[1]
assert compare(package_path, isolated=True) == fail
Loading