Skip to content

Commit 978d215

Browse files
committed
Switch to TOML file and ruff.
1 parent 4f1f3c8 commit 978d215

30 files changed

+124
-231
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ jobs:
3333
with:
3434
python-version: ${{ matrix.python-version }}
3535
cache: pip
36-
cache-dependency-path: 'requirements.txt'
36+
cache-dependency-path: 'pyproject.toml'
3737

3838
- name: Install dependencies
3939
run: |
4040
python -m pip install --upgrade pip setuptools wheel
41-
python -m pip install -r requirements.txt
41+
python -m pip install .
4242
4343
- name: Run tests
4444
run: |

.pre-commit-config.yaml

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,30 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- id: mixed-line-ending
9-
- repo: https://github.com/pycqa/flake8
10-
rev: 4.0.1
9+
- repo: https://github.com/astral-sh/ruff-pre-commit
10+
rev: v0.9.4
1111
hooks:
12-
- id: flake8
12+
- id: ruff
13+
args: [--fix]
14+
- id: ruff-format
1315
- repo: https://github.com/pycqa/doc8
14-
rev: 0.11.2
16+
rev: v1.1.2
1517
hooks:
1618
- id: doc8
17-
- repo: https://github.com/asottile/pyupgrade
18-
rev: v2.34.0
19-
hooks:
20-
- id: pyupgrade
21-
args: [--py38-plus]
2219
- repo: https://github.com/adamchainz/django-upgrade
23-
rev: 1.7.0
20+
rev: 1.22.2
2421
hooks:
2522
- id: django-upgrade
26-
args: [--target-version, "3.2"]
27-
- repo: https://github.com/pycqa/isort
28-
rev: 5.10.1
29-
hooks:
30-
- id: isort
23+
args: [--target-version, "5.0"]
3124
- repo: https://github.com/pre-commit/pygrep-hooks
32-
rev: v1.9.0
25+
rev: v1.10.0
3326
hooks:
3427
- id: python-check-blanket-noqa
3528
- id: python-check-mock-methods
3629
- id: python-no-eval
3730
- id: python-no-log-warn
38-
- repo: https://github.com/psf/black
39-
rev: 22.3.0
40-
hooks:
41-
- id: black
42-
language_version: python3
43-
entry: black --target-version=py38

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ warning. Do what's comfortable.
7878

7979
If not, I highly recommend using the Windows Subsystem for Linux
8080
([docs](https://learn.microsoft.com/en-us/windows/wsl/about)). If you do, the
81-
rest of the instructions will work for you. If you don't have access to that,
81+
rest of the instructions will work for you. If you don't have access to that,
8282
please scroll down to [Windows non-WSL Setup](#windows-non-wsl-setup).
8383

8484
---
@@ -95,7 +95,7 @@ please scroll down to [Windows non-WSL Setup](#windows-non-wsl-setup).
9595
```
9696
3. Install the project dependencies.
9797
```shell
98-
pip install -r requirements.txt
98+
pip install -e .
9999
```
100100
4. Create a new .env file.
101101
```shell
@@ -151,7 +151,7 @@ Proceed to [Lab 1](docs/lab1.md).
151151
```
152152
3. Install the project dependencies.
153153
```shell
154-
pip install -r requirements.txt
154+
pip install -e .
155155
```
156156
4. Create a new .env file.
157157
```shell

docs/lab1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ If you've gone through all the steps of the investigation, and you're still unsu
168168
file isn't being shared, you should read about the
169169
[``enctype`` attribute of forms](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/form#enctype).
170170

171-
You'll see that the
171+
You'll see that the
172172

173173
By default, a ``<form>`` element will use ``enctype="application/x-www-form-urlencoded"``.
174174
However, as we found, that will not submit any ``<input type="file" />`` (or other file-based

docs/lab2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cache.clear()
3636
Let's consider what we know:
3737

3838
- The pages render correctly and there are no errors.
39-
- The pages rendered "fast" earlier, but over time as the data set has grown,
39+
- The pages rendered "fast" earlier, but over time as the data set has grown,
4040
they have slowed down.
4141

4242

@@ -449,7 +449,7 @@ At this point it's clear there's a difference in functionality between how
449449
``toggle_post_privacy`` and ``update_post`` save the data changes.
450450
``toggle_post_privacy`` updates the instance using a ``QuerySet.update()``
451451
call while ``update_post`` uses ``PostForm.save()`` which under the hood is
452-
doing something like ``Model.save()``. If we read
452+
doing something like ``Model.save()``. If we read
453453
[the documentation for ``update``](https://docs.djangoproject.com/en/stable/ref/models/querysets/#update)
454454
we'll see that there's a note that the ``post_save`` signal isn't emitted.
455455
This explains why ``toggle_post_privacy`` doesn't delete the cached value

manage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
"""Django's command-line utility for administrative tasks."""
3+
34
import os
45
import sys
56

project/data/management/commands/fake_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def log(event):
2121
logger.info(f"{event} - start")
2222
yield
2323
end = timezone.now()
24-
logger.info(f"{event} - end, {(end-start).total_seconds()}s")
24+
logger.info(f"{event} - end, {(end - start).total_seconds()}s")
2525

2626

2727
class Command(BaseCommand):

project/data/markdown.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timezone
1+
from datetime import UTC, datetime
22
from itertools import cycle
33

44
from faker import Faker
@@ -42,17 +42,17 @@ def generate_data(user, image_category, post_categories):
4242
slug = slugify(title) + f"-{fake.pyint(10, 99999)}"
4343
publish_at = (
4444
fake.date_time_between_dates(
45-
datetime_start=datetime(2020, 1, 1, tzinfo=timezone.utc),
46-
datetime_end=datetime(2022, 10, 12, tzinfo=timezone.utc),
47-
tzinfo=timezone.utc,
45+
datetime_start=datetime(2020, 1, 1, tzinfo=UTC),
46+
datetime_end=datetime(2022, 10, 12, tzinfo=UTC),
47+
tzinfo=UTC,
4848
)
4949
if fake.pybool()
5050
else None
5151
)
5252
created = fake.date_time_between_dates(
53-
datetime_start=datetime(2020, 1, 1, tzinfo=timezone.utc),
54-
datetime_end=datetime(2022, 10, 12, tzinfo=timezone.utc),
55-
tzinfo=timezone.utc,
53+
datetime_start=datetime(2020, 1, 1, tzinfo=UTC),
54+
datetime_end=datetime(2022, 10, 12, tzinfo=UTC),
55+
tzinfo=UTC,
5656
)
5757
if publish_at and publish_at < created:
5858
created = publish_at
@@ -89,17 +89,17 @@ def generate_data(user, image_category, post_categories):
8989
slug = slugify(title) + f"-{fake.pyint(10, 9999)}"
9090
publish_at = (
9191
fake.date_time_between_dates(
92-
datetime_start=datetime(2020, 1, 1, tzinfo=timezone.utc),
93-
datetime_end=datetime(2022, 10, 12, tzinfo=timezone.utc),
94-
tzinfo=timezone.utc,
92+
datetime_start=datetime(2020, 1, 1, tzinfo=UTC),
93+
datetime_end=datetime(2022, 10, 12, tzinfo=UTC),
94+
tzinfo=UTC,
9595
)
9696
if fake.pybool()
9797
else None
9898
)
9999
created = fake.date_time_between_dates(
100-
datetime_start=datetime(2020, 1, 1, tzinfo=timezone.utc),
101-
datetime_end=datetime(2022, 10, 12, tzinfo=timezone.utc),
102-
tzinfo=timezone.utc,
100+
datetime_start=datetime(2020, 1, 1, tzinfo=UTC),
101+
datetime_end=datetime(2022, 10, 12, tzinfo=UTC),
102+
tzinfo=UTC,
103103
)
104104
if publish_at and publish_at < created:
105105
created = publish_at

project/data/subscribers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import OrderedDict
2-
from datetime import datetime, timezone
2+
from datetime import UTC, datetime
33
from functools import partial
44

55
from django.contrib.auth.models import User
@@ -25,9 +25,9 @@ def generate_data(categories: CategoryData):
2525
)
2626
user.email = f"{user.username}@example.com"
2727
user.date_joined = fake.date_time_between_dates(
28-
datetime_start=datetime(2020, 1, 1, tzinfo=timezone.utc),
29-
datetime_end=datetime(2022, 10, 12, tzinfo=timezone.utc),
30-
tzinfo=timezone.utc,
28+
datetime_start=datetime(2020, 1, 1, tzinfo=UTC),
29+
datetime_end=datetime(2022, 10, 12, tzinfo=UTC),
30+
tzinfo=UTC,
3131
)
3232
users.append(user)
3333
User.objects.bulk_create(users, ignore_conflicts=True)
@@ -50,9 +50,9 @@ def generate_data(categories: CategoryData):
5050
for i in range(0, USER_COUNT, 50):
5151
created_map = {
5252
user_id: fake.date_time_between_dates(
53-
datetime_start=datetime(2020, 1, 1, tzinfo=timezone.utc),
54-
datetime_end=datetime(2022, 10, 12, tzinfo=timezone.utc),
55-
tzinfo=timezone.utc,
53+
datetime_start=datetime(2020, 1, 1, tzinfo=UTC),
54+
datetime_end=datetime(2022, 10, 12, tzinfo=UTC),
55+
tzinfo=UTC,
5656
)
5757
for user_id in user_ids[i : i + 50]
5858
}

project/newsletter/migrations/0001_initial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class Migration(migrations.Migration):
10-
1110
initial = True
1211

1312
dependencies = [

0 commit comments

Comments
 (0)