Skip to content

Commit 5acc15d

Browse files
committed
feat: add --installer option
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 10bcc37 commit 5acc15d

File tree

6 files changed

+84
-27
lines changed

6 files changed

+84
-27
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ jobs:
4949
with:
5050
python-version: ${{ matrix.python-version }}
5151

52+
- uses: yezz123/setup-uv@v4
53+
5254
- name: Install package
53-
run: python -m pip install .[test]
55+
run: uv pip install -e.[test] --system
5456

5557
- name: Test package
56-
run: python -m pytest -ra --cov=check-sdist
58+
run: pytest -ra --cov=check-sdist
5759

5860
- name: Upload coverage report
5961
uses: codecov/codecov-action@v4

.pre-commit-config.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ ci:
33
autofix_commit_msg: "style: pre-commit fixes"
44

55
repos:
6-
- repo: https://github.com/psf/black-pre-commit-mirror
7-
rev: "24.4.0"
8-
hooks:
9-
- id: black-jupyter
10-
116
- repo: https://github.com/pre-commit/pre-commit-hooks
127
rev: "v4.6.0"
138
hooks:
@@ -43,6 +38,7 @@ repos:
4338
hooks:
4439
- id: ruff
4540
args: ["--fix", "--show-fixes"]
41+
- id: ruff-format
4642

4743
- repo: https://github.com/pre-commit/mirrors-mypy
4844
rev: "v1.9.0"

noxfile.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import nox
44

5-
nox.options.sessions = ["lint", "pylint", "tests"]
5+
nox.needs_version = ">=2024.4.15"
6+
nox.options.default_venv_backend = "uv|virtualenv"
67

78

89
@nox.session
@@ -21,7 +22,7 @@ def pylint(session: nox.Session) -> None:
2122
"""
2223
# This needs to be installed into the package environment, and is slower
2324
# than a pre-commit check
24-
session.install(".", "pylint")
25+
session.install("-e.", "pylint")
2526
session.run("pylint", "src", *session.posargs)
2627

2728

@@ -30,7 +31,7 @@ def tests(session: nox.Session) -> None:
3031
"""
3132
Run the unit and regular tests.
3233
"""
33-
session.install(".[test]")
34+
session.install("-e.[test]")
3435
session.run("pytest", *session.posargs)
3536

3637

@@ -44,7 +45,7 @@ def coverage(session: nox.Session) -> None:
4445
tests(session)
4546

4647

47-
@nox.session
48+
@nox.session(default=False)
4849
def build(session: nox.Session) -> None:
4950
"""
5051
Build an SDist and wheel.

pyproject.toml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ classifiers = [
2727
]
2828
dynamic = ["version"]
2929
dependencies = [
30-
"build",
30+
"build >=1.2",
31+
"importlib-resources; python_version<'3.9'",
3132
"pathspec",
3233
"tomli; python_version<'3.11'",
33-
"importlib-resources; python_version<'3.9'",
3434
]
3535
keywords = ["sdist", "packaging", "lint"]
3636

@@ -43,6 +43,9 @@ dev = [
4343
"pytest >=6",
4444
"pytest-cov >=3",
4545
]
46+
uv = [
47+
"uv",
48+
]
4649

4750
[project.urls]
4851
Homepage = "https://github.com/henryiii/check-sdist"
@@ -89,8 +92,10 @@ disallow_incomplete_defs = true
8992

9093

9194
[tool.ruff]
92-
select = [
93-
"E", "F", "W", # flake8
95+
src = ["src"]
96+
97+
[tool.ruff.lint]
98+
extend-select = [
9499
"B", # flake8-bugbear
95100
"I", # isort
96101
"ARG", # flake8-unused-arguments
@@ -111,13 +116,10 @@ select = [
111116
"YTT", # flake8-2020
112117
"EXE", # flake8-executable
113118
]
114-
extend-ignore = [
115-
"PLR", # Design related pylint codes
119+
ignore = [
120+
"PLR09", # Design related pylint codes
116121
"E501", # Line too long
117-
]
118-
src = ["src"]
119-
unfixable = [
120-
"F841", # Removes unused variables
122+
"ISC001", # Conflicts with formatter
121123
]
122124
flake8-unused-arguments.ignore-variadic-names = true
123125
isort.required-imports = ["from __future__ import annotations"]

src/check_sdist/__main__.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import argparse
44
import contextlib
5+
import importlib.util
6+
import shutil
57
from collections.abc import Sequence
68
from pathlib import Path
9+
from typing import Literal
710

811
import pathspec
912

@@ -15,7 +18,34 @@
1518
from .sdist import sdist_files
1619

1720

18-
def compare(source_dir: Path, *, isolated: bool, verbose: bool = False) -> int:
21+
def select_installer(
22+
installer: Literal["pip", "uv", "uv|pip"], # type: ignore[name-defined]
23+
) -> Literal["uv", "pip"]:
24+
"""
25+
Select uv, pip, or uv if available, then pip ("uv|pip"). Returns uv, pip,
26+
or throws an error if uv was required and not available.
27+
"""
28+
if "uv" in installer:
29+
if importlib.util.find_spec("uv") is not None:
30+
return "uv"
31+
32+
if shutil.which("uv") is not None:
33+
return "uv"
34+
35+
if installer == "uv":
36+
msg = "Can't find uv"
37+
raise ImportError(msg)
38+
39+
return "pip"
40+
41+
42+
def compare(
43+
source_dir: Path,
44+
*,
45+
isolated: bool,
46+
verbose: bool = False,
47+
installer: Literal["uv", "pip", "uv|pip"] = "uv|pip", # type: ignore[name-defined]
48+
) -> int:
1949
"""
2050
Compare the files in the SDist with the files tracked by git.
2151
@@ -27,6 +57,8 @@ def compare(source_dir: Path, *, isolated: bool, verbose: bool = False) -> int:
2757
conditions are true.
2858
"""
2959

60+
installer = select_installer(installer)
61+
3062
config = {}
3163
pyproject_toml = source_dir.joinpath("pyproject.toml")
3264
with contextlib.suppress(FileNotFoundError), pyproject_toml.open("rb") as f:
@@ -38,7 +70,9 @@ def compare(source_dir: Path, *, isolated: bool, verbose: bool = False) -> int:
3870
default_ignore = config.get("default-ignore", True)
3971
recurse_submodules = config.get("recurse-submodules", True)
4072

41-
sdist = sdist_files(source_dir, isolated) - {"PKG-INFO"}
73+
sdist = sdist_files(source_dir, isolated=isolated, installer=installer) - {
74+
"PKG-INFO"
75+
}
4276
git = git_files(source_dir, recurse_submodules=recurse_submodules)
4377

4478
if default_ignore:
@@ -100,14 +134,25 @@ def main(sys_args: Sequence[str] | None = None, /) -> None:
100134
action="store_true",
101135
help="Print out SDist contents too",
102136
)
137+
parser.add_argument(
138+
"--installer",
139+
choices={"uv", "pip", "uv|pip"},
140+
default="uv|pip",
141+
help="Tool to use when installing packages for making the SDist",
142+
)
103143
args = parser.parse_args(sys_args)
104144

105145
with contextlib.ExitStack() as stack:
106146
if args.inject_junk:
107147
stack.enter_context(inject_junk_files(args.source_dir))
108148

109149
raise SystemExit(
110-
compare(args.source_dir, isolated=not args.no_isolation, verbose=args.verbose)
150+
compare(
151+
args.source_dir,
152+
isolated=not args.no_isolation,
153+
verbose=args.verbose,
154+
installer=args.installer,
155+
)
111156
)
112157

113158

src/check_sdist/sdist.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@
55
import tarfile
66
import tempfile
77
from pathlib import Path
8+
from typing import Literal
89

910

10-
def sdist_files(source_dir: Path, isolated: bool) -> frozenset[str]:
11+
def sdist_files(
12+
source_dir: Path, *, isolated: bool, installer: Literal["uv", "pip"]
13+
) -> frozenset[str]:
1114
"""Return the files that would be (are) placed in the SDist."""
1215

1316
with tempfile.TemporaryDirectory() as outdir:
14-
cmd = [sys.executable, "-m", "build", "--sdist", "--outdir", outdir]
17+
cmd = [
18+
sys.executable,
19+
"-m",
20+
"build",
21+
"--sdist",
22+
"--outdir",
23+
outdir,
24+
f"--installer={installer}",
25+
]
1526
if not isolated:
1627
cmd.append("--no-isolation")
1728
subprocess.run(cmd, check=True, cwd=source_dir)
@@ -31,4 +42,4 @@ def sdist_files(source_dir: Path, isolated: bool) -> frozenset[str]:
3142

3243

3344
if __name__ == "__main__":
34-
print(*sorted(sdist_files(Path.cwd(), True)), sep="\n")
45+
print(*sorted(sdist_files(Path.cwd(), isolated=True, installer="pip")), sep="\n")

0 commit comments

Comments
 (0)