Skip to content

Commit 62e1838

Browse files
committed
Merge branch 'package-groups' into develop
2 parents 3ff0ea5 + 2c6fb8c commit 62e1838

15 files changed

+2287
-4664
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
requirements*.txt linguist-generated=true
1+
uv.lock linguist-generated=true
22
*.lockb binary diff=lockb

.github/workflows/docker-image.yml

+11-19
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,30 @@ jobs:
4242
python-version: '3.12'
4343
# cache: 'pip'
4444
- name: set up `uv`
45-
run: pip install uv && uv pip list
46-
- name: restore uv cache
47-
uses: actions/cache/restore@v4
48-
id: cache-uv-restore
45+
uses: astral-sh/setup-uv@v5
4946
with:
50-
path: ~/.cache/uv
51-
key: uv
47+
version: "0.6.2"
48+
enable-cache: true
49+
cache-dependency-glob: "uv.lock"
5250
- name: install pip dependencies with uv
5351
run: >
54-
uv pip sync --system requirements.dev.txt
55-
&& uv pip install --system . deps/wtforms-widgets
56-
&& uv pip list --system
52+
uv sync --locked --dev
53+
&& uv pip install deps/wtforms-widgets
54+
&& uv pip list
5755
id: pip-install
58-
- name: save uv cache
59-
uses: actions/cache/save@v4
60-
id: cache-uv-save
61-
with:
62-
path: ~/.cache/uv
63-
key: uv
6456
# now come the tests
6557
- name: Execute ruff
66-
run: ruff check --output-format=github .
58+
run: uv run ruff check --output-format=github .
6759
if: success() || steps.pip-install.conclusion == 'success'
6860
- name: Execute mypy
69-
run: ./scripts/run_mypy.sh
61+
run: uv run ./scripts/run_mypy.sh
7062
if: success() || steps.pip-install.conclusion == 'success'
7163
# docs stuff
7264
- name: Build sphinx docs
73-
run: make SPHINXOPTS="-EN -w sphinx.log" -C doc html
65+
run: uv run make SPHINXOPTS="-EN -w sphinx.log" -C doc html
7466
if: success() || steps.pip-install.conclusion == 'success'
7567
- name: Render sphinx warnings as annotations
76-
run: python ./scripts/render_sphinx_log.py doc/sphinx.log
68+
run: uv run python ./scripts/render_sphinx_log.py doc/sphinx.log
7769
if: success() || steps.pip-install.conclusion == 'success'
7870
- name: Publish sphinx docs as pages artifact
7971
uses: actions/upload-pages-artifact@v3

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,6 @@ venv.bak/
227227

228228
manuf
229229
celerybeat-schedule
230+
# timestamp-based dependency tracking.
231+
# used by some docker entrypoint hooks
232+
.*.stamp

.pre-commit-config.yaml

+2-13
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,9 @@ repos:
1616
hooks:
1717
- id: ruff
1818
- repo: https://github.com/astral-sh/uv-pre-commit
19-
rev: 0.4.7
19+
rev: 0.6.2
2020
hooks:
21-
- id: pip-compile
22-
name: "pip-compile: requirements.txt"
23-
args: [pyproject.toml, --generate-hashes, --quiet, -o, requirements.txt]
24-
files: ^(pyproject.toml|requirements.txt)$
25-
- id: pip-compile
26-
name: "pip-compile: requirements.dev.txt"
27-
args: [pyproject.toml, --generate-hashes, --extra, dev, --quiet, -o, requirements.dev.txt]
28-
files: ^(pyproject.toml|requirements.dev.txt)$
29-
- id: pip-compile
30-
name: "pip-compile: requirements.prod.txt"
31-
args: [pyproject.toml, --generate-hashes, --extra, prod, --quiet, -o, requirements.prod.txt]
32-
files: ^(pyproject.toml|requirements.prod.txt)$
21+
- id: uv-lock
3322
- repo: https://github.com/semgrep/pre-commit
3423
rev: 'v1.70.0'
3524
hooks:

doc/guides/setup.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ you only need to do the following:
4242
.. code:: shell
4343
4444
uv venv
45-
uv pip sync requirements.dev.txt && uv pip install -e deps/wtforms-widgets -e '.[dev]'
45+
uv sync --locked && uv pip install -e deps/wtforms-widgets
4646
4747
#. Run tests / Build docs / …

doc/guides/troubleshooting.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Reinstall the pip requirements
2424

2525
.. code:: sh
2626
27-
drc run --rm dev-app pip sync requirements.txt
27+
drc run --rm dev-app uv sync --locked
28+
drc run --rm dev-app uv pip install -e . deps/wtforms-widgets
2829
2930
I need to downgrade the schema
3031
------------------------------

docker/base.Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ARG GID=1000
99
ENV LANG=C.UTF-8 DEBIAN_FRONTEND=noninteractive
1010

1111
COPY etc/apt /etc/apt
12+
COPY --from=ghcr.io/astral-sh/uv:0.6.2 /uv /uvx /usr/local/bin/
1213

1314
# Install Debian packages
1415
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
@@ -29,9 +30,8 @@ WORKDIR /opt/pycroft
2930
# - Create app directory
3031
ENV VIRTUAL_ENV=/opt/pycroft/venv
3132
RUN --mount=type=cache,target=/opt/pycroft/.cache,uid=$UID,gid=$GID\
32-
python3 -m venv /opt/pycroft/venv \
33-
&& /opt/pycroft/venv/bin/pip install -U uv \
34-
&& /opt/pycroft/venv/bin/uv pip install -U setuptools wheel \
33+
uv venv /opt/pycroft/venv \
34+
&& uv pip install pip \
3535
&& mkdir /opt/pycroft/app /opt/pycroft/wheel
3636

3737
COPY --link . /

docker/dev/container/hooks/init/10_venv

+11-19
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,27 @@
22

33
set -euo pipefail
44
LOCKDIR=/opt/pycroft/venv
5+
INFILE=uv.lock
6+
STAMPFILE=.uv.stamp
57

68
. /container/common/locking.sh
79

810
function execute_hook() {
911
set -x
10-
PIP="/opt/pycroft/venv/bin/uv pip"
11-
UV="/opt/pycroft/venv/bin/uv"
12-
PY="/opt/pycroft/venv/bin/python"
12+
PIP="uv pip"
1313

14-
if [[ ! -f /opt/pycroft/venv/bin/activate ]]; then
15-
echo "Creating virtual environment"
16-
python3 -m venv /opt/pycroft/venv
17-
fi
18-
19-
if $PY -c 'import importlib.util as u; exit(0 if u.find_spec("pycroft") is not None else 1)'; then
20-
echo "Pip packages present, nothing to do"
14+
cd /opt/pycroft/app
15+
if [[ ! $INFILE -nt $STAMPFILE ]]; then
16+
echo "Lockfile did not change since last run. Nothing to do."
2117
return
2218
fi
2319

24-
$PY -m ensurepip
25-
$PY -m pip install uv
26-
$PIP install wheel
27-
2820
echo "No pip packages found, installing requirements"
29-
cd /opt/pycroft/app
30-
$PIP install --upgrade uv
31-
ls `$UV cache dir`
32-
$PIP sync requirements.dev.txt
33-
$PIP install -e '.[dev]' 'wtforms-widgets @ ./deps/wtforms-widgets'
21+
ls "$(uv cache dir)" || true
22+
uv venv "$VIRTUAL_ENV"
23+
uv sync --active --locked
24+
$PIP install -e . -e './deps/wtforms-widgets'
25+
touch $STAMPFILE
3426
}
3527

3628
[[ -d $LOCKDIR ]] || mkdir $LOCKDIR

docker/prod.Dockerfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ FROM pycroft-dev AS builder
88
WORKDIR /opt/pycroft/app
99

1010
# Download or build wheels of requirements
11-
COPY --chown=pycroft:pycroft requirements.prod.txt .
11+
COPY --chown=pycroft:pycroft uv.lock pyproject.toml ./
1212
COPY --chown=pycroft:pycroft ./deps ./deps
13-
RUN /opt/pycroft/venv/bin/pip wheel --wheel-dir /opt/pycroft/wheel -r requirements.prod.txt \
13+
RUN uv export --locked --no-emit-project --no-dev --group prod > requirements.prod.txt \
14+
&& /opt/pycroft/venv/bin/pip wheel --wheel-dir /opt/pycroft/wheel -r requirements.prod.txt \
1415
&& rm /opt/pycroft/wheel/wtforms_widgets*.whl \
1516
&& /opt/pycroft/venv/bin/pip wheel --wheel-dir /opt/pycroft/wheel --no-deps ./deps/wtforms-widgets
1617

@@ -27,7 +28,7 @@ FROM pycroft-base
2728

2829
# Install wheels from builder
2930
RUN --mount=type=bind,from=builder,source=/opt/pycroft/wheel,target=/opt/pycroft/wheel \
30-
/opt/pycroft/venv/bin/pip install /opt/pycroft/wheel/*.whl
31+
uv pip install /opt/pycroft/wheel/*.whl
3132

3233
EXPOSE 5000
3334

justfile

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ setup: _setup && build _schema-import schema-upgrade
2929
@echo -e "{{ _a_by }}About to build all docker images. This may take a while.{{ _a_rst }}"
3030
@echo "If you wish to skip this, run \`setup-no-build\` instead."
3131

32+
local-setup:
33+
uv sync --locked
34+
uv pip install -e . -e deps/wtforms-widgets
35+
3236
_setup:
3337
git submodule init
3438
git submodule update
@@ -133,11 +137,9 @@ schema-diff: (_up "dev-db") (alembic "diff")
133137
# upgrade the (imported or created) schema to the current revision
134138
schema-upgrade: (_up "dev-db") (alembic "upgrade" "head")
135139

136-
# extract `requirements` lockfiles from `pyproject.toml` dependency spec
140+
# regenerate `uv.lock`
137141
deps-compile:
138-
uv pip compile pyproject.toml --generate-hashes -o requirements.txt
139-
uv pip compile pyproject.toml --generate-hashes --extra dev -o requirements.dev.txt
140-
uv pip compile pyproject.toml --generate-hashes --extra prod -o requirements.prod.txt
142+
uv lock
141143

142144
_stop_all:
143145
{{ drc }} --progress=quiet stop

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dependencies = [
6464
"wtforms-widgets", # note: use `pip install -e deps/wtforms-widgets` for development
6565
]
6666

67-
[project.optional-dependencies]
67+
[dependency-groups]
6868
prod = [
6969
"uwsgi ~= 2.0.21",
7070
"uwsgitop ~= 0.11",

0 commit comments

Comments
 (0)