Skip to content

Commit

Permalink
Introduce uv and ruff formatting (#3823)
Browse files Browse the repository at this point in the history
* Use ruff for formatting

Some config changes are left to do

* Switch from poetry to uv

I dropped the Makefile because `uv run` does not require `poetry install` first,
and because I think people should be aware of manage.py.

I also bumped python to 3.13 as uv will install that for you automatically if needed.

In the Dockerfile, everything got a bit simpler, (fewer stages) because uv can run
while only being mounted, not actually written into the final image.

* Fix test workflow

* Update freezegun

* Format

* Fix randint in tests
  • Loading branch information
DeD1rk authored Nov 13, 2024
1 parent 3851a3a commit 2c3a429
Show file tree
Hide file tree
Showing 160 changed files with 2,063 additions and 3,688 deletions.
131 changes: 44 additions & 87 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,25 @@ jobs:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Setup Poetry
uses: snok/install-poetry@v1

- name: Checkout repository
uses: actions/checkout@v4

- name: Restore any cached Poetry dependencies
uses: actions/cache@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
enable-cache: true

- name: Install any new dependencies
run: poetry install
if: steps.cache.outputs.cache-hit != 'true'
- name: Set up Python
run: uv python install

- name: Run isort
run: make isortcheck
- name: Install the project
run: uv sync --frozen

- name: Run black
run: make blackcheck
- name: Run ruff check
run: uv run ruff check --output-format=github

- name: Run Ruff
run: make ruff
- name: Run ruff format
run: uv run ruff format --check

tests:
name: Django Tests
Expand All @@ -59,37 +47,37 @@ jobs:
env:
DJANGO_ENV: testing
steps:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Setup Poetry
uses: snok/install-poetry@v1

- name: Checkout repository
uses: actions/checkout@v4

- name: Restore any cached Poetry dependencies
uses: actions/cache@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
enable-cache: true

- name: Install any new dependencies
run: poetry install --with postgres
if: steps.cache.outputs.cache-hit != 'true'
- name: Set up Python
run: uv python install

- name: Install the project
run: uv sync --frozen

- name: Run checks
run: |
uv run website/manage.py check
uv run website/manage.py templatecheck --project-only
uv run website/manage.py makemigrations --no-input --check --dry-run
- name: Run tests
run: make test
run: uv run coverage run website/manage.py test website/

- name: Report coverage
run: make coverage
run: |
uv run coverage report --fail-under=100 --omit "website/registrations/urls.py" website/registrations/**.py
uv run coverage report --fail-under=100 --omit "website/payments/urls.py" website/payments/**.py
uv run coverage report
- name: Create coverage report
run: make covhtml
run: uv run coverage html --directory=covhtml --no-skip-covered --title="Coverage Report"

- name: Save coverage report
uses: actions/upload-artifact@v4
Expand All @@ -112,58 +100,27 @@ jobs:
env:
DJANGO_ENV: testing
steps:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Setup Poetry
uses: snok/install-poetry@v1

- name: Checkout repository
uses: actions/checkout@v4

- name: Restore any cached Poetry dependencies
uses: actions/cache@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
enable-cache: true

- name: Install any new dependencies
run: poetry install --with postgres
if: steps.cache.outputs.cache-hit != 'true'
- name: Set up Python
run: uv python install

- name: Run create fixtures
run: make fixtures

documentation-tests:
name: Documentation Tests
runs-on: ubuntu-latest
steps:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install the project
run: uv sync --frozen

- name: Setup Poetry
uses: snok/install-poetry@v1
- name: Migrate
run: |
uv run website/manage.py migrate
uv run website/manage.py createcachetable
- name: Checkout repository
uses: actions/checkout@v4

- name: Restore any cached Poetry dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install any new dependencies
run: poetry install
if: steps.cache.outputs.cache-hit != 'true'
- name: Run create fixtures
run: uv run website/manage.py createfixtures -a

upload-coverage:
name: Deploy Coverage Report
Expand Down
17 changes: 5 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,23 @@ dumb.rdb
celerybeat-schedule.*
db.sqlite3
*.egg-info
.ruff_cache/
.ruff_cache
.venv
.mypy_cache

website/media/
website/filepond-temp-uploads/
website/static/
covhtml/
covhtml
htmlcov
.make

# make graphs
full_models_graph.png
partial_models_graph.png

# Ignore local settings
website/thaliawebsite/settings/localsettings.py
website/.sass-cache/

# rope
.ropeproject/

# Coverage
.coverage

# venv from source_me.sh
venv/

# macOS
.DS_Store
16 changes: 2 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,8 @@ repos:
- id: name-tests-test
args: [--django]
exclude: .*/__mocks__.py
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: "23.9.1"
hooks:
- id: black
exclude: .*/migrations/.*
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.291"
rev: "v0.7.1"
hooks:
- id: ruff
- repo: https://github.com/python-poetry/poetry
rev: "1.8.2"
hooks:
- id: poetry-check
- id: ruff-format
2 changes: 0 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"recommendations": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.black-formatter",
"ms-python.isort",
"charliermarsh.ruff"
]
}
18 changes: 7 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,24 @@
//
// The same goes for the launch.json file.
{
"ruff.organizeImports": false,
"python.defaultInterpreterPath": ".venv/bin/python",
"python.analysis.autoImportCompletions": true,
"python.analysis.addImport.exactMatchOnly": true,
"python.analysis.typeCheckingMode": "off",
"python.analysis.extraPaths": [
"website"
],
"ruff.organizeImports": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.formatOnType": true,
"source.organizeImports.isort": "never",
"source.organizeImports": "explicit",
}
},
"git.branchProtection": [
"master"
],
"black-formatter.importStrategy": "fromEnvironment",
"isort.args": [
"--profile",
"black"
],
"ruff.lint.args": [
"--extend-exclude",
".pyenv"
Expand Down
Loading

0 comments on commit 2c3a429

Please sign in to comment.