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 for linting #488

Merged
merged 5 commits into from
Jan 12, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
with:
path: ${{ env.HOME }}/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/[email protected].0
- uses: pre-commit/[email protected].1
test_js:
runs-on: ubuntu-latest
needs: lint
Expand Down
25 changes: 5 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,12 @@ default_language_version:
node: 22.11.0
python: python3.13
repos:
- repo: https://github.com/psf/black
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
args: ['--target-version', 'py311']
- repo: https://github.com/pycqa/isort
# isort config is in setup.cfg
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/pycqa/flake8
# flake8 config is in setup.cfg
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
- flake8-assertive==2.1.0
- flake8-blind-except==0.2.1
- flake8-comprehensions==3.15.0
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/pycontribs/mirrors-prettier
rev: v3.3.2
hooks:
Expand Down
43 changes: 11 additions & 32 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime
import os
import subprocess
from shlex import quote
import subprocess

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 @@ -59,15 +60,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",
)
# Create extension schema, for error-free restores from Heroku backups
Expand All @@ -91,12 +88,8 @@ def import_data(
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",
)

Expand Down Expand Up @@ -198,9 +191,7 @@ 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 {command}".format(
command=command,
),
f"aws {command}",
env={
"AWS_ACCESS_KEY_ID": aws_access_key_id,
"AWS_SECRET_ACCESS_KEY": aws_secret_access_key,
Expand All @@ -215,10 +206,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 @@ -242,11 +230,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 @@ -275,18 +259,13 @@ def pull_database_from_heroku(c, app_instance):
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",
)


Expand Down
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", "wagtailio.settings")

Expand Down
Loading
Loading