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

Add update-lock.py script to compile requirements using pip-tools #37463

Closed
wants to merge 6 commits into from
Closed
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
57 changes: 57 additions & 0 deletions tools/update-lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# pyright: strict
import argparse
import subprocess
from pathlib import Path

import toml


def compile_requirements(pyproject_file: Path, groups: dict[str, list[str]]) -> None:
requirements_dir = pyproject_file.parent / "requirements"
if not requirements_dir.exists():
requirements_dir.mkdir()
subprocess.run(
[
"pip-compile",
"-v",
"--upgrade",
"--no-build-isolation",
"--output-file",
str(requirements_dir / "requirements.txt"),
pyproject_file,
],
check=True,
)
for group in groups:
requirements_file = requirements_dir / f"{group}-requirements.txt"
requirements_in_file = requirements_dir / f"{group}.in"
with requirements_in_file.open("w") as f:
f.write("\n".join(groups[group]))
subprocess.run(
[
"pip-compile",
"-v",
"--upgrade",
"--no-build-isolation",
"--output-file",
str(requirements_file),
str(requirements_in_file),
],
check=True,
)


parser = argparse.ArgumentParser(
description="Update lock files under requirements using pip-tools compile."
)
parser.add_argument(
"sourcedir", help="The source directory of the pyproject.toml file."
)
args = parser.parse_args()

pyproject_file = Path(args.sourcedir) / "pyproject.toml"
with pyproject_file.open("r") as f:
pyproject = toml.load(f)

groups = pyproject.get("dependency-groups", {})
compile_requirements(pyproject_file, groups)
Loading