Skip to content

Commit 90da7f5

Browse files
committed
Lint
1 parent 13eb87f commit 90da7f5

File tree

228 files changed

+542
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+542
-551
lines changed

fabfile.py

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import datetime
22
import os
33
import subprocess
4+
45
from shlex import quote
56

67
from invoke import run as local
78
from invoke.tasks import task
89

10+
911
# Process .env file
1012
if os.path.exists(".env"):
1113
with open(".env") as f:
@@ -135,15 +137,11 @@ def psql(c, command=None):
135137
@task
136138
def delete_docker_database(c, local_database_name=LOCAL_DATABASE_NAME):
137139
dexec(
138-
"dropdb --if-exists --host db --username={project_name} {database_name}".format(
139-
project_name=PROJECT_NAME, database_name=LOCAL_DATABASE_NAME
140-
),
140+
f"dropdb --if-exists --host db --username={PROJECT_NAME} {LOCAL_DATABASE_NAME}",
141141
"db",
142142
)
143143
dexec(
144-
"createdb --host db --username={project_name} {database_name}".format(
145-
project_name=PROJECT_NAME, database_name=LOCAL_DATABASE_NAME
146-
),
144+
f"createdb --host db --username={PROJECT_NAME} {LOCAL_DATABASE_NAME}",
147145
"db",
148146
)
149147
psql(c, "CREATE SCHEMA heroku_ext;")
@@ -158,12 +156,8 @@ def import_data(c, database_filename):
158156
delete_docker_database(c)
159157
# Import the database file to the db container
160158
dexec(
161-
"pg_restore --clean --no-acl --if-exists --no-owner --host db \
162-
--username={project_name} -d {database_name} {database_filename}".format(
163-
project_name=PROJECT_NAME,
164-
database_name=LOCAL_DATABASE_NAME,
165-
database_filename=database_filename,
166-
),
159+
f"pg_restore --clean --no-acl --if-exists --no-owner --host db \
160+
--username={PROJECT_NAME} -d {LOCAL_DATABASE_NAME} {database_filename}",
167161
service="db",
168162
)
169163
print(
@@ -273,12 +267,8 @@ def delete_local_database(c, local_database_name=LOCAL_DATABASE_NAME):
273267

274268
def aws(c, command, aws_access_key_id, aws_secret_access_key):
275269
return local(
276-
"AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_key} "
277-
"aws {command}".format(
278-
access_key_id=aws_access_key_id,
279-
secret_key=aws_secret_access_key,
280-
command=command,
281-
)
270+
f"AWS_ACCESS_KEY_ID={aws_access_key_id} AWS_SECRET_ACCESS_KEY={aws_secret_access_key} "
271+
f"aws {command}"
282272
)
283273

284274

@@ -289,10 +279,7 @@ def pull_media_from_s3(
289279
aws_storage_bucket_name,
290280
local_media_dir=LOCAL_MEDIA_DIR,
291281
):
292-
aws_cmd = "s3 sync --delete s3://{bucket_name} {local_media}".format(
293-
bucket_name=aws_storage_bucket_name,
294-
local_media=local_media_dir,
295-
)
282+
aws_cmd = f"s3 sync --delete s3://{aws_storage_bucket_name} {local_media_dir}"
296283
aws(c, aws_cmd, aws_access_key_id, aws_secret_access_key)
297284

298285

@@ -316,11 +303,7 @@ def pull_images_from_s3(
316303
aws_storage_bucket_name,
317304
local_images_dir=LOCAL_IMAGES_DIR,
318305
):
319-
aws_cmd = (
320-
"s3 sync --delete s3://{bucket_name}/original_images {local_media}".format(
321-
bucket_name=aws_storage_bucket_name, local_media=local_images_dir
322-
)
323-
)
306+
aws_cmd = f"s3 sync --delete s3://{aws_storage_bucket_name}/original_images {local_images_dir}"
324307
aws(c, aws_cmd, aws_access_key_id, aws_secret_access_key)
325308
# The above command just syncs the original images, so we need to drop the wagtailimages_renditions
326309
# table so that the renditions will be re-created when requested on the local build.
@@ -349,18 +332,13 @@ def pull_database_from_heroku(c, app_instance, anonymise=False):
349332
datestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
350333

351334
local(
352-
"heroku pg:backups:download --output={dump_folder}/{datestamp}.dump --app {app}".format(
353-
app=app_instance, dump_folder=LOCAL_DUMP_DIR, datestamp=datestamp
354-
),
335+
f"heroku pg:backups:download --output={LOCAL_DUMP_DIR}/{datestamp}.dump --app {app_instance}",
355336
)
356337

357338
import_data(c, f"/app/{LOCAL_DUMP_DIR}/{datestamp}.dump")
358339

359340
local(
360-
"rm {dump_folder}/{datestamp}.dump".format(
361-
dump_folder=LOCAL_DUMP_DIR,
362-
datestamp=datestamp,
363-
),
341+
f"rm {LOCAL_DUMP_DIR}/{datestamp}.dump",
364342
)
365343

366344
if anonymise:
@@ -392,13 +370,9 @@ def make_bold(msg):
392370
def dellar_snapshot(c, filename):
393371
"""Snapshot the database, files will be stored in the db container"""
394372
dexec(
395-
"pg_dump -d {database_name} -U {database_username} > {filename}.psql".format(
396-
database_name=LOCAL_DATABASE_NAME,
397-
database_username=LOCAL_DATABASE_USERNAME,
398-
filename=filename,
399-
),
373+
f"pg_dump -d {LOCAL_DATABASE_NAME} -U {LOCAL_DATABASE_USERNAME} > {filename}.psql",
400374
service="db",
401-
),
375+
)
402376
print("Database snapshot created")
403377

404378

@@ -407,14 +381,12 @@ def dellar_restore(c, filename):
407381
"""Restore the database from a snapshot in the db container"""
408382
delete_docker_database(c)
409383

410-
dexec(
411-
"psql -U {database_username} -d {database_name} < {filename}.psql".format(
412-
database_name=LOCAL_DATABASE_NAME,
413-
database_username=LOCAL_DATABASE_USERNAME,
414-
filename=filename,
384+
(
385+
dexec(
386+
f"psql -U {LOCAL_DATABASE_USERNAME} -d {LOCAL_DATABASE_NAME} < {filename}.psql",
387+
service="db",
415388
),
416-
service="db",
417-
),
389+
)
418390
print("Database restored.")
419391

420392

@@ -424,10 +396,10 @@ def dellar_list(c):
424396
print("Database snapshots:")
425397
dexec(
426398
"""for f in *.psql; do
427-
printf ' - %s\n' "${f%.psql}"
428-
done""",
399+
printf ' - %s\n' "${f%.psql}"
400+
done""",
429401
service="db",
430-
),
402+
)
431403
print("Restore with `dellar-restore <snapshot>`")
432404

433405

@@ -437,7 +409,7 @@ def dellar_remove(c, filename):
437409
dexec(
438410
f"rm {filename}.psql",
439411
service="db",
440-
),
412+
)
441413
print(f"Snapshot {filename} removed")
442414

443415

gunicorn-conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Replace gunicorn's 'Server' HTTP header to avoid leaking info to attackers
22
import gunicorn
33

4+
45
gunicorn.SERVER_SOFTWARE = ""

manage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44

5+
56
if __name__ == "__main__":
67
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tbx.settings.production")
78

ruff.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ extend-ignore = [
2525
]
2626
fixable = ["C4", "E", "F", "I", "UP"]
2727

28+
[lint.per-file-ignores]
29+
"fabfile.py" = ["S603", "S607", "T201"]
30+
"tbx/core/utils/scripts/run_flightpath.py" = ["T201"]
31+
"tbx/core/utils/scripts/run_flightpath_status_check.py" = ["T201"]
32+
2833
[lint.isort]
2934
known-first-party = ["tbx"]
3035
lines-between-types = 1

tbx/blog/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import factory
22
import wagtail_factories
3+
34
from tbx.blog.models import BlogIndexPage, BlogPage
45
from tbx.core.factories import StoryBlockFactory
56

tbx/blog/feeds.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from datetime import datetime, time
22

3-
from django.contrib.syndication.views import Feed
4-
53
import filetype
64

5+
from django.contrib.syndication.views import Feed
6+
77
from .models import BlogPage
88

9+
910
# Main blog feed
1011

1112

tbx/blog/migrations/0001_initial.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# Generated by Django 4.2.8 on 2024-01-02 10:49
22

3-
from django.db import migrations, models
43
import django.db.models.deletion
54
import modelcluster.fields
6-
import tbx.core.blocks
75
import wagtail.blocks
86
import wagtail.embeds.blocks
97
import wagtail.fields
108
import wagtail.images.blocks
119
import wagtailmarkdown.blocks
1210
import wagtailmedia.blocks
1311

12+
from django.db import migrations, models
13+
14+
import tbx.core.blocks
1415

15-
class Migration(migrations.Migration):
1616

17+
class Migration(migrations.Migration):
1718
initial = True
1819

1920
dependencies = [

tbx/blog/migrations/0002_remove_blogindexpage_call_to_action_and_more.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# Generated by Django 4.2.9 on 2024-01-15 10:16
22

3-
from django.db import migrations
4-
import tbx.core.blocks
53
import wagtail.blocks
64
import wagtail.embeds.blocks
75
import wagtail.fields
86
import wagtail.images.blocks
97
import wagtailmarkdown.blocks
108
import wagtailmedia.blocks
119

10+
from django.db import migrations
11+
12+
import tbx.core.blocks
1213

13-
class Migration(migrations.Migration):
1414

15+
class Migration(migrations.Migration):
1516
dependencies = [
1617
("blog", "0001_initial"),
1718
]

tbx/blog/migrations/0003_add_new_image_block_to_body_streamfield.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Generated by Django 4.2.9 on 2024-01-15 11:14
22

3-
from django.db import migrations
43
import wagtail.blocks
54
import wagtail.embeds.blocks
65
import wagtail.fields
76
import wagtail.images.blocks
87
import wagtailmarkdown.blocks
98
import wagtailmedia.blocks
109

10+
from django.db import migrations
11+
1112

1213
class Migration(migrations.Migration):
13-
1414
dependencies = [
1515
("blog", "0002_remove_blogindexpage_call_to_action_and_more"),
1616
]

tbx/blog/migrations/0003_alter_blogpage_body.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# Generated by Django 4.2.9 on 2024-01-15 12:25
22

3-
from django.db import migrations
4-
import tbx.core.blocks
53
import wagtail.blocks
64
import wagtail.embeds.blocks
75
import wagtail.fields
86
import wagtail.images.blocks
97
import wagtailmarkdown.blocks
108
import wagtailmedia.blocks
119

10+
from django.db import migrations
11+
12+
import tbx.core.blocks
1213

13-
class Migration(migrations.Migration):
1414

15+
class Migration(migrations.Migration):
1516
dependencies = [
1617
("blog", "0002_remove_blogindexpage_call_to_action_and_more"),
1718
]

0 commit comments

Comments
 (0)