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

chore: Set up linting #406

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
24 changes: 24 additions & 0 deletions .github/workflows/ci-pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run pre-commit
on:
push:
branches:
- main
pull_request:
branches:
- '*'

jobs:
check:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Run pre-commit
uses: pre-commit/[email protected]
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
default_language_version:
node: system
python: python3.12
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-toml
- id: check-merge-conflict
- id: check-byte-order-marker
- id: check-case-conflict
- id: debug-statements
- id: detect-private-key
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.9
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ The testsuite uses [pytest](https://docs.pytest.org/) and [pytest-django](https:
pytest
```

### Linting

To ensure a uniform code style, this project uses [black](https://black.readthedocs.io/en/stable/) and [ruff](https://docs.astral.sh/ruff/). You can install the [pre-commit](https://pre-commit.com) hook to run them automatically when making a git commit:

```bash
pre-commit install
```

## Frontend Development

This project uses Bootstrap. The exact version is specified in the `package.json` file.
Expand Down
3 changes: 2 additions & 1 deletion docker/gunicorn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

import gunicorn

accesslog = "-"
errorlog = "-"
access_log_format = json.dumps(
Expand Down Expand Up @@ -27,5 +29,4 @@
chdir = "/app"

# Obfuscate the Server header (to the md5sum of "Springload")
import gunicorn
gunicorn.SERVER_SOFTWARE = "04e96149a2f64d6135c82d199ab62122"
4 changes: 2 additions & 2 deletions docker/init-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

set -x

python /app/manage.py makemigrations --dry-run --no-input
python /app/manage.py makemigrations --check --no-input
python /app/manage.py migrate --no-input
python /app/manage.py createcachetable
python /app/manage.py collectstatic --no-input
pytest --cov --cov-report=xml
if [ -d /coverage ]; then cp .coverage coverage.xml /coverage/; fi
python /app/manage.py makemigrations --dry-run --no-input
python /app/manage.py makemigrations --check --no-input
1 change: 0 additions & 1 deletion ietf/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from __future__ import absolute_import
1 change: 1 addition & 0 deletions ietf/announcements/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import wagtail_factories

from ietf.utils.factories import StandardBlockFactory

from .models import IABAnnouncementIndexPage, IABAnnouncementPage


Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,78 @@
# Generated by Django 4.2.7 on 2024-04-03 13:40

from django.db import migrations
import wagtail.blocks
import wagtail.contrib.table_block.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
import wagtailmarkdown.blocks
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('announcements', '0003_alter_iabannouncementpage_body'),
("announcements", "0003_alter_iabannouncementpage_body"),
]

operations = [
migrations.AlterField(
model_name='iabannouncementpage',
name='body',
field=wagtail.fields.StreamField([('heading', wagtail.blocks.CharBlock(icon='title')), ('paragraph', wagtail.blocks.RichTextBlock(icon='pilcrow')), ('image', wagtail.images.blocks.ImageChooserBlock(icon='image', template='includes/imageblock.html')), ('markdown', wagtailmarkdown.blocks.MarkdownBlock(icon='code')), ('embed', wagtail.embeds.blocks.EmbedBlock(icon='code')), ('raw_html', wagtail.blocks.RawHTMLBlock(icon='placeholder')), ('table', wagtail.contrib.table_block.blocks.TableBlock(table_options={'renderer': 'html'}, template='includes/tableblock.html')), ('typed_table', wagtail.contrib.typed_table_block.blocks.TypedTableBlock([('text', wagtail.blocks.CharBlock(required=False)), ('numeric', wagtail.blocks.FloatBlock(required=False, template='blocks/float_block.html')), ('rich_text', wagtail.blocks.RichTextBlock(required=False)), ('image', wagtail.images.blocks.ImageChooserBlock(required=False))])), ('note_well', wagtail.blocks.StructBlock([], icon='placeholder', label='Note Well Text'))], use_json_field=True),
model_name="iabannouncementpage",
name="body",
field=wagtail.fields.StreamField(
[
("heading", wagtail.blocks.CharBlock(icon="title")),
("paragraph", wagtail.blocks.RichTextBlock(icon="pilcrow")),
(
"image",
wagtail.images.blocks.ImageChooserBlock(
icon="image", template="includes/imageblock.html"
),
),
("markdown", wagtailmarkdown.blocks.MarkdownBlock(icon="code")),
("embed", wagtail.embeds.blocks.EmbedBlock(icon="code")),
("raw_html", wagtail.blocks.RawHTMLBlock(icon="placeholder")),
(
"table",
wagtail.contrib.table_block.blocks.TableBlock(
table_options={"renderer": "html"},
template="includes/tableblock.html",
),
),
(
"typed_table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
("text", wagtail.blocks.CharBlock(required=False)),
(
"numeric",
wagtail.blocks.FloatBlock(
required=False,
template="blocks/float_block.html",
),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(required=False),
),
(
"image",
wagtail.images.blocks.ImageChooserBlock(
required=False
),
),
]
),
),
(
"note_well",
wagtail.blocks.StructBlock(
[], icon="placeholder", label="Note Well Text"
),
),
],
use_json_field=True,
),
),
]
6 changes: 5 additions & 1 deletion ietf/announcements/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class Meta:
@property
def children(self):
announcements = self.get_children().live().specific()
return sorted(announcements, key=lambda announcement: announcement.specific.date, reverse=True)
return sorted(
announcements,
key=lambda announcement: announcement.specific.date,
reverse=True,
)


IABAnnouncementIndexPage.content_panels = Page.content_panels + [
Expand Down
7 changes: 4 additions & 3 deletions ietf/announcements/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import timedelta

import pytest
from bs4 import BeautifulSoup
from django.test import Client
from django.utils import timezone

import pytest

from ietf.home.models import IABHomePage

from .factories import IABAnnouncementIndexPageFactory, IABAnnouncementPageFactory
from .models import IABAnnouncementIndexPage, IABAnnouncementPage

Expand Down Expand Up @@ -55,7 +56,7 @@ def test_announcement_page(self):
assert self.announcement_3.introduction in html

def test_homepage(self):
""" The two most recent announcements are shown on the homepage """
"""The two most recent announcements are shown on the homepage"""
response = self.client.get(self.home.url)
assert response.status_code == 200
html = response.content.decode()
Expand Down
1 change: 0 additions & 1 deletion ietf/bibliography/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
# X model mixin with pre-parser method
# item rendering template tag
# itemS rendering template tag

2 changes: 1 addition & 1 deletion ietf/bibliography/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class BibliographyAppConfig(AppConfig):
name = 'ietf.bibliography'
name = "ietf.bibliography"
verbose_name = "Bibliography items"
4 changes: 2 additions & 2 deletions ietf/bibliography/management/commands/fix_BMI_page_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def change_links(page):
group_pattern1 = re.compile("\((\w+)\)\\xa0[Ww]orking [Gg]roup$")
group_pattern2 = re.compile(" *(\w+) +[Ww]orking [Gg]roup$")

for fieldname in page.CONTENT_FIELD_MAP.keys():
for fieldname in page.CONTENT_FIELD_MAP:
field = getattr(page, fieldname)
for item in field.stream_data:
if not item["type"] in ("paragraph", "raw_html"):
if item["type"] not in ("paragraph", "raw_html"):
continue
soup = BeautifulSoup(item["value"], "html.parser")
for tag in soup.find_all("a", string=rfc_pattern):
Expand Down
75 changes: 60 additions & 15 deletions ietf/bibliography/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,78 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-04-10 18:46
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

initial = True

dependencies = [
('wagtailcore', '0040_page_draft_title'),
('contenttypes', '0002_remove_content_type_name'),
("wagtailcore", "0040_page_draft_title"),
("contenttypes", "0002_remove_content_type_name"),
]

operations = [
migrations.CreateModel(
name='BibliographyItem',
name="BibliographyItem",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ordering', models.PositiveIntegerField(help_text='The bibliography items on each referring page are sorted and numbered with this ordering number.')),
('content_key', models.CharField(help_text='The "key" with which this item was created, eg. "rfc" in [[rfc:3514]].', max_length=127)),
('content_identifier', models.CharField(help_text='The "value" with which this item was created, eg. "3514" in [[rfc:3514]].', max_length=127)),
('content_long_title', models.CharField(blank=True, max_length=127)),
('content_title', models.CharField(help_text='The link title for this item, eg. "RFC 7168" for [[rfc:7168]].', max_length=127)),
('object_id', models.PositiveIntegerField(blank=True, null=True)),
('content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
('page', models.ForeignKey(help_text='The page that this item links to.', on_delete=django.db.models.deletion.CASCADE, related_name='bibliography_items', to='wagtailcore.Page')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"ordering",
models.PositiveIntegerField(
help_text="The bibliography items on each referring page are sorted and numbered with this ordering number."
),
),
(
"content_key",
models.CharField(
help_text='The "key" with which this item was created, eg. "rfc" in [[rfc:3514]].',
max_length=127,
),
),
(
"content_identifier",
models.CharField(
help_text='The "value" with which this item was created, eg. "3514" in [[rfc:3514]].',
max_length=127,
),
),
("content_long_title", models.CharField(blank=True, max_length=127)),
(
"content_title",
models.CharField(
help_text='The link title for this item, eg. "RFC 7168" for [[rfc:7168]].',
max_length=127,
),
),
("object_id", models.PositiveIntegerField(blank=True, null=True)),
(
"content_type",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="contenttypes.ContentType",
),
),
(
"page",
models.ForeignKey(
help_text="The page that this item links to.",
on_delete=django.db.models.deletion.CASCADE,
related_name="bibliography_items",
to="wagtailcore.Page",
),
),
],
),
]
Loading
Loading