Skip to content

Commit

Permalink
Migrate to the Ruff formatter (#1846)
Browse files Browse the repository at this point in the history
* Migrate to the Ruff formatter

* Update config.js

* Update notify-dev-entrypoint.sh

Unintended commit, brain was not working at 9PM 😅

* Add ruff dependency

- Moved Ruff configs to the bottom of pyproject.toml
- Remove deprecated vscode linter settings

* Format with Ruff

- Migrate extension better toml to even better toml due to deprecation

* Update poetry lock file

* Update run_tests.sh to use Ruff

* update lockfile

* formatting

* update lockfile
  • Loading branch information
whabanks authored Sep 3, 2024
1 parent ae1b884 commit 1a94276
Show file tree
Hide file tree
Showing 27 changed files with 202 additions and 332 deletions.
8 changes: 3 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
"SHELL": "/bin/zsh"
},
"settings": {
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "/usr/local/bin/pylint",
"python.pythonPath": "/usr/local/bin/python",
},
"extensions": [
Expand All @@ -27,7 +24,8 @@
"visualstudioexptteam.vscodeintellicode",
"yzhang.markdown-all-in-one",
"ms-ossdata.vscode-postgresql",
"bungcip.better-toml",
"tamasfe.even-better-toml",
"charliermarsh.ruff",
],
"features": {
"ghcr.io/devcontainers/features/node:1": {
Expand All @@ -39,4 +37,4 @@
],
"postCreateCommand": "notify-dev-entrypoint.sh",
"remoteUser": "vscode"
}
}
2 changes: 1 addition & 1 deletion .devcontainer/scripts/installations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo -e "fpath+=/.zfunc" >> ~/.zshrc
echo -e "autoload -Uz compinit && compinit"

# Install Poetry
pip install poetry==${POETRY_VERSION}
pip install poetry==${POETRY_VERSION} poetry-plugin-sort
echo "PATH=$PATH"
#echo "/home/vscode/.local/bin/.."
export PATH=$PATH:/home/vscode/.local/bin/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install poetry
env:
POETRY_VERSION: "1.7.1"
run: pip install poetry==${POETRY_VERSION} && poetry --version
run: pip install poetry==${POETRY_VERSION} poetry-plugin-sort && poetry --version
- name: Install requirements
run: poetry install --with test
- uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3.3.3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ cypress*env*json*
node_modules/
tests_cypress/cypress/videos/
tests_cypress/cypress/screenshots/
.ruff_cache/
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ run-dev:

.PHONY: format
format:
isort ./app ./tests
black ./app ./tests
flake8 ./app ./tests
isort --check-only ./app ./tests
ruff check --select I --fix .
ruff format .
mypy ./
npx prettier --write app/assets/javascripts app/assets/stylesheets tests_cypress/cypress/e2e

Expand Down
78 changes: 34 additions & 44 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,10 @@ def get_human_day(time):


def format_time(date):
return (
{"12:00AM": "Midnight", "12:00PM": "Midday"}
.get(
utc_string_to_aware_gmt_datetime(date).strftime("%-I:%M%p"),
utc_string_to_aware_gmt_datetime(date).strftime("%-I:%M%p"),
)
.lower()
)
return {"12:00AM": "Midnight", "12:00PM": "Midday"}.get(
utc_string_to_aware_gmt_datetime(date).strftime("%-I:%M%p"),
utc_string_to_aware_gmt_datetime(date).strftime("%-I:%M%p"),
).lower()


def format_date(date):
Expand Down Expand Up @@ -450,9 +446,7 @@ def _getStatusByBounceSubtype():
"suppressed": _("Blocked"),
"on-account-suppression-list": _("Blocked"),
},
}[
template_type
].get(feedback_subtype, _("No such address"))
}[template_type].get(feedback_subtype, _("No such address"))
else:
return _("No such address")

Expand Down Expand Up @@ -510,40 +504,36 @@ def format_notification_status_as_time(status, created, updated):


def format_notification_status_as_field_status(status, notification_type):
return (
{
"letter": {
"failed": "error",
"technical-failure": "error",
"temporary-failure": "error",
"permanent-failure": "error",
"delivered": None,
"sent": None,
"sending": None,
"created": None,
"accepted": None,
"pending-virus-check": None,
"virus-scan-failed": "error",
"returned-letter": None,
"cancelled": "error",
}
return {
"letter": {
"failed": "error",
"technical-failure": "error",
"temporary-failure": "error",
"permanent-failure": "error",
"delivered": None,
"sent": None,
"sending": None,
"created": None,
"accepted": None,
"pending-virus-check": None,
"virus-scan-failed": "error",
"returned-letter": None,
"cancelled": "error",
}
.get(
notification_type,
{
"failed": "error",
"technical-failure": "error",
"temporary-failure": "error",
"permanent-failure": "error",
"delivered": None,
"sent": None,
"sending": "default",
"created": "default",
"pending": "default",
},
)
.get(status, "error")
)
}.get(
notification_type,
{
"failed": "error",
"technical-failure": "error",
"temporary-failure": "error",
"permanent-failure": "error",
"delivered": None,
"sent": None,
"sending": "default",
"created": "default",
"pending": "default",
},
).get(status, "error")


def format_notification_status_as_url(status, notification_type):
Expand Down
4 changes: 1 addition & 3 deletions app/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
HiddenField,
IntegerField,
PasswordField,
)
from wtforms import RadioField as WTFormsRadioField
from wtforms import (
SelectField,
SelectMultipleField,
StringField,
Expand All @@ -31,6 +28,7 @@
validators,
widgets,
)
from wtforms import RadioField as WTFormsRadioField
from wtforms.fields import EmailField, SearchField, TelField
from wtforms.validators import (
URL,
Expand Down
8 changes: 2 additions & 6 deletions app/main/views/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,19 @@
)
from app.extensions import redis_client
from app.main import main
from app.main.forms import (
EmailTemplateForm, # remove when FF_TEMPLATE_CATEGORY is removed
)
from app.main.forms import (
SMSTemplateForm, # remove when FF_TEMPLATE_CATEGORY is removed
)
from app.main.forms import (
TC_PRIORITY_VALUE,
AddEmailRecipientsForm,
AddSMSRecipientsForm,
CreateTemplateForm,
EmailTemplateForm, # remove when FF_TEMPLATE_CATEGORY is removed
EmailTemplateFormWithCategory,
LetterTemplateForm,
LetterTemplateFormWithCategory,
LetterTemplatePostageForm,
SearchByNameForm,
SetTemplateSenderForm,
SMSTemplateForm, # remove when FF_TEMPLATE_CATEGORY is removed
SMSTemplateFormWithCategory,
TemplateAndFoldersSelectionForm,
TemplateCategoryForm,
Expand Down
1 change: 0 additions & 1 deletion application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware
from dotenv import load_dotenv
from flask import Flask

from werkzeug.middleware.proxy_fix import ProxyFix

from app import create_app
Expand Down
1 change: 0 additions & 1 deletion config/mixpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class NotifyMixpanel:

enabled = False

def __init__(self) -> None:
Expand Down
3 changes: 1 addition & 2 deletions gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import traceback

import gunicorn # type: ignore

import newrelic.agent # See https://bit.ly/2xBVKBH

newrelic.agent.initialize() # noqa: E402

# Guincorn sets the server type on our app. We don't want to show it in the header in the response.
gunicorn.SERVER = 'Undisclosed'
gunicorn.SERVER = "Undisclosed"

workers = 5
worker_class = "gevent"
Expand Down
Loading

0 comments on commit 1a94276

Please sign in to comment.