Skip to content
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
9 changes: 9 additions & 0 deletions .github/actions/setup-uv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Set up uv
description: Install the lowest uv version allowed by the root pyproject.toml.
runs:
using: composite
steps:
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
version-file: pyproject.toml
resolution-strategy: lowest
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ updates:
patterns:
- "*"
# Compose manifests live at the root; Dockerfiles live under src/.
# Update uv in the Dockerfiles together with every workflow's UV_VERSION manually.
# Keep the Dockerfile uv image tags at the lower bound in pyproject.toml.
- package-ecosystem: "docker-compose"
directory: "/"
schedule:
Expand Down
69 changes: 57 additions & 12 deletions .github/verify_deps_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
PRECOMMIT_CONFIG = ".pre-commit-config.yaml"
PYPROJECTS = ["./pyproject.toml", "./client/pyproject.toml"]
TRACKED_DEPS = ("uv", "ruff", "ty", "prek")
UV_REQUIRED_VERSION_PROJECTS = {"./pyproject.toml"}

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -52,10 +53,31 @@ def add_dep(deps: dict[str, list[dict[str, str]]], dep: str, file: str, group: s
deps[pkg].append({"file": file, "version": parsed["version"], "group": group})


def add_pyproject_deps(deps: dict[str, list[dict[str, str]]], pyproject_path: str) -> None:
def uv_lower_bound(required_version: str, source: str, troubles: list[str]) -> str | None:
versions = re.findall(r"(?:^|,)\s*>=\s*(\d+(?:\.\d+){1,2})(?=\s*(?:,|$))", required_version)
if len(versions) != 1:
troubles.append(
f"{source}: [tool.uv].required-version must have one >= lower bound, found {required_version!r}"
)
return None
return versions[0]


def add_pyproject_deps(deps: dict[str, list[dict[str, str]]], pyproject_path: str, troubles: list[str]) -> None:
with Path(pyproject_path).open("rb") as f:
pyproject: dict[str, Any] = tomllib.load(f)

tool_config = pyproject.get("tool", {})
uv_config = tool_config.get("uv") if isinstance(tool_config, dict) else None
if pyproject_path in UV_REQUIRED_VERSION_PROJECTS or uv_config is not None:
required_version = uv_config.get("required-version") if isinstance(uv_config, dict) else None
if isinstance(required_version, str):
lower_bound = uv_lower_bound(required_version, pyproject_path, troubles)
if lower_bound is not None:
deps["uv"].append({"file": pyproject_path, "version": f"=={lower_bound}", "group": "required-version"})
else:
troubles.append(f"{pyproject_path}: [tool.uv].required-version is missing")

project = pyproject.get("project", {})
if isinstance(project, dict):
dependencies = project.get("dependencies", [])
Expand All @@ -80,6 +102,8 @@ def add_pyproject_deps(deps: dict[str, list[dict[str, str]]], pyproject_path: st

def main() -> None:
deps: dict[str, list[dict[str, str]]] = {dep: [] for dep in TRACKED_DEPS}
troubles = []
setup_action_calls = 0

for dockerfile in DOCKERFILES:
dockerfile_content = Path(dockerfile).read_text(encoding="utf-8")
Expand All @@ -105,20 +129,41 @@ def main() -> None:
})

for pyproject_path in PYPROJECTS:
add_pyproject_deps(deps, pyproject_path)
add_pyproject_deps(deps, pyproject_path, troubles)

for workflow_file in Path(".github/workflows").glob("*.yml"):
with workflow_file.open("r", encoding="utf-8") as f:
workflow = yaml.safe_load(f) or {}
env = workflow.get("env", {})
if "UV_VERSION" in env:
deps["uv"].append({
"file": str(workflow_file),
"version": f"=={env['UV_VERSION'].lstrip('v')}",
"group": "workflow",
})
workflow_content = workflow_file.read_text(encoding="utf-8")
if "astral-sh/setup-uv@" in workflow_content:
troubles.append(f"{workflow_file}: use the shared .github/actions/setup-uv action")
setup_action_calls += workflow_content.count("./.github/actions/setup-uv")

action_path = Path(".github/actions/setup-uv/action.yml")
action = yaml.safe_load(action_path.read_text(encoding="utf-8"))
setup_steps = [
step
for step in action.get("runs", {}).get("steps", [])
if str(step.get("uses", "")).startswith("astral-sh/setup-uv@")
]
if setup_action_calls == 0:
troubles.append(".github/workflows: no shared .github/actions/setup-uv calls found")
if len(setup_steps) != 1:
troubles.append(f"{action_path}: expected one astral-sh/setup-uv step")
else:
setup = setup_steps[0].get("with", {})
if (
"version" in setup
or setup.get("version-file") != "pyproject.toml"
or setup.get("resolution-strategy") != "lowest"
):
troubles.append(f"{action_path}: install uv from pyproject.toml with resolution-strategy: lowest")
else:
root = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))
required = root.get("tool", {}).get("uv", {}).get("required-version")
if isinstance(required, str):
lower_bound = uv_lower_bound(required, "pyproject.toml", troubles)
if lower_bound is not None:
deps["uv"].append({"file": str(action_path), "version": f"=={lower_bound}", "group": "setup-uv"})

troubles = []
for dep, versions in deps.items():
if not versions:
troubles.append(f"{dep}: no tracked version found")
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

env:
PYTHON_VERSION: "3.11"
UV_VERSION: "0.11.14"

jobs:
docker:
Expand All @@ -19,9 +18,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Build, run & check docker
env:
SUPERADMIN_LOGIN: dummy_login
Expand Down Expand Up @@ -51,9 +48,7 @@ jobs:
with:
python-version: ${{ matrix.python }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Install project
run: |
uv pip install --system -e client/.
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ on:
push:
branches: main

env:
UV_VERSION: "0.11.14"

jobs:
gh-pages:
runs-on: ubuntu-latest
Expand All @@ -17,9 +14,7 @@ jobs:
with:
python-version: "3.10"
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Install dependencies
run: uv pip install --system -e "client/.[docs]"

Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:

env:
PYTHON_VERSION: "3.11"
UV_VERSION: "0.11.14"

jobs:
pypi:
Expand All @@ -18,9 +17,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Install dependencies
run: uv pip install --system setuptools wheel twine --upgrade
- name: Build and publish
Expand All @@ -47,9 +44,7 @@ jobs:
with:
python-version: ${{ matrix.python }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Install package
run: |
uv pip install --system pyroclient
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
pull_request:
branches: main

env:
UV_VERSION: "0.11.14"

jobs:
docs-client:
runs-on: ubuntu-latest
Expand All @@ -18,9 +15,7 @@ jobs:
with:
python-version: "3.10"
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Install dependencies
run: uv pip install --system -e "client/.[docs]"

Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ env:
BACKEND_IMAGE_NAME: alert-api
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_LOGIN }}
PYTHON_VERSION: "3.11"
UV_VERSION: "0.11.14"

jobs:
docker:
Expand All @@ -20,9 +19,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Resolve image tag
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

env:
PYTHON_VERSION: "3.11"
UV_VERSION: "0.11.14"

jobs:
end-to-end:
Expand All @@ -19,9 +18,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Run the backend & the test
env:
SUPERUSER_LOGIN: dummy_login
Expand Down
13 changes: 3 additions & 10 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

env:
PYTHON_VERSION: "3.11"
UV_VERSION: "0.11.14"

jobs:
ruff:
Expand All @@ -19,9 +18,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Run ruff
run: |
uv run --group quality ruff --version
Expand All @@ -35,9 +32,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Run ty
run: |
uv run --group quality ty --version
Expand All @@ -51,9 +46,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Run prek hooks
run: |
uv run --group quality prek --version
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

env:
PYTHON_VERSION: "3.11"
UV_VERSION: "0.11.14"

jobs:
pytest:
Expand All @@ -19,9 +18,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
# Build while PostgreSQL and S3 download and become healthy.
- parallel:
- name: Start test services
Expand Down Expand Up @@ -81,9 +78,7 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
- uses: ./.github/actions/setup-uv
- name: Run client tests
env:
SUPERADMIN_LOGIN: dummy_login
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies = []

[tool.uv]
package = false
required-version = ">=0.13.4,<1.0.0"

[tool.uv.sources]
pyroclient = { path = "client", editable = true }
Expand Down
2 changes: 1 addition & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN apt-get -y update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY --from=ghcr.io/astral-sh/uv:0.11.14 /uv /bin/uv
COPY --from=ghcr.io/astral-sh/uv:0.13.4 /uv /bin/uv

COPY pyproject.toml uv.lock /app/
COPY client/pyproject.toml /app/client/pyproject.toml
Expand Down
2 changes: 1 addition & 1 deletion src/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt-get -y update \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p client

RUN --mount=from=ghcr.io/astral-sh/uv:0.11.14,source=/uv,target=/bin/uv \
RUN --mount=from=ghcr.io/astral-sh/uv:0.13.4,source=/uv,target=/bin/uv \
--mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading