Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ruff #322

Open
wants to merge 3 commits into
base: chore/deps-updates
Choose a base branch
from
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
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

19 changes: 5 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@ default_language_version:
node: system
python: python3.13
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.8.3' # keep in sync with pyproject.toml
hooks:
- id: black
language_version: python3.13
exclude: .+/migrations
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
# flake8 config is in setup.cfg
rev: 7.1.1
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: local
hooks:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ static_compiled
*.html
coverage
venv
.venv
74 changes: 23 additions & 51 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import datetime
import os
import subprocess

from shlex import quote

from invoke import run as local
from invoke.tasks import task


# Process .env file
if os.path.exists(".env"):
with open(".env") as f:
Expand Down Expand Up @@ -135,15 +137,11 @@ def psql(c, command=None):
@task
def delete_docker_database(c, local_database_name=LOCAL_DATABASE_NAME):
dexec(
"dropdb --if-exists --host db --username={project_name} {database_name}".format(
project_name=PROJECT_NAME, database_name=LOCAL_DATABASE_NAME
),
f"dropdb --if-exists --host db --username={PROJECT_NAME} {LOCAL_DATABASE_NAME}",
"db",
)
dexec(
"createdb --host db --username={project_name} {database_name}".format(
project_name=PROJECT_NAME, database_name=LOCAL_DATABASE_NAME
),
f"createdb --host db --username={PROJECT_NAME} {LOCAL_DATABASE_NAME}",
"db",
)
psql(c, "CREATE SCHEMA heroku_ext;")
Expand All @@ -158,12 +156,8 @@ def import_data(c, database_filename):
delete_docker_database(c)
# Import the database file to the db container
dexec(
"pg_restore --clean --no-acl --if-exists --no-owner --host db \
--username={project_name} -d {database_name} {database_filename}".format(
project_name=PROJECT_NAME,
database_name=LOCAL_DATABASE_NAME,
database_filename=database_filename,
),
f"pg_restore --clean --no-acl --if-exists --no-owner --host db \
--username={PROJECT_NAME} -d {LOCAL_DATABASE_NAME} {database_filename}",
service="db",
)
print(
Expand Down Expand Up @@ -273,12 +267,8 @@ def delete_local_database(c, local_database_name=LOCAL_DATABASE_NAME):

def aws(c, command, aws_access_key_id, aws_secret_access_key):
return local(
"AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_key} "
"aws {command}".format(
access_key_id=aws_access_key_id,
secret_key=aws_secret_access_key,
command=command,
)
f"AWS_ACCESS_KEY_ID={aws_access_key_id} AWS_SECRET_ACCESS_KEY={aws_secret_access_key} "
f"aws {command}"
)


Expand All @@ -289,10 +279,7 @@ def pull_media_from_s3(
aws_storage_bucket_name,
local_media_dir=LOCAL_MEDIA_DIR,
):
aws_cmd = "s3 sync --delete s3://{bucket_name} {local_media}".format(
bucket_name=aws_storage_bucket_name,
local_media=local_media_dir,
)
aws_cmd = f"s3 sync --delete s3://{aws_storage_bucket_name} {local_media_dir}"
aws(c, aws_cmd, aws_access_key_id, aws_secret_access_key)


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

local(
"heroku pg:backups:download --output={dump_folder}/{datestamp}.dump --app {app}".format(
app=app_instance, dump_folder=LOCAL_DUMP_DIR, datestamp=datestamp
),
f"heroku pg:backups:download --output={LOCAL_DUMP_DIR}/{datestamp}.dump --app {app_instance}",
)

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

local(
"rm {dump_folder}/{datestamp}.dump".format(
dump_folder=LOCAL_DUMP_DIR,
datestamp=datestamp,
),
f"rm {LOCAL_DUMP_DIR}/{datestamp}.dump",
)

if anonymise:
Expand Down Expand Up @@ -392,13 +370,9 @@ def make_bold(msg):
def dellar_snapshot(c, filename):
"""Snapshot the database, files will be stored in the db container"""
dexec(
"pg_dump -d {database_name} -U {database_username} > {filename}.psql".format(
database_name=LOCAL_DATABASE_NAME,
database_username=LOCAL_DATABASE_USERNAME,
filename=filename,
),
f"pg_dump -d {LOCAL_DATABASE_NAME} -U {LOCAL_DATABASE_USERNAME} > {filename}.psql",
service="db",
),
)
print("Database snapshot created")


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

dexec(
"psql -U {database_username} -d {database_name} < {filename}.psql".format(
database_name=LOCAL_DATABASE_NAME,
database_username=LOCAL_DATABASE_USERNAME,
filename=filename,
(
dexec(
f"psql -U {LOCAL_DATABASE_USERNAME} -d {LOCAL_DATABASE_NAME} < {filename}.psql",
service="db",
),
service="db",
),
)
print("Database restored.")


Expand All @@ -424,10 +396,10 @@ def dellar_list(c):
print("Database snapshots:")
dexec(
"""for f in *.psql; do
printf ' - %s\n' "${f%.psql}"
done""",
printf ' - %s\n' "${f%.psql}"
done""",
service="db",
),
)
print("Restore with `dellar-restore <snapshot>`")


Expand All @@ -437,7 +409,7 @@ def dellar_remove(c, filename):
dexec(
f"rm {filename}.psql",
service="db",
),
)
print(f"Snapshot {filename} removed")


Expand Down
1 change: 1 addition & 0 deletions gunicorn-conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Replace gunicorn's 'Server' HTTP header to avoid leaking info to attackers
import gunicorn


gunicorn.SERVER_SOFTWARE = ""
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys


if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tbx.settings.production")

Expand Down
Loading
Loading