Skip to content

Commit 45b47b0

Browse files
committed
Migrated to use pyproject.toml and uv
Also removed the `test-results` job (added in b833efd) as it's not needed now that we don't use `strategy.matrix` anymore to run the tests. Also changed Dependabot's update schedule for our Python dependencies from daily to weekly, which is probably more manageable for us. Also upgraded `actions/checkout` and `actions/setup-python`, which didn't have any breaking changes for us.
1 parent 08c8aeb commit 45b47b0

File tree

13 files changed

+1155
-151
lines changed

13 files changed

+1155
-151
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "pip"
3+
- package-ecosystem: "uv"
44
directory: "/"
55
schedule:
6-
interval: "daily"
6+
interval: "weekly"
77
target-branch: "main"
88
commit-message:
99
prefix: ""
1010
include: "scope"
1111

1212
- package-ecosystem: "github-actions"
13-
# Workflow files stored in the
14-
# default location of `.github/workflows`
13+
# Workflow files stored in the default location of `.github/workflows`
1514
directory: "/"
1615
schedule:
1716
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,46 @@ on: [ push, pull_request ]
44

55
jobs:
66
test:
7-
name: Python ${{ matrix.python-version }}
7+
name: Tests
88
runs-on: ubuntu-latest
9-
strategy:
10-
max-parallel: 4
11-
matrix:
12-
python-version: [ "3.10", "3.11" ]
139

10+
# Code based on https://docs.astral.sh/uv/guides/integration/github/
1411
steps:
15-
- uses: actions/checkout@v4
12+
- name: Check out Git repository
13+
uses: actions/checkout@v5
1614

17-
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v5
15+
- name: Set up Python
16+
uses: actions/setup-python@v6
1917
with:
20-
python-version: ${{ matrix.python-version }}
21-
cache: "pip"
22-
cache-dependency-path: "requirements*.txt"
18+
python-version-file: "pyproject.toml"
2319

2420
- name: Install System Dependencies
25-
# Retries installing files 3 times, as the GitHub Actions CI is occasionally unreliable
21+
# Retries installing files 3 times, as either the GitHub Actions runner or APT's API can be unreliable
2622
run: |
2723
sudo apt update
2824
sudo apt install python3-dev libldap2-dev libsasl2-dev libssl-dev -o Acquire::Retries=3
2925
30-
- name: Install Python Dependencies
31-
run: |
32-
python -m pip install --upgrade pip
33-
pip install -r requirements.txt
34-
pip install -r requirements_codecov.txt
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v6
28+
with:
29+
enable-cache: true
30+
31+
- name: Set `UV_PROJECT_ENVIRONMENT` envvar
32+
# Install packages into the system environment instead of a `.venv/`.
33+
# (`pythonLocation` is from `actions/setup-python` - see
34+
# https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#environment-variables)
35+
run: echo "UV_PROJECT_ENVIRONMENT=$pythonLocation" >> $GITHUB_ENV
36+
- name: Install Python dependencies
37+
run: uv sync --locked --group ci
3538

3639
- name: Run Django Tests
3740
run: |
38-
python manage.py collectstatic --no-input
39-
coverage run manage.py test
40-
coverage xml
41+
uv run manage.py collectstatic --no-input
42+
uv run coverage run manage.py test
43+
uv run coverage xml
4144
4245
- name: Upload to Codecov
4346
uses: codecov/codecov-action@v3
4447
with:
4548
token: ${{ secrets.CODECOV_TOKEN }}
4649
file: ./coverage.xml
47-
48-
# Based on https://github.com/orgs/community/discussions/26822#discussioncomment-5122101
49-
test-results:
50-
name: Tests passed
51-
runs-on: ubuntu-latest
52-
needs: [test]
53-
if: ${{ always() }}
54-
55-
steps:
56-
- if: >- # Starts a multiline string (see https://stackoverflow.com/a/67532120)
57-
${{
58-
contains(needs.*.result, 'failure')
59-
|| contains(needs.*.result, 'cancelled')
60-
}}
61-
run: exit 1

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Lastly, a new [release](https://github.com/MAKENTNU/web/releases) must be create
3030
- Deleted the `dev` branch; now, the `main` branch will be used as the (sole) default branch, and releases/tags will be used for deployments
3131
(MAKENTNU/web#758)
3232
- Prevented `compilemessages` from processing files outside the `src` folder (MAKENTNU/web#766)
33+
- Migrated project to use the more modern `pyproject.toml` and [uv](https://docs.astral.sh/uv/) instead of `requirements.txt` and pip
34+
(MAKENTNU/web#766)
3335

3436

3537
## 2025-05-03 (MAKENTNU/web#757)

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
FROM python:3.11
22
ENV PYTHONUNBUFFERED 1
33
RUN apt update --fix-missing && apt install -y python3-dev libldap2-dev libsasl2-dev libssl-dev gettext libgettextpo-dev
4+
RUN python -m pip install --upgrade pip
5+
RUN pipx install uv
46
RUN mkdir /web
57
WORKDIR /web
6-
COPY requirements.txt /web/
7-
RUN python -m pip install --upgrade pip
8-
RUN pip install -r requirements.txt
8+
COPY pyproject.toml uv.lock /web/
9+
RUN uv sync --locked

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
run:
2-
python manage.py runserver 0.0.0.0:8000
2+
uv run manage.py runserver 0.0.0.0:8000
33

44
migrations:
5-
python manage.py makemigrations ${A}
5+
uv run manage.py makemigrations ${A}
66

77
migrate:
8-
python manage.py migrate
8+
uv run manage.py migrate
99

1010
superuser:
11-
python manage.py createsuperuser
11+
uv run manage.py createsuperuser
1212

1313
startapp:
14-
python manage.py startapp
14+
uv run manage.py startapp
1515

1616
shell:
17-
python manage.py shell
17+
uv run manage.py shell
1818

1919
test:
20-
python manage.py test
20+
uv run manage.py test

README.md

Lines changed: 37 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@
33
[![codecov](https://codecov.io/gh/MAKENTNU/web/graph/badge.svg?token=EL6fslS1y2)](https://codecov.io/gh/MAKENTNU/web)
44

55

6-
## Setup
6+
## 🛠️ Setup
77

88
<details>
99
<summary>Click to expand</summary>
1010

11-
### Prerequisites
12-
13-
* [Git](https://git-scm.com/downloads)
14-
* Using a [Git GUI](https://git-scm.com/downloads/guis) is highly recommended, as they allow for much easier and faster visualization of the commit
15-
structure, and interaction with it, which will help you avoid many common mistakes
16-
* [Git Extensions](https://gitextensions.github.io/) is a good choice - though it only runs on Windows, as of time of writing
17-
* Python **3.10**+ (latest, stable version preferred)
18-
* Having cloned this repository to your machine
19-
* Either press a "Clone repository" button in your Git GUI, or run:
20-
```shell
21-
git clone https://github.com/MAKENTNU/web.git
22-
```
11+
1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/) (a Python package manager)
12+
1. [Install Git](https://git-scm.com/downloads)
13+
1. Installing a [Git GUI](https://git-scm.com/downloads/guis) is highly recommended, as they allow for much easier and faster visualization of
14+
the commit structure, and interaction with it, which will help you avoid many common mistakes
15+
* [Git Extensions](https://gitextensions.github.io/) is an excellent choice, with support for pretty much all Git features you'll ever use - though
16+
it only runs on Windows, as of time of writing
17+
* [GitHub Desktop](https://github.com/apps/desktop) works well, but has very limited functionality
18+
1. Clone this repository to your machine
19+
* Either press a "Clone repository" button in your Git GUI, or run:
20+
```shell
21+
git clone https://github.com/MAKENTNU/web.git
22+
```
23+
1. Install dev dependencies:
24+
(this will create a `.venv` folder inside your repository folder, by default)
25+
```shell
26+
uv sync --group dev
27+
```
2328

2429
#### PyCharm
2530

@@ -28,66 +33,25 @@ and because it's able to integrate all the IntelliJ-specific settings in [the pr
2833

2934
If you decide to use this IDE, open the repo folder cloned as part of the prerequisites, through PyCharm (File → Open...),
3035
and set the following settings (File → Settings...):
31-
* Under "**Languages & Frameworks**""Django":
36+
* Under "**Python**""Django":
3237
* Make sure the "Enable Django Support" checkbox is checked
3338
* "Django project root:" `<repo folder location>/src`
3439
* "Settings:" `web/settings.py`
3540
* "Manage script:" `<repo folder location>/manage.py`
36-
* Under "**Project: \<repo folder name\>**""Project Structure":
41+
* Under "**Project Structure**":
3742
* Mark the `src` folder as "Sources"
43+
* Follow [these instructions](https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#-r16mz0_87)
44+
to add the _existing_ uv environment that you created inside the `.venv` folder
3845

39-
### Installation
40-
41-
1. Create a virtual environment, presumably named `venv`:
42-
* This should be placed in the folder *containing* the project folder, and not inside the project folder itself
43-
* Example folder structure (where `web` is the name of the project folder):
44-
```
45-
MAKE
46-
├─ venv
47-
└─ web
48-
└─ README.md (this file)
49-
```
50-
* Among other things, this prevents translations from being made inside the virtual environment folder
51-
when running the `makemessages` management command
52-
* If using PyCharm, and a virtual environment was not created as part of the project creation process, refer to
53-
[the "Configure a virtual environment" guide](https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html#python_create_virtual_env)
54-
* Otherwise, `cd` to the project folder, and run:
55-
```shell
56-
[newest installed Python command, like python3.11] -m venv ../venv
57-
```
58-
1. Activate the virtual environment:
59-
* If using PyCharm, this should be done automatically when opening a terminal tab inside the IDE
60-
* Otherwise, `cd` to the project folder, and run:
61-
* On Windows:
62-
```shell
63-
..\venv\Scripts\activate
64-
```
65-
* On Linux/macOS:
66-
```shell
67-
source ../venv/bin/activate
68-
```
69-
1. Install requirements:
70-
* If using Windows, first download the correct wheel for the [`python-ldap`](https://pypi.org/project/python-ldap/) package
71-
from [Christoph Gohlke](https://github.com/cgohlke)'s [python-ldap-build repository](https://github.com/cgohlke/python-ldap-build).
72-
and install it:
73-
```shell
74-
pip install [path to .whl file]
75-
```
76-
(It is possible to instead build `python-ldap` from source, but it's a bit cumbersome setting up the right build tools.)
77-
* Regardless of operating system, run:
78-
```shell
79-
pip install -r requirements.txt
80-
```
81-
82-
### Running the server for the first time
46+
### 🚀 Starting the webserver
8347

8448
1. Create an SQLite database file with the proper tables:
8549
```shell
86-
python manage.py migrate
50+
uv run manage.py migrate
8751
```
8852
1. Create an admin user for local development:
8953
```shell
90-
python manage.py createsuperuser
54+
uv run manage.py createsuperuser
9155
```
9256
It's easiest to create one with both the username and the password set to "admin", and with no email address.
9357
1. Run the server:
@@ -96,23 +60,31 @@ and set the following settings (File → Settings...):
9660
which by default should be named "web" and have a tiny Django logo
9761
* Otherwise, run:
9862
```shell
99-
python manage.py runserver [optional port number; defaults to 8000]
63+
uv run manage.py runserver
10064
```
65+
66+
### 🧳 Developing offline
67+
68+
When running uv commands, pass [the `--offline` flag](https://docs.astral.sh/uv/reference/cli/#uv-run--offline).
69+
For example:
70+
```shell
71+
uv run --offline manage.py runserver
72+
```
10173
</details>
10274
10375
104-
## Contribution guidelines
76+
## 🧑‍💻 Contribution guidelines
10577
10678
See [CONTRIBUTING.md](CONTRIBUTING.md) for the following topics:
10779
* [Code style guides](CONTRIBUTING.md#code-style-guides)
10880
* [Code review guideline: Code smells](CONTRIBUTING.md#code-review-guideline-code-smells)
10981
11082
111-
## [Wiki](https://github.com/MAKENTNU/web/wiki)
83+
## 📖 [Wiki](https://github.com/MAKENTNU/web/wiki)
11284
[Visit the wiki](https://github.com/MAKENTNU/web/wiki) to read about various things related to development of this project!
11385
11486
115-
## Changelog
87+
## 📝 Changelog
11688
11789
[View the changelog](CHANGELOG.md) to see a list of changes made to the website over time,
11890
as well as a superficial description of the release process.

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ services:
44
web:
55
build: .
66
command: >
7-
bash -c "python manage.py migrate
8-
&& python manage.py runserver 0.0.0.0:8000"
7+
bash -c "uv run manage.py migrate
8+
&& uv run manage.py runserver 0.0.0.0:8000"
99
volumes:
1010
- ./:/web
1111
ports:

pyproject.toml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[project]
2+
name = "web"
3+
requires-python = "==3.11.*"
4+
5+
classifiers = [
6+
"Programming Language :: Python :: 3 :: Only",
7+
"Programming Language :: Python :: 3.11",
8+
]
9+
dynamic = [ "version" ]
10+
11+
dependencies = [
12+
# Django-related packages
13+
"Django==5.0.2",
14+
"django-hosts==6.0",
15+
"django-ckeditor==6.7.0",
16+
"django-cleanup==8.1.0",
17+
"django-constance==3.1.0",
18+
"django-decorator-include==3.0",
19+
# (See this page for a list of all management commands:
20+
# https://django-extensions.readthedocs.io/en/latest/command_extensions.html)
21+
"django-extensions==3.2.3",
22+
"django-ical==1.9.2",
23+
"django-multiselectfield==0.1.12",
24+
"django-phonenumber-field[phonenumbers]==7.3.0",
25+
"django-simple-history==3.5.0",
26+
"sorl-thumbnail==12.10.0",
27+
28+
# Packages related to authentication and other "social" stuff
29+
"social-auth-app-django==5.4.1",
30+
# This is already a requirement of `social-auth-app-django`, but it's listed here
31+
# to provide the `openidconnect` extra - see
32+
# https://python-social-auth.readthedocs.io/en/stable/installing.html#using-the-extras-options
33+
"social-auth-core[openidconnect]==4.4.2",
34+
"python-ldap==3.4.4",
35+
36+
# Async-related packages (mainly for sending of emails)
37+
"channels[daphne]==4.1.0",
38+
"channels-redis==4.2.0",
39+
40+
# Misc. packages
41+
"bleach[css]==6.1.0",
42+
"Pillow==11.3.0",
43+
"uuid==1.30",
44+
"XlsxWriter==3.2.0",
45+
]
46+
47+
[dependency-groups]
48+
dev = [
49+
"django-debug-toolbar==6.0.0",
50+
]
51+
ci = [
52+
"coverage==7.10.6",
53+
]
54+
55+
[tool.uv]
56+
# Don't install `dev` by default (see
57+
# https://docs.astral.sh/uv/concepts/projects/dependencies/#default-groups), to make it
58+
# easier to *not* install those dependencies in prod
59+
default-groups = [ ]
60+
61+
[tool.uv.sources]
62+
python-ldap = [
63+
# Christoph Gohlke distributes pre-compiled binaries of various Python packages,
64+
# among others: https://github.com/cgohlke/python-ldap-build/releases.
65+
# The library version must match the version selected under the `dev`
66+
# dependency group, and the `cp3xx` version must match `requires-python`.
67+
# URL found at https://github.com/cgohlke/python-ldap-build/releases/tag/v3.4.4-2
68+
{ url = "https://github.com/cgohlke/python-ldap-build/releases/download/v3.4.4-2/python_ldap-3.4.4-cp311-cp311-win_amd64.whl", marker = "sys_platform == 'win32'" },
69+
]

0 commit comments

Comments
 (0)