Skip to content

Commit 9894286

Browse files
authored
chore: migration from pdm to uv (#187)
* chore(migration from pdm to uv): fix ci workflow * chore(migration from pdm to uv): fix ci workflow * chore(migration from pdm to uv): fix docs workflow * chore(migration from pdm to uv): fix makefile commands * chore(migration from pdm to uv): fix pyproject, move some commands from pdm scripts to makefile * chore(migration from pdm to uv): fix ci workflow * chore(migration from pdm to uv): replace pdm.lock to uv.lock * chore(migration from pdm to uv): fix commands * chore(migration from pdm to uv): use makefile commands in dockerfile * chore(migration from pdm to uv): add uv install command to makefile * chore(migration from pdm to uv): fix workflows * chore(migration from pdm to uv): fix pdm installing note
1 parent 7205e23 commit 9894286

File tree

17 files changed

+2437
-3262
lines changed

17 files changed

+2437
-3262
lines changed

.github/workflows/ci.yaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ concurrency:
1212
env:
1313
PYTHONUNBUFFERED: "1"
1414
FORCE_COLOR: "1"
15+
UV_LOCKED: 1
16+
1517
jobs:
1618
validate:
1719
runs-on: ubuntu-latest
@@ -48,24 +50,20 @@ jobs:
4850
- name: Create cache file
4951
run: echo '${{ matrix.python-version }}' > ./matrix-file.txt
5052

51-
- uses: pdm-project/setup-pdm@v4
52-
name: Set up PDM
53+
- name: Install uv
54+
uses: astral-sh/setup-uv@v4
5355
with:
54-
python-version: ${{ matrix.python-version }}
55-
allow-python-prereleases: false
56-
cache: true
57-
cache-dependency-path: |
58-
./pdm.lock
59-
./matrix-file.txt
56+
version: "0.5.10"
57+
enable-cache: true
6058

6159
- name: Install base libraries
6260
run: pip install nodeenv cython setuptools pip --upgrade --quiet --user
6361

6462
- name: Install dependencies
65-
run: pdm install -G:all
63+
run: uv sync --all-groups
6664

6765
- name: Test with Coverage
68-
run: pdm run pytest tests --cov=app --cov-report=xml
66+
run: uv run pytest tests --cov=app --cov-report=xml
6967

7068
- if: matrix.python-version == '3.11'
7169
uses: actions/upload-artifact@v4
@@ -87,18 +85,17 @@ jobs:
8785
with:
8886
python-version: "3.11"
8987

90-
- uses: pdm-project/setup-pdm@v4
91-
name: Set up PDM
88+
- name: Install uv
89+
uses: astral-sh/setup-uv@v4
9290
with:
93-
python-version: "3.11"
94-
allow-python-prereleases: false
95-
cache: true
91+
version: "0.5.10"
92+
enable-cache: true
9693

9794
- name: Install dependencies
98-
run: pdm install -G:all
95+
run: uv sync --all-groups
9996

10097
- name: Build docs
101-
run: pdm run make docs
98+
run: uv run make docs
10299

103100
- name: Save PR number
104101
env:
@@ -127,12 +124,15 @@ jobs:
127124
uses: actions/checkout@v4
128125
- name: Install base libraries
129126
run: pip install nodeenv cython setuptools pip --upgrade --quiet --user
130-
- uses: pdm-project/setup-pdm@v4
131-
name: Set up PDM
127+
128+
- name: Install uv
129+
uses: astral-sh/setup-uv@v4
132130
with:
133-
python-version: "3.11"
134-
cache: true
131+
version: "0.5.10"
132+
enable-cache: true
133+
135134
- name: Install dependencies
136-
run: pdm install -G:all
135+
run: uv sync --all-groups
136+
137137
- name: Perform CodeQL Analysis
138138
uses: github/codeql-action/analyze@v3

.github/workflows/docs.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches:
88
- main
99

10+
env:
11+
UV_LOCKED: 1
12+
1013
jobs:
1114
docs:
1215
permissions:
@@ -19,25 +22,24 @@ jobs:
1922
with:
2023
python-version: "3.11"
2124

22-
- uses: pdm-project/setup-pdm@v4
23-
name: Set up PDM
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v4
2427
with:
25-
python-version: "3.11"
26-
allow-python-prereleases: true
27-
cache: true
28+
version: "0.5.10"
29+
enable-cache: true
2830

2931
- name: Install dependencies
30-
run: pdm install -G:all
32+
run: uv sync --all-groups
3133

3234
- name: Fetch gh pages
3335
run: git fetch origin gh-pages --depth=1
3436

3537
- name: Build release docs
36-
run: pdm run python scripts/build-docs.py docs-build
38+
run: uv run python scripts/build-docs.py docs-build
3739
if: github.event_name == 'release'
3840

3941
- name: Build dev docs
40-
run: pdm run python scripts/build-docs.py docs-build
42+
run: uv run python scripts/build-docs.py docs-build
4143
if: github.event_name == 'push'
4244

4345
- name: Deploy

CONTRIBUTING.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Contribution Guide
55
Setting up the environment
66
--------------------------
77

8-
1. Install `Pizza Delivery Man <https://pdm.fming.dev/latest/>`_
9-
2. Run ``pdm install -G:all`` to create a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ and install
8+
1. If you do not have already have Astral's UV installed, run `make install-uv`
9+
2. Run ``uv sync --all-groups`` to create a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ and install
1010
the dependencies
11-
3. If you're working on the documentation and need to build it locally, install the extra dependencies with ``pdm install -G:docs``
11+
3. If you're working on the documentation and need to build it locally, install the extra dependencies with `` uv sync --group docs``
1212
4. Install `pre-commit <https://pre-commit.com/>`_
1313
5. Run ``pre-commit install`` to install pre-commit hooks
1414

@@ -57,7 +57,7 @@ To run or build the docs locally, you need to first install the required depende
5757

5858
.. code-block:: console
5959
60-
pdm install -G:docs
60+
uv sync --group docs
6161
6262
Then you can serve the documentation with ``make docs-serve``, or build them with ``make docs``
6363

Makefile

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ SHELL := /bin/bash
55

66
.DEFAULT_GOAL:=help
77
.ONESHELL:
8-
USING_PDM = $(shell grep "tool.pdm" pyproject.toml && echo "yes")
98
USING_NPM = $(shell python3 -c "if __import__('pathlib').Path('package-lock.json').exists(): print('yes')")
109
ENV_PREFIX =.venv/bin/
11-
VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')")
1210
NODE_MODULES_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('node_modules').exists(): print('yes')")
1311
SRC_DIR =src
1412
BUILD_DIR =dist
15-
PDM_OPTS ?=
16-
PDM ?= pdm $(PDM_OPTS)
1713

1814
.EXPORT_ALL_VARIABLES:
1915

@@ -30,43 +26,28 @@ help: ## Display this help text for Makefile
3026
.PHONY: upgrade
3127
upgrade: ## Upgrade all dependencies to the latest stable versions
3228
@echo "=> Updating all dependencies"
33-
@if [ "$(USING_PDM)" ]; then $(PDM) update; fi
29+
@uv lock --upgrade
3430
@echo "=> Python Dependencies Updated"
3531
@if [ "$(USING_NPM)" ]; then npm upgrade --latest; fi
3632
@echo "=> Node Dependencies Updated"
3733
@$(ENV_PREFIX)pre-commit autoupdate
3834
@echo "=> Updated Pre-commit"
3935

40-
.PHONY: uninstall
41-
uninstall:
42-
@echo "=> Uninstalling PDM"
43-
ifeq ($(OS),Windows_NT)
44-
@echo "=> Removing PDM from %APPDATA%\Python\Scripts"
45-
@if exist "%APPDATA%\Python\Scripts\pdm" (del "%APPDATA%\Python\Scripts\pdm")
46-
else
47-
@echo "=> Removing PDM from ~/.local/bin"
48-
@rm -f ~/.local/bin/pdm
49-
endif
50-
@echo "=> PDM removal complete"
51-
@echo "=> Uninstallation complete!"
52-
5336
# =============================================================================
5437
# Developer Utils
5538
# =============================================================================
56-
install-pdm: ## Install latest version of PDM
57-
@curl -sSLO https://pdm.fming.dev/install-pdm.py && \
58-
curl -sSL https://pdm.fming.dev/install-pdm.py.sha256 | shasum -a 256 -c - && \
59-
python3 install-pdm.py
39+
.PHONY: install-uv
40+
install-uv: ## Install latest version of uv
41+
@echo "${INFO} Installing uv..."
42+
@curl -LsSf https://astral.sh/uv/install.sh | sh >/dev/null 2>&1
43+
@uv tool install nodeenv >/dev/null 2>&1
44+
@echo "${OK} UV installed successfully"
6045

6146
install: ## Install the project and
62-
@if ! $(PDM) --version > /dev/null; then echo '=> Installing PDM'; $(MAKE) install-pdm; fi
63-
@if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; fi
64-
if [ "$(VENV_EXISTS)" ]; then $(MAKE) destroy-venv; fi
65-
if [ "$(VENV_EXISTS)" ]; then $(MAKE) clean; fi
47+
@uv sync
48+
uv run python scripts/pre-build.py --install-packages
6649
@if [ "$(NODE_MODULES_EXISTS)" ]; then echo "=> Removing existing node modules"; fi
6750
if [ "$(NODE_MODULES_EXISTS)" ]; then $(MAKE) destroy-node_modules; fi
68-
@if [ "$(USING_PDM)" ]; then $(PDM) config venv.in_project true && python3 -m venv --copies .venv && . $(ENV_PREFIX)/activate && $(ENV_PREFIX)/pip install --quiet -U wheel setuptools cython pip mypy nodeenv; fi
69-
@if [ "$(USING_PDM)" ]; then $(PDM) install -G:all; fi
7051
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"
7152

7253

@@ -105,17 +86,19 @@ migrate: ## Generate database migrations
10586
.PHONY: build
10687
build:
10788
@echo "=> Building package..."
108-
@if [ "$(USING_PDM)" ]; then pdm build; fi
89+
uv run python scripts/pre-build.py --build-assets
90+
@uv build
10991
@echo "=> Package build complete..."
11092

111-
.PHONY: refresh-lockfiles
112-
refresh-lockfiles: ## Sync lockfiles with requirements files.
113-
@pdm update --update-reuse --group :all
114-
11593
.PHONY: lock
11694
lock: ## Rebuild lockfiles from scratch, updating all dependencies
117-
@pdm update --update-eager --group :all
95+
@uv lock
96+
97+
start-infra:
98+
docker compose -f docker-compose.infra.yml up --force-recreate -d
11899

100+
stop-infra:
101+
docker compose -f docker-compose.infra.yml down --remove-orphans
119102
# =============================================================================
120103
# Tests, Linting, Coverage
121104
# =============================================================================
@@ -151,7 +134,7 @@ test: ## Run the tests
151134
.PHONY: docs-install
152135
docs-install: ## Install docs dependencies
153136
@echo "=> Installing documentation dependencies"
154-
@$(PDM) install -dG:docs
137+
@uv sync --group docs
155138
@echo "=> Installed documentation dependencies"
156139

157140
docs-clean: ## Dump the existing built docs
@@ -161,8 +144,8 @@ docs-clean: ## Dump the existing built docs
161144

162145
docs-serve: docs-clean ## Serve the docs locally
163146
@echo "=> Serving documentation"
164-
$(PDM_RUN_BIN) sphinx-autobuild docs docs/_build/ -j auto --watch src --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002
147+
$uv run sphinx-autobuild docs docs/_build/ -j auto --watch src --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002
165148

166149
docs: docs-clean ## Dump the existing built docs and rebuild them
167150
@echo "=> Building documentation"
168-
@$(PDM_RUN_BIN) sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going
151+
@uv run sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ make install
4949

5050
```bash
5151
cp .env.local.example .env
52-
pdm run start-infra # this starts a database and redis instance only
52+
make start-infra # this starts a database and redis instance only
5353
# this will start the SAQ worker, Vite development process, and Litestar
54-
pdm run app run
54+
uv run app run
5555

5656
# to stop the database and redis, run
57-
pdm run stop-infra
57+
make stop-infra
5858
```
5959

6060
### Docker

deploy/docker/dev/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ RUN apt-get update \
3030
## ------------------------- Python build base -------------------------------------- ##
3131
## ---------------------------------------------------------------------------------- ##
3232
FROM python-base AS build-base
33-
ARG PDM_INSTALL_ARGS="-G:all"
34-
ENV PDM_INSTALL_ARGS="${PDM_INSTALL_ARGS}" \
33+
ARG UV_INSTALL_ARGS="--all-groups"
34+
ENV UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
3535
GRPC_PYTHON_BUILD_WITH_CYTHON=1 \
3636
PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH"
3737
## -------------------------- add build packages ----------------------------------- ##
@@ -45,16 +45,16 @@ RUN apt-get install -y --no-install-recommends build-essential curl \
4545

4646
## -------------------------- install application ----------------------------------- ##
4747
WORKDIR /workspace/app
48-
COPY pyproject.toml pdm.lock README.md .pre-commit-config.yaml LICENSE Makefile \
48+
COPY pyproject.toml uv.lock README.md .pre-commit-config.yaml LICENSE Makefile \
4949
package.json package-lock.json vite.config.ts tsconfig.json tsconfig.node.json \
5050
tailwind.config.cjs postcss.config.cjs components.json \
5151
./
5252
COPY scripts ./scripts/
5353
COPY public ./public/
5454
COPY resources ./resources/
5555
RUN python -m venv --copies /workspace/app/.venv \
56-
&& /workspace/app/.venv/bin/pip install cython pdm nodeenv \
57-
&& pdm install ${PDM_INSTALL_ARGS} --no-self
56+
&& /workspace/app/.venv/bin/pip install cython uv nodeenv \
57+
&& uv install ${UV_INSTALL_ARGS}
5858
COPY src ./src/
5959

6060
## ---------------------------------------------------------------------------------- ##
@@ -82,7 +82,7 @@ WORKDIR /workspace/app
8282
COPY docs/ docs/
8383
COPY tests/ tests/
8484
COPY src src/
85-
RUN pdm install $PDM_INSTALL_ARGS
85+
RUN uv install $UV_INSTALL_ARGS
8686
STOPSIGNAL SIGINT
8787
EXPOSE 8000
8888
ENTRYPOINT ["tini","--" ]

deploy/docker/run/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,34 @@ RUN apt-get update \
3030
## ------------------------- Python build base -------------------------------------- ##
3131
## ---------------------------------------------------------------------------------- ##
3232
FROM python-base AS build-base
33-
ARG PDM_INSTALL_ARGS=""
34-
ENV PDM_INSTALL_ARGS="${PDM_INSTALL_ARGS}" \
33+
ARG UV_INSTALL_ARGS=""
34+
ENV UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
3535
GRPC_PYTHON_BUILD_WITH_CYTHON=1 \
3636
PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH"
3737
## -------------------------- add build packages ----------------------------------- ##
3838
RUN apt-get install -y --no-install-recommends build-essential curl \
3939
&& apt-get autoremove -y \
40-
&& apt-get clean -y \
40+
&& apt-get clean make -y \
4141
&& rm -rf /root/.cache \
4242
&& rm -rf /var/apt/lists/* \
4343
&& rm -rf /var/cache/apt/* \
4444
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
4545

4646
## -------------------------- install application ----------------------------------- ##
4747
WORKDIR /workspace/app
48-
COPY pyproject.toml pdm.lock README.md .pre-commit-config.yaml LICENSE Makefile \
48+
COPY pyproject.toml uv.lock README.md .pre-commit-config.yaml LICENSE Makefile \
4949
package.json package-lock.json vite.config.ts tsconfig.json tsconfig.node.json \
5050
tailwind.config.cjs postcss.config.cjs components.json \
5151
./
5252
COPY scripts ./scripts/
5353
COPY public ./public/
5454
COPY resources ./resources/
5555
RUN python -m venv --copies /workspace/app/.venv \
56-
&& /workspace/app/.venv/bin/pip install --quiet pdm nodeenv cython \
57-
&& pdm install ${PDM_INSTALL_ARGS} --no-self \
58-
&& pdm export ${PDM_INSTALL_ARGS} --without-hashes --prod --output=requirements.txt
56+
&& /workspace/app/.venv/bin/pip install --quiet uv nodeenv cython \
57+
&& make install ${UV_INSTALL_ARGS} \
58+
&& uv export ${UV_INSTALL_ARGS} --no-hashes --no-dev --output-file=requirements.txt
5959
COPY src ./src/
60-
RUN pdm build
60+
RUN make build
6161

6262

6363
## ---------------------------------------------------------------------------------- ##

0 commit comments

Comments
 (0)