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 1 commit
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
42 changes: 11 additions & 31 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 @@ -59,15 +61,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 +89,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 +192,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 +207,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 +231,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 +260,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
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extend-ignore = [
fixable = ["C4", "E", "F", "I", "UP"]

[lint.per-file-ignores]
"fabfile.py" = ["S603", "S607", "T201"]
"fabfile.py" = ["S101", "S603", "S607", "S608", "T201"]

[lint.isort]
known-first-party = ["wagtailio"]
Expand Down
1 change: 1 addition & 0 deletions wagtailio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from wagtailio.areweheadlessyet.models import AreWeHeadlessYetHomePage


api_router = WagtailAPIRouter("wagtailapi")


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.management.base import BaseCommand

import requests

from django.core.management.base import BaseCommand

from wagtailio.areweheadlessyet.models import WagtailHeadlessIssue


Expand All @@ -12,6 +12,7 @@ def handle(self, *args, **options):
response = requests.get(
"https://api.github.com/repos/wagtail/wagtail/issues",
params={"labels": "headless"},
timeout=10,
)
response.raise_for_status()

Expand Down
4 changes: 2 additions & 2 deletions wagtailio/areweheadlessyet/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Generated by Django 3.2.8 on 2022-01-24 11:57

import django.db.models.deletion
from django.db import migrations, models

import wagtail.blocks
import wagtail.fields

from django.db import migrations, models


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zerolab this change looks a bit strange to me - I assume this happens because import x takes precedence over from x import y. I would prefer third-party imports stay in alphabetical order.

Is this intentional behavior by ruff or is this something we can have an opinion about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a ruff opinion. will have a look tommorrow whether we can influence that

Copy link
Contributor Author

@zerolab zerolab Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the best I could get it to is:

- import django.db.models.deletion
from django.db import migrations, models
+ import django.db.models.deletion

import wagtail.blocks
import wagtail.fields

using https://docs.astral.sh/ruff/settings/#lint_isort_force-sort-within-sections

this halved the number of changed files

class Migration(migrations.Migration):
initial = True
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Generated by Django 3.2.8 on 2022-01-25 14:05

import django.db.models.deletion
from django.db import migrations, models

import wagtail.blocks
import wagtail.fields

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Generated by Django 3.2.8 on 2022-01-27 10:27

from django.db import migrations, models

import wagtail.blocks
import wagtail.fields
import wagtail.snippets.blocks

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Generated by Django 3.2.8 on 2022-02-08 12:57

from django.db import migrations

import wagtail.blocks
import wagtail.fields

from django.db import migrations

import wagtailio.areweheadlessyet.blocks


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Generated by Django 3.2.8 on 2022-06-01 14:53

from django.db import migrations

import wagtail.blocks
import wagtail.fields

from django.db import migrations

import wagtailio.areweheadlessyet.blocks


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Generated by Django 3.2.16 on 2022-10-04 12:34

from django.db import migrations

import wagtail.blocks
import wagtail.fields

from django.db import migrations

import wagtailio.areweheadlessyet.blocks


Expand Down
1 change: 0 additions & 1 deletion wagtailio/areweheadlessyet/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models

from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.api import APIField
from wagtail.fields import RichTextField, StreamField
Expand Down
1 change: 0 additions & 1 deletion wagtailio/areweheadlessyet/signal_handlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.conf import settings

from wagtail.signals import page_published, page_unpublished

from .models import AreWeHeadlessYetHomePage, AreWeHeadlessYetTopicPage
Expand Down
6 changes: 4 additions & 2 deletions wagtailio/areweheadlessyet/thread_pool.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging

from concurrent.futures import ThreadPoolExecutor

import requests

from django.conf import settings

import requests

logger = logging.getLogger("wagtailio")

Expand Down Expand Up @@ -53,5 +55,5 @@ def deploy(sender, **kwargs):
except (KeyboardInterrupt, SystemExit):
raise

except Exception: # noqa: B902
except Exception:
logger.exception("The request to trigger a new build on Vercel has failed.")
4 changes: 2 additions & 2 deletions wagtailio/blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Generated by Django 1.9.8 on 2016-07-29 09:55

import django.db.models.deletion
from django.db import migrations, models

import wagtail.blocks
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

from django.db import migrations, models

import wagtailio.utils.blocks


Expand Down
4 changes: 2 additions & 2 deletions wagtailio/blog/migrations/0004_auto_20190805_1754.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Generated by Django 2.0.13 on 2019-08-05 17:54

from django.db import migrations

import wagtail.blocks
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

from django.db import migrations

import wagtailio.utils.blocks


Expand Down
1 change: 1 addition & 0 deletions wagtailio/blog/migrations/0005_auto_20190813_0931.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 2.0.13 on 2019-08-13 09:31

import django.db.models.deletion

from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Generated by Django 3.2.12 on 2022-08-18 11:05

import django.db.models.deletion
from django.db import migrations, models

import modelcluster.fields
import wagtail.blocks
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

from django.db import migrations, models

import wagtailio.utils.blocks


Expand Down
4 changes: 2 additions & 2 deletions wagtailio/blog/migrations/0008_featuredpost.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Generated by Django 3.2.12 on 2022-08-22 12:45

import django.db.models.deletion
from django.db import migrations, models

import modelcluster.fields

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
Expand Down
4 changes: 2 additions & 2 deletions wagtailio/blog/migrations/0009_update_templates.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Generated by Django 3.2.12 on 2022-08-31 16:29

from django.db import migrations

import wagtail.blocks
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

from django.db import migrations

import wagtailio.utils.blocks


Expand Down
4 changes: 2 additions & 2 deletions wagtailio/blog/migrations/0010_streamfield_use_json_field.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Generated by Django 3.2.16 on 2022-10-04 12:34

from django.db import migrations

import wagtail.blocks
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks

from django.db import migrations

import wagtailio.utils.blocks


Expand Down
4 changes: 2 additions & 2 deletions wagtailio/blog/migrations/0012_clean_up_blog_blocks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Generated by Django 3.2.18 on 2023-05-19 18:37

from django.db import migrations

import wagtail.blocks
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
import wagtail.snippets.blocks

from django.db import migrations

import wagtailio.utils.blocks


Expand Down
4 changes: 2 additions & 2 deletions wagtailio/blog/migrations/0013_alter_blogpage_body.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Generated by Django 4.2.8 on 2023-12-08 18:07

from django.db import migrations

import wagtail.blocks
import wagtail.documents.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
import wagtail.snippets.blocks

from django.db import migrations

import wagtailio.utils.blocks


Expand Down
Loading
Loading