-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pip-install-dependency-groups installs dependency groups by calling `pip` in a subprocess. Use this to replace the rendered requirements data in `requirements/` by having `tox` invoke `pip-install-dependency-groups` as a pre-command.
- Loading branch information
Showing
11 changed files
with
100 additions
and
41 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,70 @@ | ||
#!/usr/bin/env python | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import subprocess | ||
import sys | ||
|
||
from dependency_groups import DependencyGroupResolver | ||
|
||
try: | ||
import tomllib | ||
except ImportError: | ||
try: | ||
import tomli as tomllib # type: ignore[no-redef] | ||
except ImportError: # pragma: no cover | ||
tomllib = None # type: ignore[assignment] | ||
|
||
|
||
def _invoke_pip(deps: list[str]) -> None: | ||
subprocess.check_call([sys.executable, "-m", "pip", "install"] + deps) | ||
|
||
|
||
def main(*, argv: list[str] | None = None) -> None: | ||
if not tomllib: | ||
print( | ||
"Usage error: dependency-groups CLI requires tomli or Python 3.11+", | ||
file=sys.stderr, | ||
) | ||
sys.exit(2) | ||
|
||
parser = argparse.ArgumentParser(description="Install Dependency Groups.") | ||
parser.add_argument( | ||
"DEPENDENCY_GROUP", nargs="+", help="The dependency groups to install." | ||
) | ||
parser.add_argument( | ||
"-f", | ||
"--pyproject-file", | ||
default="pyproject.toml", | ||
help="The pyproject.toml file. Defaults to trying in the current directory.", | ||
) | ||
args = parser.parse_args(argv if argv is not None else sys.argv[1:]) | ||
|
||
with open(args.pyproject_file, "rb") as fp: | ||
pyproject = tomllib.load(fp) | ||
dependency_groups_raw = pyproject.get("dependency-groups", {}) | ||
|
||
errors: list[str] = [] | ||
resolved: list[str] = [] | ||
try: | ||
resolver = DependencyGroupResolver(dependency_groups_raw) | ||
except (ValueError, TypeError) as e: | ||
errors.append(f"{type(e).__name__}: {e}") | ||
else: | ||
for groupname in args.DEPENDENCY_GROUP: | ||
try: | ||
resolved.extend(str(r) for r in resolver.resolve(groupname)) | ||
except (LookupError, ValueError, TypeError) as e: | ||
errors.append(f"{type(e).__name__}: {e}") | ||
|
||
if errors: | ||
print("errors encountered while examining dependency groups:") | ||
for msg in errors: | ||
print(f" {msg}") | ||
sys.exit(1) | ||
|
||
_invoke_pip(resolved) | ||
|
||
|
||
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