-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start * Bump h5py requirement * Bump numpy, disable cuda * Attempt running on CI * Missing dependency * Bump dask * Version constrain a pandas warning * Ignore warnings for old version of h5py * Skip doctest that changes between pandas versions * Apply suggestions from code review Co-authored-by: Philipp A. <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * release note * remove unused script * Update min-deps script * Update CI job * coverage * Release note --------- Co-authored-by: Philipp A. <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b9f346c
commit 0de445a
Showing
8 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!python3 | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import sys | ||
from collections import deque | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
if sys.version_info >= (3, 11): | ||
import tomllib | ||
else: | ||
import tomli as tomllib | ||
|
||
from packaging.requirements import Requirement | ||
from packaging.version import Version | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Generator, Iterable | ||
|
||
|
||
def min_dep(req: Requirement) -> Requirement: | ||
""" | ||
Given a requirement, return the minimum version specifier. | ||
Example | ||
------- | ||
>>> min_dep(Requirement("numpy>=1.0")) | ||
"numpy==1.0" | ||
""" | ||
req_name = req.name | ||
if req.extras: | ||
req_name = f"{req_name}[{','.join(req.extras)}]" | ||
|
||
if not req.specifier: | ||
return Requirement(req_name) | ||
|
||
min_version = Version("0.0.0.a1") | ||
for spec in req.specifier: | ||
if spec.operator in [">", ">=", "~="]: | ||
min_version = max(min_version, Version(spec.version)) | ||
elif spec.operator == "==": | ||
min_version = Version(spec.version) | ||
|
||
return Requirement(f"{req_name}=={min_version}.*") | ||
|
||
|
||
def extract_min_deps( | ||
dependencies: Iterable[Requirement], *, pyproject | ||
) -> Generator[Requirement, None, None]: | ||
dependencies = deque(dependencies) # We'll be mutating this | ||
project_name = pyproject["project"]["name"] | ||
|
||
while len(dependencies) > 0: | ||
req = dependencies.pop() | ||
|
||
# If we are referring to other optional dependency lists, resolve them | ||
if req.name == project_name: | ||
assert req.extras, f"Project included itself as dependency, without specifying extras: {req}" | ||
for extra in req.extras: | ||
extra_deps = pyproject["project"]["optional-dependencies"][extra] | ||
dependencies += map(Requirement, extra_deps) | ||
else: | ||
yield min_dep(req) | ||
|
||
|
||
def main(): | ||
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`.""", | ||
usage="pip install `python min-deps.py pyproject.toml`", | ||
) | ||
parser.add_argument( | ||
"path", type=Path, help="pyproject.toml to parse minimum dependencies from" | ||
) | ||
parser.add_argument( | ||
"--extras", type=str, nargs="*", default=(), help="extras to install" | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
pyproject = tomllib.loads(args.path.read_text()) | ||
|
||
project_name = pyproject["project"]["name"] | ||
deps = [ | ||
*map(Requirement, pyproject["project"]["dependencies"]), | ||
*(Requirement(f"{project_name}[{extra}]") for extra in args.extras), | ||
] | ||
|
||
min_deps = extract_min_deps(deps, pyproject=pyproject) | ||
|
||
print(" ".join(map(str, min_deps))) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters