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

Pip compile check mode #1950

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions .github/workflows/pip-compile-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ name: "Refresh dev dependencies"
labels:
required: false
type: string
push:
branches:
- devel
paths:
- .github/workflows/reusable-pip-compile.yml
- ".github/workflows/pip-compile-dev.yml"
- "tests/*.in"

jobs:
refresh:
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/pip-compile-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ name: "Refresh docs build dependencies"
labels:
required: false
type: string
push:
branches:
- devel
paths:
- .github/workflows/reusable-pip-compile.yml
- ".github/workflows/pip-compile-docs.yml"
- "tests/*.in"

jobs:
refresh:
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/reusable-nox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
fail-fast: false
matrix:
include:
# Inputs:
# session: name of session
# python-versions: comma-separated list of Python versions to install
# extra-args (optional): extra arguments to pass to nox session.
- session: static
python-versions: "3.11"
- session: formatters_check
Expand All @@ -25,6 +29,9 @@ jobs:
python-versions: "3.11"
- session: "actionlint"
python-versions: "3.11"
- session: "pip-compile"
extra-args: "--check"
python-versions: "3.11"
name: "Run nox ${{ matrix.session }} session"
steps:
- name: Check out repo
Expand All @@ -38,4 +45,6 @@ jobs:
nox -e clone-core
- name: "Run nox -e ${{ matrix.session }}"
run: |
nox -e "${{ matrix.session }}"
# Using GHA expression interpolation is fine here,
# as we control all the inputs.
nox -e "${{ matrix.session }}" -- ${{ matrix.extra-args }}
12 changes: 11 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ def pip_compile(session: nox.Session, req: str):

# Use --upgrade by default unless a user passes -P.
args = list(session.posargs)
if not any(

# Support a custom --check flag to fail if pip-compile made any changes
# so we can check that that lockfiles are in sync with the input (.in) files.
check_mode = "--check" in args
if check_mode:
# Remove from args, as pip-compile doesn't actually support --check.
args.remove("--check")
oraNod marked this conversation as resolved.
Show resolved Hide resolved
elif not any(
arg.startswith(("-P", "--upgrade-package", "--no-upgrade")) for arg in args
):
args.append("--upgrade")
Expand All @@ -176,6 +183,9 @@ def pip_compile(session: nox.Session, req: str):
)
# fmt: on

if check_mode and session.run("git", "diff", "tests", silent=True, external=True):
session.error("Check mode: files were changed")


@nox.session(name="clone-core")
def clone_core(session: nox.Session):
Expand Down