Skip to content

Commit

Permalink
Dev tooling upgrades (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tijani-Dia committed Nov 9, 2023
1 parent 4bf0003 commit 287feab
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 307 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
with:
python-version: 3.11
- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.2.2 python -
run: curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.0 python -
- name: Install Python dependencies
run: poetry install
- name: System checks
Expand All @@ -60,7 +60,7 @@ jobs:
with:
python-version: 3.11
- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.2.2 python -
run: curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.0 python -
- name: Install Python dependencies
run: poetry install
- name: Lint
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ apps/guide/settings/local.py
/media/
/static/
.coverage
.ruff_cache
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tasks:
- init: |
npm ci
npm run build
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.2.2 python -
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.0 python -
poetry install
poetry run python manage.py migrate
poetry run python manage.py createcachetable
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ARG POETRY_HOME=/opt/poetry
ARG POETRY_INSTALL_ARGS="--without dev"

# IMPORTANT: Remember to review this when upgrading
ARG POETRY_VERSION=1.2.2
ARG POETRY_VERSION=1.7.0

# Install dependencies in a virtualenv
ENV VIRTUAL_ENV=/venv
Expand Down
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ test-coverage:
poetry run coverage run manage.py test && poetry run coverage report

format-backend:
poetry run isort apps
poetry run black apps
poetry run ruff check . --fix
poetry run black .

format-frontend:
npm run format

format: format-backend format-frontend

lint-backend:
poetry run flake8 apps
poetry run isort --check-only --diff apps
poetry run black --check --diff apps
poetry run ruff check .
poetry run black --check --diff .

lint-frontend:
npm run lint
Expand All @@ -36,7 +35,7 @@ frontend:
npm run build

backend:
poetry install
poetry install --no-root
poetry run python manage.py migrate
poetry run python manage.py createcachetable
poetry run python manage.py createsuperuser
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ We assume that you have basic knowledge of Node/Webpack and Python/Django/Wagtai

- Git
- Python >= 3.11
- Poetry >= 1.2.2
- Poetry >= 1.7.0
- Node (see `.nvmrc` for version)

### Setting up Wagtail guide in a virtual environment
Expand Down Expand Up @@ -102,7 +102,7 @@ If you're a Python or Django developer, fork the repo and join us. You'll find a
## Development

- Run formatting (Black & Prettier) `make format`
- Run linting (Flake8, isort, Black, Prettier, Eslint) `make lint`
- Run linting (Ruff, Black, Prettier, Eslint) `make lint`
- Run tests `make test`

# Other Notes
Expand Down
2 changes: 1 addition & 1 deletion apps/core/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _create(cls, model_class, *args, **kwargs):


class ContentPageFactory(wagtail_factories.PageFactory):
title = factory.Sequence(lambda n: "Page {}".format(n))
title = factory.Sequence(lambda n: f"Page {n}")
locale = factory.SubFactory(LocaleFactory)

class Meta:
Expand Down
1 change: 0 additions & 1 deletion apps/core/monkey_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
logger = logging.getLogger(__name__)


# flake8: noqa: C901
@transaction.atomic
def _copy_for_translation(self, page, locale, copy_parents, alias, exclude_fields):
# Find the translated version of the parent page to create the new page under
Expand Down
16 changes: 8 additions & 8 deletions apps/core/tests/test_content_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ def setUp(self):

def test_create_table_of_contents_no_id(self):
# If there's no id, generate it by slugifying the text.
assert self.content_page.table_of_contents == ""
self.assertEqual(self.content_page.table_of_contents, "")
self.content_page.body = '[{"type": "text", "value": "<h2>Foo bar</h2>"}]'
self.content_page.save_revision()
assert (
self.content_page.table_of_contents
== '<ul><li><a href="#foo-bar">Foo bar</a></li></ul>'
self.assertEqual(
self.content_page.table_of_contents,
'<ul><li><a href="#foo-bar">Foo bar</a></li></ul>',
)

def test_create_table_of_contents_existing_id(self):
# Our custom AnchorBlockConverter for Draft.js isn't called when
# translating with wagtail-localize, so the id isn't updated.
# If there's an existing id, make sure to use that instead so the link
# still works.
assert self.content_page.table_of_contents == ""
self.assertEqual(self.content_page.table_of_contents, "")
self.content_page.body = (
'[{"type": "text", "value": "<h2 id=\\"something\\">ekkie</h2>"}]'
)
self.content_page.save_revision()
assert (
self.content_page.table_of_contents
== '<ul><li><a href="#something">ekkie</a></li></ul>'
self.assertEqual(
self.content_page.table_of_contents,
'<ul><li><a href="#something">ekkie</a></li></ul>',
)
2 changes: 1 addition & 1 deletion apps/core/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def register_keyboard_input_text_style(features):
"background-color": "#eee",
"border-radius": "3px",
"border": "1px solid #b4b4b4",
"box-shadow": "0 1px 1px rgba(0, 0, 0, .2), 0 2px 0 0 rgba(255, 255, 255, .7) inset", # noqa
"box-shadow": "0 1px 1px rgba(0, 0, 0, .2), 0 2px 0 0 rgba(255, 255, 255, .7) inset",
"color": "#333",
"display": "inline-block",
"font-size": ".85em",
Expand Down
7 changes: 3 additions & 4 deletions apps/guide/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
Expand Down Expand Up @@ -290,7 +290,7 @@

# ManifestStaticFilesStorage is recommended in production, to prevent outdated
# JavaScript / CSS assets being served from cache (e.g. after a Wagtail upgrade).
# See https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#manifeststaticfilesstorage # noqa
# See https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#manifeststaticfilesstorage
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
Expand All @@ -307,7 +307,7 @@
MEDIA_ROOT = BASE_DIR / "media"
MEDIA_URL = "/media/"

# Place static files that need a specific URL (such as robots.txt and favicon.ico) in the "public" folder # noqa
# Place static files that need a specific URL (such as robots.txt and favicon.ico) in the "public" folder
WHITENOISE_ROOT = os.path.join(BASE_DIR, "public")

# Wagtail settings
Expand Down Expand Up @@ -490,7 +490,6 @@
is_in_shell = len(sys.argv) > 1 and sys.argv[1] in ["shell", "shell_plus"]

if "SENTRY_DSN" in env and not is_in_shell:

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.utils import get_default_release
Expand Down
6 changes: 3 additions & 3 deletions apps/guide/settings/dev.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import * # noqa
from .base import * # noqa: F403

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -11,7 +11,7 @@

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

INSTALLED_APPS += [ # noqa
INSTALLED_APPS += [ # noqa: F405
"django_extensions",
]

Expand All @@ -22,6 +22,6 @@


try:
from .local import * # noqa
from .local import * # noqa: F403
except ImportError:
pass
14 changes: 8 additions & 6 deletions apps/guide/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from .base import * # noqa
from .base import * # noqa: F403

DEBUG = False

SECRET_KEY = env["SECRET_KEY"] # noqa
SECRET_KEY = env["SECRET_KEY"] # noqa: F405

if allowed_hosts := env.get("ALLOWED_HOSTS"): # noqa
if allowed_hosts := env.get("ALLOWED_HOSTS"): # noqa: F405
ALLOWED_HOSTS = allowed_hosts.split(",")

MANIFEST_LOADER["cache"] = True # noqa
MANIFEST_LOADER["cache"] = True # noqa: F405

# Force HTTPS redirect (enabled by default!)
# https://docs.djangoproject.com/en/stable/ref/settings/#secure-ssl-redirect
Expand All @@ -25,7 +25,9 @@
# dev and testing settings.
# https://docs.djangoproject.com/en/stable/ref/settings/#secure-hsts-seconds
DEFAULT_HSTS_SECONDS = 30 * 24 * 60 * 60 # 30 days
SECURE_HSTS_SECONDS = int(env.get("SECURE_HSTS_SECONDS", DEFAULT_HSTS_SECONDS)) # noqa
SECURE_HSTS_SECONDS = int(
env.get("SECURE_HSTS_SECONDS", DEFAULT_HSTS_SECONDS) # noqa: F405
)

# Do not use the `includeSubDomains` directive for HSTS. This needs to be prevented
# because the apps are running on client domains (or our own for staging), that are
Expand All @@ -43,7 +45,7 @@
# Referrer-policy header settings.
# https://django-referrer-policy.readthedocs.io/en/1.0/

REFERRER_POLICY = env.get( # noqa
REFERRER_POLICY = env.get( # noqa: F405
"SECURE_REFERRER_POLICY", "no-referrer-when-downgrade"
).strip()

Expand Down
2 changes: 1 addition & 1 deletion apps/guide/settings/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import * # noqa
from .base import * # noqa: F403

DEBUG = False

Expand Down
2 changes: 1 addition & 1 deletion apps/guide/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from django.core.wsgi import get_wsgi_application

from monkey_patches import * # noqa
from monkey_patches import * # noqa: F403

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "guide.settings.dev")

Expand Down
3 changes: 2 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python
from monkey_patches import * # noqa
import os
import sys

from monkey_patches import * # noqa: F403

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apps.guide.settings.dev")

Expand Down
9 changes: 4 additions & 5 deletions monkey_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
- `/en-3.0/`
- `/en-4.0.x/`
"""
import re
import logging
import re

from django.conf import settings
from django.utils import translation
from django.utils.translation import get_language_info as original_get_language_info
from django.utils.translation import gettext_lazy, trans_real
from django.utils.regex_helper import _lazy_re_compile

from django.utils.translation import get_language_info as original_get_language_info
from django.utils.translation import trans_real

logger = logging.getLogger(__name__)
logger.warning(
Expand All @@ -34,7 +33,7 @@

def remove_version_number_from_language_code(lang_code):
# Make sure to remove the version only if it exists
if any((version in lang_code for version in settings.WAGTAIL_GUIDE_VERSIONS)):
if any(version in lang_code for version in settings.WAGTAIL_GUIDE_VERSIONS):
return lang_code.rsplit("-", maxsplit=1)[0]
return lang_code

Expand Down
Loading

0 comments on commit 287feab

Please sign in to comment.