Skip to content

Commit

Permalink
Change from PDM to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
Centurix committed Feb 8, 2025
1 parent e2e1989 commit 54c0561
Show file tree
Hide file tree
Showing 22 changed files with 1,255 additions and 1,743 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v3
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.9"
- name: Install dependencies
run: |
curl -sSL https://pdm.fming.dev/install-pdm.py | python3 -
pdm install
python-version: 3.9
- run: uv sync
- name: Lint with Ruff
run: pdm run lint
run: uv run ./lint
- name: Test with pytest
run: pdm run test
run: uv run ./test

build_docker_image:
name: Build & Push Docker image
Expand Down
34 changes: 0 additions & 34 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
.pdm-build

# lint
.ruff_cache
Expand Down Expand Up @@ -108,36 +107,6 @@ target/
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid
Expand Down Expand Up @@ -184,7 +153,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.pdm-python
.python-version

# SPA files
Expand Down Expand Up @@ -224,5 +192,3 @@ test-results/
playwright-report/

*.db

.pdm.lock
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ COPY . /traffcap
WORKDIR /traffcap

# Install Python dependencies
RUN curl -sSL https://pdm.fming.dev/install-pdm.py | python3 - && \
pdm install --production && \
pdm cache clear
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
uv sync --no-dev && \
uv cache clean

# Build frontend
RUN cd src/traffcap/spa && \
Expand All @@ -39,4 +39,4 @@ WORKDIR /traffcap/src

VOLUME /data

CMD pdm run server
CMD uv run ./server
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![build workflow](https://github.com/huh-sters/traffcap/actions/workflows/build.yml/badge.svg)
![licence](https://img.shields.io/github/license/huh-sters/traffcap.svg)
![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)
![uv-managed](https://img.shields.io/badge/uv-managed-blueviolet)

![Logo](https://github.com/huh-sters/traffcap/blob/master/src/traffcap/spa/src/assets/traffcap_logo.png?raw=true)

Expand Down Expand Up @@ -81,15 +81,15 @@ And a basic server will start. Typing `traffcap --help` will list the available
At the moment, you'll need the following to run it:

* Python 3.9 or greater ([pyenv](https://github.com/pyenv/pyenv#automatic-installer) is a good way to manage versions)
* [PDM installed](https://pdm.fming.dev/latest/#installation)
* [uv installed](https://github.com/astral-sh/uv)
* Node v12 or greater ([nvm](https://github.com/nvm-sh/nvm#installing-and-updating) is a good way to manage versions)
* NPM (If you installed Node, you should have a version of NPM already)

## Installing Python project dependencies

After cloning the repository to a directory somewhere, change to the repository directory and run the following to install dependencies in a virtual environment:

`pdm install`
`uv sync`

Then, once the dependencies are done the server part is ready to rock. But out of the box, there's no UI to configure anything, so you'll need the next step.

Expand All @@ -105,7 +105,7 @@ It should display messages about Quasar building and if all is good you'll see l

From the repository root, issue the following command to start the server:

`pdm run server`
`uv run ./server`

You'll get a bunch of messages and the server will be up and running. Now, you can visit:

Expand All @@ -115,7 +115,7 @@ That's it!

## What Does It Run?

When you invoke `pdm run server`, it starts [Gunicorn](https://gunicorn.org/) with 4 [Uvicorn](https://www.uvicorn.org/) workers.
When you invoke `uv run ./server`, it starts [Gunicorn](https://gunicorn.org/) with 4 [Uvicorn](https://www.uvicorn.org/) workers.

It then binds everything to `0.0.0.0` on port `9669`

Expand Down Expand Up @@ -170,28 +170,28 @@ Now you can set breakpoints and run this directly from VSCode.

## How Do I Get The Python Interpreter Path For The Virtual Environment?

This project uses PDM for managing dependencies and virtual environments. You can issue this command to list the virtual environment path for the project:
This project uses [uv] for managing dependencies and virtual environments. You can create virtual environments with the following command:

`pdm venv list`
`uv venv .venv`

You'll get a list of environments and the Python versions that they are for. The Python interpreter is in the `bin` directory in each environment. So for example, if you see the following:
You'll get details of the environment just created. The Python interpreter is in the `bin` directory in the environment. You see the following:

```
~/python_projects/traffcap> pdm venv list
Virtualenvs created with this project:
* 3.9: /home/chris/.pdm_venv/traffcap-kO3U-3Zd-3.9
~/python_projects/traffcap> uv venv .venv
Using CPython 3.13.2
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
```

Then the interpreter for that version of Python 3.9 is:

`/home/chris/.pdm_venv/traffcap-kO3U-3Zd-3.9/bin/python`
`.venv/bin/python`

If you wanted to, you can add the default Python interpreter in VSCode by adding the following to your projects `settings.json`:

```
{
"python.defaultInterpreterPath": "/home/chris/.pdm_venv/traffcap-kO3U-3Zd-3.9/bin/python",
"python.defaultInterpreterPath": ".venv/bin/python",
...
}
```
Expand Down Expand Up @@ -287,7 +287,7 @@ During development, it is fine to create feature branch revisions using the IDs

OR

`pdm run baseline_schema`
`uv run ./baseline_schema`

### ORM Usage and Being Database Agnostic

Expand Down
4 changes: 4 additions & 0 deletions all
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
./lint
./test
./typecheck
2 changes: 2 additions & 0 deletions baseline_schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
alembic --config=src/alembic.ini revision --autogenerate --rev-id 0.0.1 -m baseline
2 changes: 2 additions & 0 deletions lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
ruff check .
Loading

0 comments on commit 54c0561

Please sign in to comment.