Skip to content

Commit dc50634

Browse files
Migrate to uv from requirements.txt
1 parent 4e70115 commit dc50634

File tree

10 files changed

+689
-51
lines changed

10 files changed

+689
-51
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ updates:
1313
schedule:
1414
interval: "daily"
1515

16-
# Maintain dependencies for pip
17-
- package-ecosystem: "pip"
16+
# Maintain dependencies for Python
17+
- package-ecosystem: "uv"
1818
directory: "/"
1919
schedule:
2020
interval: "daily"

.github/workflows/test.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ jobs:
2424
runs-on: ubuntu-latest
2525
steps:
2626
- uses: actions/checkout@v6
27-
- uses: actions/setup-python@v6
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v4
2829
with:
29-
python-version: ${{ env.DEFAULT_PYTHON }}
30-
cache: "pip"
31-
cache-dependency-path: requirements-dev.txt
32-
- name: Install dev dependencies
33-
run: pip install -r requirements-dev.txt
30+
enable-cache: true
31+
- name: Set up Python
32+
run: uv python install ${{ env.DEFAULT_PYTHON }}
33+
- name: Install dependencies
34+
run: uv sync --group dev
3435
- name: Restore pre-commit environment from cache
3536
id: cache-precommit
3637
uses: actions/[email protected]
@@ -40,11 +41,11 @@ jobs:
4041
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
4142
- name: Install pre-commit dependencies
4243
if: steps.cache-precommit.outputs.cache-hit != 'true'
43-
run: pre-commit install-hooks
44+
run: uv run pre-commit install-hooks
4445
- name: Run pre-commit
45-
run: pre-commit run --hook-stage manual --all-files --show-diff-on-failure
46+
run: uv run pre-commit run --hook-stage manual --all-files --show-diff-on-failure
4647
- name: Run unit-tests
47-
run: python -m pytest --cov --cov-config=tox.ini --cov-report=term --cov-report=html
48+
run: uv run pytest --cov --cov-config=tox.ini --cov-report=term --cov-report=html
4849
- uses: actions/upload-artifact@v6
4950
with:
5051
name: test-coverage

CONTAINER_DOCS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ contrast_verify:
4747
APP_NAME: $APP_NAME
4848
BUILD_NUMBER: $CI_COMMIT_SHORT_SHA
4949
script:
50-
- /usr/bin/env python3 /verify.py
50+
# Both approaches work for backward compatibility:
51+
- /usr/bin/env python3 /verify.py # Legacy approach (still supported)
52+
# - uv run python3 verify.py # New approach (optional)
5153
```
5254

5355
## Logging

Dockerfile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
FROM ghcr.io/astral-sh/uv:python3.13-alpine
22

3-
ENV VIRT_ENV=/opt/venv
4-
RUN uv venv $VIRT_ENV --python 3.13
5-
ENV PATH="$VIRT_ENV/bin:$PATH"
3+
WORKDIR /app
64

7-
ADD requirements.txt requirements.txt
8-
RUN uv pip install -r requirements.txt
5+
# Copy pyproject.toml and lock file for dependency installation
6+
COPY pyproject.toml uv.lock* ./
97

10-
ADD contrastverify contrastverify
11-
ADD version.py version.py
12-
ADD verify.py verify.py
8+
# Install dependencies and create the virtual environment
9+
RUN uv sync --frozen --no-dev
1310

14-
ENTRYPOINT ["/usr/bin/env", "python3", "/verify.py"]
11+
# Copy application code
12+
COPY contrastverify contrastverify
13+
COPY version.py version.py
14+
COPY verify.py verify.py
15+
COPY verify-wrapper.py verify-wrapper.py
16+
17+
# Install the local package in the already created environment
18+
RUN uv pip install --no-deps -e .
19+
20+
# Create backward compatibility symlink for GitLab users
21+
RUN ln -s /app/verify-wrapper.py /verify.py && chmod +x /verify.py
22+
23+
# Use the virtual environment directly instead of uv run
24+
ENTRYPOINT ["/app/.venv/bin/python3", "verify.py"]

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ A HTTP or HTTPS proxy may be used, by setting the environment variables `HTTP_PR
8080
If your environment requires custom certificate(s) to be trusted, these may be provided via the input `caFile` in pem format.
8181

8282
## Development Setup
83-
1. Run `python -m venv venv` to setup a virtual environment
84-
1. Run `. venv/bin/activate` to activate the virtual environment
85-
1. Run `pip install -r requirements-dev.txt` to install development dependencies (will also include app dependencies)
86-
1. Run `pre-commit install` to setup the pre-commit hook which handles formatting
83+
1. Install [uv](https://github.com/astral-sh/uv) if you haven't already: `curl -LsSf https://astral.sh/uv/install.sh | sh`
84+
1. Run `uv sync --group dev` to install all dependencies (including development dependencies)
85+
1. Run `uv run pre-commit install` to setup the pre-commit hook which handles formatting
86+
1. Use `uv run pytest` to run tests
87+
1. Use `uv run python verify.py` to run the application locally

pyproject.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[project]
2+
name = "contrast-verify-action"
3+
version = "1.0.0"
4+
description = "GitHub Action to verify an application by determining whether the application violates a job outcome policy or threshold of open vulnerabilities from Contrast Security"
5+
authors = [
6+
{name = "Josh Anderson", email = "[email protected]"}
7+
]
8+
requires-python = ">=3.13"
9+
dependencies = [
10+
"requests",
11+
"actions-toolkit",
12+
"certifi",
13+
"cryptography",
14+
]
15+
16+
[dependency-groups]
17+
dev = [
18+
"pytest",
19+
"pytest-cov",
20+
"responses",
21+
"pre-commit",
22+
"bump2version",
23+
]
24+
25+
[build-system]
26+
requires = ["hatchling"]
27+
build-backend = "hatchling.build"
28+
29+
[tool.hatch.build.targets.wheel]
30+
packages = ["contrastverify"]

requirements-dev.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)