Skip to content

Commit f9e4ffe

Browse files
authored
build(deps-dev): switch from poetry to uv (#46)
* build(deps): switch from poetry to uv * docs: add multiple markdown files for repo * style(precommit): update config * ci(github): update CI jobs * ci(github): fix build * ci(github): revert license notice removal * ci(mypy): update setup * style(github): fix lint
1 parent 71b1e11 commit f9e4ffe

16 files changed

Lines changed: 963 additions & 420 deletions

.github/CODEOWNERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in
5+
# the repo. Unless a later match takes precedence,
6+
# @global-owner1 and @global-owner2 will be requested for
7+
# review when someone opens a pull request.
8+
* @frgfm

.github/SECURITY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Reporting security issues
2+
3+
If you believe you have found a security vulnerability in Quack API, we encourage you to let us know right away. We will investigate all legitimate reports and do our best to quickly fix the problem.
4+
5+
Please report security issues using https://github.com/frgfm/validate-python-headers/security/advisories/new

.github/dependabot.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55

66
version: 2
77
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
812
- package-ecosystem: "pip"
913
directory: "/"
1014
schedule:
1115
interval: "daily"
12-
time: "06:00"
13-
timezone: "Europe/Paris"
14-
reviewers:
15-
- "frgfm"
16-
assignees:
17-
- "frgfm"
1816
allow:
1917
- dependency-name: "ruff"
2018
- dependency-name: "mypy"
2119
- dependency-name: "pre-commit"
20+
- package-ecosystem: "docker"
21+
directory: "/"
22+
schedule:
23+
interval: "daily"
24+
allow:
25+
- dependency-name: "ghcr.io/astral-sh/uv"

.github/verify_deps_sync.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright (C) 2024, François-Guillaume Fernandez.
2+
3+
# This program is licensed under the Apache License 2.0.
4+
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details.
5+
6+
import re
7+
import tomllib
8+
from pathlib import Path
9+
10+
import yaml
11+
12+
DOCKERFILE_PATH = "./Dockerfile"
13+
PRECOMMIT_PATH = ".pre-commit-config.yaml"
14+
PYPROJECT_PATH = "./pyproject.toml"
15+
16+
17+
def main():
18+
# Retrieve & parse all deps files
19+
deps_dict = {"uv": [], "ruff": [], "mypy": []}
20+
# UV: Dockerfile, precommit, .github
21+
# Parse Dockerfile
22+
with Path(DOCKERFILE_PATH).open("r") as f:
23+
dockerfile = f.read()
24+
uv_version = re.search(r"ghcr\.io/astral-sh/uv:(\d+\.\d+\.\d+)", dockerfile)
25+
if uv_version:
26+
deps_dict["uv"] = [{"file": DOCKERFILE_PATH, "version": uv_version.group(1)}]
27+
28+
# Parse precommit
29+
with Path(PRECOMMIT_PATH).open("r") as f:
30+
precommit = yaml.safe_load(f)
31+
32+
for repo in precommit["repos"]:
33+
if repo["repo"] == "https://github.com/astral-sh/uv-pre-commit":
34+
deps_dict["uv"].append({"file": PRECOMMIT_PATH, "version": repo["rev"].lstrip("v")})
35+
elif repo["repo"] == "https://github.com/charliermarsh/ruff-pre-commit":
36+
deps_dict["ruff"] = [{"file": PRECOMMIT_PATH, "version": repo["rev"].lstrip("v")}]
37+
38+
# Parse pyproject.toml
39+
with Path(PYPROJECT_PATH).open("rb") as f:
40+
pyproject = tomllib.load(f)
41+
42+
dev_deps = pyproject["tool"]["uv"]["dev-dependencies"]
43+
for dep in dev_deps:
44+
if dep.startswith("ruff=="):
45+
deps_dict["ruff"].append({"file": PYPROJECT_PATH, "version": dep.split("==")[1]})
46+
elif dep.startswith("mypy=="):
47+
deps_dict["mypy"] = [{"file": PYPROJECT_PATH, "version": dep.split("==")[1]}]
48+
49+
# Parse github/workflows/...
50+
for workflow_file in Path(".github/workflows").glob("*.yml"):
51+
with workflow_file.open("r") as f:
52+
workflow = yaml.safe_load(f)
53+
if "env" in workflow and "UV_VERSION" in workflow["env"]:
54+
deps_dict["uv"].append({
55+
"file": str(workflow_file),
56+
"version": workflow["env"]["UV_VERSION"].lstrip("v"),
57+
})
58+
59+
# Assert all deps are in sync
60+
troubles = []
61+
for dep, versions in deps_dict.items():
62+
versions_ = {v["version"] for v in versions}
63+
if len(versions_) != 1:
64+
inv_dict = {v: set() for v in versions_}
65+
for version in versions:
66+
inv_dict[version["version"]].add(version["file"])
67+
troubles.extend([
68+
f"{dep}:",
69+
"\n".join(f"- '{v}': {', '.join(files)}" for v, files in inv_dict.items()),
70+
])
71+
72+
if len(troubles) > 0:
73+
raise AssertionError("Some dependencies are out of sync:\n\n" + "\n".join(troubles))
74+
75+
76+
if __name__ == "__main__":
77+
main()
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
name: builds
1+
name: build
22

33
on:
44
push:
55
branches: main
66
pull_request:
77
branches: main
88

9+
env:
10+
PYTHON_VERSION: "3.11"
11+
UV_VERSION: "0.5.7"
12+
913
jobs:
1014
build:
1115
runs-on: ${{ matrix.os }}
@@ -15,4 +19,7 @@ jobs:
1519
os: [ubuntu-latest]
1620
steps:
1721
- uses: actions/checkout@v4
18-
- run: docker build . -t header-validator:latest
22+
- uses: astral-sh/setup-uv@v4
23+
with:
24+
version: ${{ env.UV_VERSION }}
25+
- run: make build
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: pr-title
1+
name: pr-edited
22

33
on:
44
pull_request_target:
@@ -7,7 +7,7 @@ on:
77
types: [opened, reopened, edited, synchronize]
88

99
jobs:
10-
lint:
10+
lint-pr-title:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: amannn/action-semantic-pull-request@v5

.github/workflows/push.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: push
2+
on:
3+
push:
4+
branches: main
5+
6+
env:
7+
UV_VERSION: "0.5.7"
8+
BACKEND_IMAGE: validate-python-headers
9+
10+
jobs:
11+
docker:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
packages: write
15+
contents: read
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: astral-sh/setup-uv@v4
19+
with:
20+
version: ${{ env.UV_VERSION }}
21+
- name: Build docker image
22+
run: make build
23+
- name: Login to GHCR
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.repository_owner }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Push to GitHub container registry
30+
run: |
31+
docker tag openapm/backend:latest ghcr.io/${{ github.repository_owner }}/${{ env.BACKEND_IMAGE }}:latest
32+
docker push ghcr.io/${{ github.repository_owner }}/${{ env.BACKEND_IMAGE }}:latest

.github/workflows/style.yml

Lines changed: 22 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,109 +6,60 @@ on:
66
pull_request:
77
branches: main
88

9+
env:
10+
PYTHON_VERSION: "3.11"
11+
UV_VERSION: "0.5.7"
12+
913
jobs:
1014
ruff:
11-
runs-on: ${{ matrix.os }}
12-
strategy:
13-
matrix:
14-
os: [ubuntu-latest]
15-
python: [3.9]
15+
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
1818
- uses: actions/setup-python@v5
1919
with:
20-
python-version: ${{ matrix.python }}
20+
python-version: ${{ env.PYTHON_VERSION }}
2121
architecture: x64
22-
- uses: abatilo/actions-poetry@v3
22+
- uses: astral-sh/setup-uv@v4
2323
with:
24-
poetry-version: "1.8.2"
25-
- name: Resolve dependencies
26-
run: poetry export -f requirements.txt --without-hashes --only quality --output requirements.txt
27-
- name: Install dependencies
28-
run: |
29-
python -m pip install --upgrade uv
30-
uv pip install --system -r requirements.txt
24+
version: ${{ env.UV_VERSION }}
3125
- name: Run ruff
3226
run: |
27+
make install-quality
3328
ruff --version
34-
ruff check --diff .
29+
make lint-check
3530
3631
mypy:
37-
runs-on: ${{ matrix.os }}
38-
strategy:
39-
matrix:
40-
os: [ubuntu-latest]
41-
python: [3.9]
32+
runs-on: ubuntu-latest
4233
steps:
4334
- uses: actions/checkout@v4
4435
- uses: actions/setup-python@v5
4536
with:
46-
python-version: ${{ matrix.python }}
37+
python-version: ${{ env.PYTHON_VERSION }}
4738
architecture: x64
48-
- uses: abatilo/actions-poetry@v3
39+
- uses: astral-sh/setup-uv@v4
4940
with:
50-
poetry-version: "1.8.2"
51-
- name: Resolve dependencies
52-
run: poetry export -f requirements.txt --without-hashes --with quality --output requirements.txt
53-
- name: Install dependencies
54-
run: |
55-
python -m pip install --upgrade uv
56-
uv pip install --system -r requirements.txt
41+
version: ${{ env.UV_VERSION }}
5742
- name: Run mypy
5843
run: |
44+
make install-quality
5945
mypy --version
60-
mypy
61-
62-
ruff-format:
63-
runs-on: ${{ matrix.os }}
64-
strategy:
65-
matrix:
66-
os: [ubuntu-latest]
67-
python: [3.9]
68-
steps:
69-
- uses: actions/checkout@v4
70-
- uses: actions/setup-python@v5
71-
with:
72-
python-version: ${{ matrix.python }}
73-
architecture: x64
74-
- uses: abatilo/actions-poetry@v3
75-
with:
76-
poetry-version: "1.8.2"
77-
- name: Resolve dependencies
78-
run: poetry export -f requirements.txt --without-hashes --only quality --output requirements.txt
79-
- name: Install dependencies
80-
run: |
81-
python -m pip install --upgrade uv
82-
uv pip install --system -r requirements.txt
83-
- name: Run ruff
84-
run: |
85-
ruff --version
86-
ruff format --check --diff .
46+
make typing-check
8747
8848
precommit-hooks:
89-
runs-on: ${{ matrix.os }}
90-
strategy:
91-
matrix:
92-
os: [ubuntu-latest]
93-
python: [3.9]
49+
runs-on: ubuntu-latest
9450
steps:
9551
- uses: actions/checkout@v4
9652
- uses: actions/setup-python@v5
9753
with:
98-
python-version: ${{ matrix.python }}
54+
python-version: ${{ env.PYTHON_VERSION }}
9955
architecture: x64
100-
- uses: abatilo/actions-poetry@v3
56+
- uses: astral-sh/setup-uv@v4
10157
with:
102-
poetry-version: "1.8.2"
103-
- name: Resolve dependencies
104-
run: poetry export -f requirements.txt --without-hashes --only quality --output requirements.txt
105-
- name: Install dependencies
106-
run: |
107-
python -m pip install --upgrade uv
108-
uv pip install --system -r requirements.txt
58+
version: ${{ env.UV_VERSION }}
10959
- name: Run pre-commit hooks
11060
run: |
61+
make install-quality
11162
git checkout -b temp
11263
pre-commit install
11364
pre-commit --version
114-
pre-commit run --all-files
65+
make precommit

.github/workflows/tests.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,47 @@ on:
66
pull_request:
77
branches: main
88

9+
env:
10+
PYTHON_VERSION: "3.11"
11+
UV_VERSION: "0.5.7"
12+
913
jobs:
1014
run-action:
11-
runs-on: ${{ matrix.os }}
12-
strategy:
13-
fail-fast: false
14-
matrix:
15-
os: [ubuntu-latest]
15+
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
1818
- run: docker build . -t header-validator:latest
1919
- name: Run action
2020
run: |
2121
docker run --workdir /github/workspace -v "/home/runner/work/validate-python-headers/validate-python-headers":"/github/workspace" header-validator:latest 'François-Guillaume Fernandez' 2022 Apache-2.0 src/ __init__.py .github/ ''
2222
docker run --workdir /github/workspace -v "/home/runner/work/validate-python-headers/validate-python-headers":"/github/workspace" header-validator:latest 'François-Guillaume Fernandez' 2022 '' src/ __init__.py .github/ .github/license-notice.txt
23+
deps-sync:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-python@v5
28+
with:
29+
python-version: ${{ env.PYTHON_VERSION }}
30+
architecture: x64
31+
- uses: astral-sh/setup-uv@v4
32+
with:
33+
version: ${{ env.UV_VERSION }}
34+
- name: Run dependency sync checker
35+
run: |
36+
uv pip install --system PyYAML
37+
make deps-check
38+
39+
headers:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
persist-credentials: false
45+
- name: Check the headers
46+
uses: frgfm/validate-python-headers@main
47+
with:
48+
license: 'Apache-2.0'
49+
owner: 'François-Guillaume Fernandez'
50+
starting-year: 2022
51+
folders: 'src'
52+
ignore-files: 'version.py,__init__.py'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: pull_requests
1+
name: triage
22

33
on:
44
pull_request:
55
branches: main
66

77
jobs:
8-
triage:
8+
autolabel:
99
permissions:
1010
contents: read
1111
pull-requests: write

0 commit comments

Comments
 (0)