Skip to content

Commit

Permalink
Add nox session to pip-compile requirements (#229)
Browse files Browse the repository at this point in the history
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
Co-authored-by: Maxwell G <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2024
1 parent 4947d22 commit d0b1ab7
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .pip-tools.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.pip-tools]
resolver = "backtracking"
allow-unsafe = true
strip-extras = true
quiet = true
47 changes: 44 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
from pathlib import Path

import nox

@nox.session(python=["3.11"]) # The python version should match the readthedocs configuration.
requirements_directory = Path("requirements").resolve()

requirements_files = [
requirements_input_file_path.stem
for requirements_input_file_path in requirements_directory.glob("*.in")
]


@nox.session(name="pip-compile", python=["3.11"])
@nox.parametrize(["req"], arg_values_list=requirements_files, ids=requirements_files)
def pip_compile(session: nox.Session, req: str):
"""Generate lock files from input files or upgrade packages in lock files."""
# fmt: off
session.install(
"-r", str(requirements_directory / "pip-tools.in"),
"-c", str(requirements_directory / "pip-tools.txt"),
)
# fmt: on

# Use --upgrade by default unless a user passes -P.
upgrade_related_cli_flags = ("-P", "--upgrade-package", "--no-upgrade")
has_upgrade_related_cli_flags = any(
arg.startswith(upgrade_related_cli_flags) for arg in session.posargs
)
injected_extra_cli_args = () if has_upgrade_related_cli_flags else ("--upgrade",)

session.run(
"pip-compile",
"--output-file",
str(requirements_directory / f"{req}.txt"),
*session.posargs,
*injected_extra_cli_args,
str(requirements_directory / f"{req}.in"),
)


@nox.session(python=["3.11"]) # The python version should match the readthedocs configuration.
def build(session: nox.Session):
"""Generate HTML files for the Ansible docsite."""
# fmt: off
session.install(
"-r", "requirements.in",
"-c", "requirements.txt",
"-r", str(requirements_directory / "requirements.in"),
"-c", str(requirements_directory / "requirements.txt"),
)
# fmt: on
session.run("python", "-I", "build.py", *session.posargs)
1 change: 1 addition & 0 deletions requirements/pip-tools.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip-tools >= 7 # .pip-tools.toml was introduced in v6.14
26 changes: 26 additions & 0 deletions requirements/pip-tools.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --allow-unsafe --output-file=requirements/pip-tools.txt --strip-extras requirements/pip-tools.in
#
build==1.0.3
# via pip-tools
click==8.1.7
# via pip-tools
packaging==23.2
# via build
pip-tools==7.4.0
# via -r requirements/pip-tools.in
pyproject-hooks==1.0.0
# via
# build
# pip-tools
wheel==0.42.0
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
pip==24.0
# via pip-tools
setuptools==69.1.1
# via pip-tools
File renamed without changes.
File renamed without changes.

0 comments on commit d0b1ab7

Please sign in to comment.