Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.13
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.13
python-version: "3.13.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- name: Install uv
id: setup-uv
uses: astral-sh/setup-uv@v6
with:
version: "0.7.19"
enable-cache: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt && pip install -r requirements_test.txt && pip install ruff
if: steps.setup-uv.outputs.cache-hit != 'true'
run: uv sync
- name: Run ruff
run: |
ruff check .
uv run ruff check .
- name: Lint with flake8
run: |
make lint
Expand Down
11 changes: 5 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
image: "archlinux:latest"

before_script:
- pacman -Syu --needed --noconfirm python-pip git
- pip install coverage flake8
- pip install -r requirements.txt
- python manage.py collectstatic --noinput
- pacman -Syu --needed --noconfirm git uv
- uv sync
- uv run python manage.py collectstatic --noinput

lint:
script:
- flake8 --exclude "*/migrations/" devel main mirrors news packages releng templates todolists visualize *.py
- uv run flake8 --exclude "*/migrations/" devel main mirrors news packages releng templates todolists visualize *.py

# TODO: https://docs.gitlab.com/ee/ci/junit_test_reports.html
test:
script:
- coverage run --rcfile .coveragerc manage.py test
- uv run coverage run --rcfile .coveragerc manage.py test
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ test-pdb: test
.PHONY: test lint coverage

lint:
flake8 --extend-exclude "*/migrations/,local_settings.py" devel main mirrors news packages releng templates todolists visualize *.py
uv run flake8 --extend-exclude "*/migrations/,local_settings.py" devel main mirrors news packages releng templates todolists visualize *.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should re-evaluate if ruff already has the formatting rules, or ugh ruff format I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruff actually replaces flake8, so we can technically get rid of this and have one tool to handle formatting/linting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"replaces", not entirely most of the E1 rules are not yet implemented and if implemented are preview rules.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, this will be handled in a follow up by moving to ruff format


collectstatic:
python manage.py collectstatic --noinput
uv run python manage.py collectstatic --noinput

test: test-py

test-py coverage:
DJANGO_SETTINGS_MODULE=settings ${PYTEST} ${PYTEST_OPTIONS} ${PYTEST_COVERAGE_OPTIONS} ${PYTEST_INPUT}
DJANGO_SETTINGS_MODULE=settings uv run ${PYTEST} ${PYTEST_OPTIONS} ${PYTEST_COVERAGE_OPTIONS} ${PYTEST_INPUT}

open-coverage: coverage
${BROWSER} htmlcov/index.html
53 changes: 18 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ See AUTHORS file.

# Dependencies

- python
- Python 3.13.0
- UV
- rsync (optional for mirrorcheck with rsync mirrors)

# Python dependencies

More detail in `requirements.txt` and `requirements_prod.txt`; it is best to
use virtualenv and pip to handle these. But if you insist on (Arch Linux)
packages, you will probably want the following:
You can look at the packages `archweb` uses by looking at the `pyproject.toml` file;
it is best to use `uv` to handle these. If you insist on (Archlinux) packages, you
probably want the following:

- python-django
- python-psycopg2
Expand All @@ -32,45 +33,31 @@ packages, you will probably want the following:

# Testing Installation

1. Run `python -m venv env`.

cd /path/to/archweb && python -m venv ./env/

1. Run `uv sync`.
2. Activate the virtualenv.

source ./env/bin/activate

2. Install dependencies through `pip`.

pip install -r requirements.txt

3. Copy `local_settings.py.example` to `local_settings.py` and modify.
Make sure to uncomment the appropriate database section (either sqlite or
PostgreSQL).

4. Migrate changes.

./manage.py migrate

uv run ./manage.py migrate
5. Load the fixtures to pre populate some data. If you don't want some of the
provided data, adjust the file glob accordingly.

./manage.py loaddata main/fixtures/*.json
./manage.py loaddata devel/fixtures/*.json
./manage.py loaddata mirrors/fixtures/*.json
./manage.py loaddata releng/fixtures/*.json

uv run ./manage.py loaddata main/fixtures/*.json
uv run ./manage.py loaddata devel/fixtures/*.json
uv run ./manage.py loaddata mirrors/fixtures/*.json
uv run ./manage.py loaddata releng/fixtures/*.json
6. Use the following commands to start a service instance

./manage.py runserver

uv ./manage.py runserver
7. To optionally populate the database with real data:

wget http://mirrors.kernel.org/archlinux/core/os/x86_64/core.db.tar.gz
./manage.py reporead x86_64 core.db.tar.gz
uv run ./manage.py reporead x86_64 core.db.tar.gz
# Package file listing
wget http://mirrors.kernel.org/archlinux/core/os/x86_64/core.files.tar.gz
./manage.py reporead --filesonly x86_64 core.files.tar.gz
uv run ./manage.py reporead --filesonly x86_64 core.files.tar.gz

Alter architecture and repo to get x86\_64 and packages from other repos if
needed.
Expand All @@ -87,24 +74,20 @@ For PostgreSQL use packages/sql/update.postgresql_psycopg2.sql
To be able to create an account on your test environment an SMTP server is
required. A simple debugging SMTP server can be setup using Python and `aiosmtpd`.

Install `aiosmtpd`
Install `smtp` group

pip install aiosmtpd
uv sync --group smtp

Run the server

python -m aiosmtpd -n -l localhost:1025
uv run python -m aiosmtpd -n -l localhost:1025

In local\_settings.py add entries to set EMAIL\_HOST to 'localhost' and EMAIL\_PORT to
1025.

# Running tests and coverage

Install the test dependencies:

pip install -r requirements_test.txt

To the unittests execute the following commands:
To run unittests execute the following commands:

make collectstatic
make test
Expand Down
3 changes: 1 addition & 2 deletions main/storage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import cssmin
import jsmin
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
from django.core.files.base import ContentFile
from django.utils.encoding import smart_str

import cssmin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruff check . is happy for me, why is the uv used ruff not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be that you are running a different version of ruff? We are installing the latest in the CI:

pip install -r requirements.txt && pip install -r requirements_test.txt && pip install ruff

This is one of the benefits of managing dependencies with uv, since we are now locking a particular version and making sure we always run that version, without having a separate requirements for each group.



class MinifiedStaticFilesStorage(ManifestStaticFilesStorage):
"""
Expand Down
2 changes: 1 addition & 1 deletion mirrors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def dictfetchall(cursor):
"Returns all rows from a cursor as a dict."
desc = cursor.description
return [
dict(zip([col[0] for col in desc], row))
dict(zip([col[0] for col in desc], row, strict=False))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a place where strict=True seems fine to use.

for row in cursor.fetchall()
]

Expand Down
56 changes: 50 additions & 6 deletions ruff.toml → pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
[project]
name = "archweb"
version = "0.1.0"
description = "Archlinux website code"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arch Linux ;-)

readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"bencode-py==4.0.0",
"bleach==6.0.0",
"django==5.1.10",
"django-countries==7.6.1",
"django-csp==4.0",
"django-extensions==4.1",
"django-prometheus==2.3.1",
"feedparser==6.0.11",
"ipy==1.1",
"jsmin==3.0.1",
"markdown==3.3.7",
"parse==1.20.2",
"pgpdump==1.5",
"ptpython==2.0.4",
"requests==2.32.4",
"sqlparse==0.5.0",
"xtarfile==0.2.1",
"zstandard==0.23.0",
]

[dependency-groups]
dev = [
"flake8>=7.3.0",
"pytest>=8.4.1",
"pytest-cov>=6.2.1",
"pytest-django>=4.11.1",
"ruff>=0.12.11",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

venv managed ruff :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will still be in venv. uv will only install this when we install dev dependencies (enabled by default). Before, we had to install this separately with pip.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but I prefer system linters ;-)

]
prod = [
"pyasyncore==1.0.4",
"pyinotify==0.9.6",
"pymemcache==3.5.0",
]
smtp = [
"aiosmtpd>=1.4.6",
]

[tool.ruff]
line-length = 118
exclude = [
"*/migrations/*.py", # Ignore Django migrations
"src/cssmin/*" # cssmin, not our code
]

[lint]
[tool.ruff.lint]
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
Expand Down Expand Up @@ -33,8 +82,3 @@ ignore = [
"DJ008", # Model does not define `__str__` method
"DJ012", # Order of model's inner classes, methods, and fields does not follow the Django Style Guide: `Meta` class should come before `get_absolute_url`
]

exclude = [
"*/migrations/*.py", # Ignore Django migrations
"src/cssmin/*" # cssmin, not our code
]
19 changes: 0 additions & 19 deletions requirements.txt

This file was deleted.

4 changes: 0 additions & 4 deletions requirements_prod.txt

This file was deleted.

4 changes: 0 additions & 4 deletions requirements_test.txt

This file was deleted.

Loading