Skip to content

Commit

Permalink
Actually working min-deps job (#3337)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Nov 14, 2024
1 parent 02cb8c0 commit 0146f1a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# Python build files
__pycache__/
/src/scanpy/_version.py
/ci/scanpy-min-deps.txt
/dist/
/*-env/
/env-*/
Expand Down
35 changes: 28 additions & 7 deletions ci/scripts/min-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import argparse
import sys
from collections import deque
from contextlib import ExitStack
from pathlib import Path
from typing import TYPE_CHECKING

Expand All @@ -23,7 +24,7 @@
from packaging.version import Version

if TYPE_CHECKING:
from collections.abc import Generator, Iterable
from collections.abc import Generator, Iterable, Sequence


def min_dep(req: Requirement) -> Requirement:
Expand Down Expand Up @@ -75,12 +76,19 @@ def extract_min_deps(
yield min_dep(req)


def main():
class Args(argparse.Namespace):
path: Path
output: Path | None
extras: list[str]


def main(argv: Sequence[str] | None = None) -> None:
parser = argparse.ArgumentParser(
prog="min-deps",
description="""Parse a pyproject.toml file and output a list of minimum dependencies.
Output is directly passable to `pip install`.""",
description=(
"Parse a pyproject.toml file and output a list of minimum dependencies. "
"Output is optimized for `[uv] pip install` (see `-o`/`--output` for details)."
),
usage="pip install `python min-deps.py pyproject.toml`",
)
parser.add_argument(
Expand All @@ -89,8 +97,18 @@ def main():
parser.add_argument(
"--extras", type=str, nargs="*", default=(), help="extras to install"
)
parser.add_argument(
*("--output", "-o"),
type=Path,
default=None,
help=(
"output file (default: stdout). "
"Without this option, output is space-separated for direct passing to `pip install`. "
"With this option, output written to a file newline-separated file usable as `requirements.txt` or `constraints.txt`."
),
)

args = parser.parse_args()
args = parser.parse_args(argv, Args())

pyproject = tomllib.loads(args.path.read_text())

Expand All @@ -102,7 +120,10 @@ def main():

min_deps = extract_min_deps(deps, pyproject=pyproject)

print(" ".join(map(str, min_deps)))
sep = "\n" if args.output else " "
with ExitStack() as stack:
f = stack.enter_context(args.output.open("w")) if args.output else sys.stdout
print(sep.join(map(str, min_deps)), file=f)


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions ci/scripts/towncrier_automation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env python3
# /// script
# dependencies = [ "towncrier", "packaging" ]
# ///

from __future__ import annotations

import argparse
Expand Down
9 changes: 6 additions & 3 deletions hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ features = ["test", "dask-ml"]
extra-dependencies = ["ipykernel"]
overrides.matrix.deps.env-vars = [
{ if = ["pre"], key = "UV_PRERELEASE", value = "allow" },
{ if = ["min"], key = "UV_RESOLUTION", value = "lowest-direct" },
{ if = ["min"], key = "UV_CONSTRAINT", value = "ci/scanpy-min-deps.txt" },
]
overrides.matrix.deps.pre-install-commands = [
{ if = ["min"], value = "uv run ci/scripts/min-deps.py pyproject.toml -o ci/scanpy-min-deps.txt" },
]
overrides.matrix.deps.python = [
{ if = ["min"] , value = "3.10" },
{ if = ["min"], value = "3.10" },
{ if = ["stable", "full", "pre"], value = "3.12" },
]
overrides.matrix.deps.features = [
{ if = ["full"] , value = "test-full" },
{ if = ["full"], value = "test-full" },
]

[[envs.hatch-test.matrix]]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dependencies = [
"pandas >=1.5",
"scipy>=1.8",
"seaborn>=0.13",
"h5py>=3.6",
"h5py>=3.7",
"tqdm",
"scikit-learn>=1.1",
"statsmodels>=0.13",
Expand Down

0 comments on commit 0146f1a

Please sign in to comment.