Skip to content

Commit

Permalink
Migrate checks and formattings from black to ruff (#469)
Browse files Browse the repository at this point in the history
* Migrate to Ruff & fix problems (refs #467)

* Update README for Ruff (refs #467)

* Ruff format (refs #467)

* Run ruff romat & check separately (refs #467)

* Reformat the rest (refs #469)
  • Loading branch information
Almad authored Mar 23, 2024
1 parent 927b57c commit 8fb65e0
Show file tree
Hide file tree
Showing 50 changed files with 55 additions and 87 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: psf/black@stable
with:
options: ". --check"
- name: Install ruff
run: pip install ruff
- name: Ruff Check Linhting
run: ruff check --output-format=github .
- name: Ruff Check Formatting
run: ruff format --check
9 changes: 9 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[lint.per-file-ignores]
# Those are intentional global namespace populations so that importer
# doesn't have to care about the package's internal structure, and they can
# be moved around flexibly
"ddcz/models/__init__.py" = ["F403"]
"ddcz/models/views/__init__.py" = ["F403"]
"ddcz/models/used/__init__.py" = ["F403"]
"graveyard/settings/__init__.py" = ["F403"]
"ddcz/views/__init__.py" = ["F403"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Production is running at http://nove.dracidoupe.cz/ . But be warned, we are head

## Contributions

Contributions are welcome provided you agree your work will be shared under the same license as Graveyard (MIT). Please use [black](https://pypi.org/project/black/) for code formatting.
Contributions are welcome provided you agree your work will be shared under the same license as Graveyard (MIT). Please use [ruff](https://docs.astral.sh/ruff/) for code formatting and verification ([VS Code integration here](https://github.com/astral-sh/ruff-vscode?tab=readme-ov-file#ruff-extension-for-visual-studio-code)).

If you don't know where to start, take a look [at the roadmap](https://github.com/dracidoupe/graveyard/milestones) or ask Almad on [development Slack](https://dracidoupe.slack.com/messages/C7F0YCTFU) or [community Discord](https://discord.gg/SnFux2x3Vw) or in Pošta on [DraciDoupe.cz](https://www.dracidoupe.cz/).

Expand Down
1 change: 0 additions & 1 deletion ddcz/commonarticles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

# TODO: Redo into pages fixtures


# Normative directory of Creative Pages allowed on the page
# Key is the common "short" identification of creative page,
# as present in database (as string) and data model
Expand Down
2 changes: 1 addition & 1 deletion ddcz/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
UserProfile,
CreationEmailSubscription,
)
from ddcz.notifications import MAX_EMAIL_BATCH, logger
from ddcz.notifications import MAX_EMAIL_BATCH
from django.urls import reverse

logger = logging.getLogger(__name__)
Expand Down
14 changes: 7 additions & 7 deletions ddcz/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ def encode_valid_html(entity_string):
# meaning it's correctly paired?
if (
entity_string[
current_character_index
+ 5 : current_character_index
current_character_index + 5 : current_character_index
+ 5
+ len(tag_stack[-1])
].lower()
Expand All @@ -211,8 +210,7 @@ def encode_valid_html(entity_string):
elif (
len(tag_stack) > 1
and entity_string[
current_character_index
+ 5 : current_character_index
current_character_index + 5 : current_character_index
+ 5
+ len(tag_stack[-2])
].lower()
Expand Down Expand Up @@ -262,8 +260,7 @@ def encode_valid_html(entity_string):
# FIXME: Doesn't support tag attributes
tag_candidate_string = (
entity_string[
current_character_index
+ 4 : current_character_index
current_character_index + 4 : current_character_index
+ 3
+ MAX_LOOKAHEAD_FROM_LEFT
+ 3
Expand Down Expand Up @@ -342,6 +339,9 @@ class HtmlTagMismatchException(Exception):


def check_creation_html(entity_string):
html_string = unsafe_encode_any_creation_html(entity_string)
unsafe_encode_any_creation_html(entity_string)
parser = HtmlChecker()
parser.feed(entity_string)
# TODO: Explore this version
# html_string = unsafe_encode_any_creation_html(entity_string)
# parser.feed(html_string)
1 change: 0 additions & 1 deletion ddcz/management/commands/checkcreationshtml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys

from django.apps import apps
from django.core.management.base import BaseCommand, CommandError

from ddcz.models import CreativePage
Expand Down
3 changes: 1 addition & 2 deletions ddcz/management/commands/deleteauthors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.apps import apps
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand

from ddcz.models import Author

Expand Down
1 change: 0 additions & 1 deletion ddcz/management/commands/fixit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.apps import apps
from django.core.management import call_command
from django.core.management.base import BaseCommand

Expand Down
4 changes: 2 additions & 2 deletions ddcz/management/commands/migrateauthors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

from django.apps import apps
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand

from ddcz.models import Author, CreativePage, UserProfile
from ddcz.text import misencode
Expand Down Expand Up @@ -61,7 +61,7 @@ def get_author(self, creation, creation_model):
user_nick=creation.author_nick,
)

except UserProfile.DoesNotExist as err:
except UserProfile.DoesNotExist:
author_type = Author.ANONYMOUS_USER_TYPE

try:
Expand Down
4 changes: 1 addition & 3 deletions ddcz/management/commands/migratephorum.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import logging
import sys

from django.apps import apps
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
from ddcz.text import misencode

from ddcz.models import Phorum, UserProfile
from ddcz.text import misencode

logger = logging.getLogger(__name__)

Expand Down
4 changes: 1 addition & 3 deletions ddcz/management/commands/migratetavernaccess.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging
import sys

from django.apps import apps
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand

from ddcz.tavern import migrate_tavern_access

Expand Down
2 changes: 0 additions & 2 deletions ddcz/management/commands/registeruser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.apps import apps
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand, CommandError
from django.core.validators import validate_email
from django.contrib.auth.password_validation import validate_password
Expand Down
1 change: 0 additions & 1 deletion ddcz/migrations/0001_initial-post-switch-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


class Migration(migrations.Migration):

replaces = [
("ddcz", "0001_initial"),
("ddcz", "0002_dating_userprofile"),
Expand Down
3 changes: 1 addition & 2 deletions ddcz/migrations/squashed/0002_dating_userprofile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ddcz.models.magic
from django.db import migrations, models
from django.db import migrations

# When migrating from unmanaged to managed models,
# CreateModel must be explicitly used in order for table
Expand Down
1 change: 0 additions & 1 deletion ddcz/migrations/squashed/0003_auto_20180608_2230.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 2.0.2 on 2018-06-08 20:30

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


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion ddcz/migrations/squashed/0007_levelsystemparams.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 2.0.2 on 2018-06-09 19:28

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


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion ddcz/migrations/squashed/0020_verbose_names.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 2.0.13 on 2020-03-04 14:22

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


class Migration(migrations.Migration):
Expand Down
3 changes: 1 addition & 2 deletions ddcz/migrations/squashed/0027_links_rename.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 2.0.13 on 2020-10-10 16:09

import ddcz.models.magic
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
3 changes: 1 addition & 2 deletions ddcz/migrations/squashed/0038_item_rename.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 2.0.13 on 2020-10-16 15:04

import ddcz.models.magic
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion ddcz/migrations/squashed/0056_creationcomments_fix.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 2.0.13 on 2021-04-07 17:37

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


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion ddcz/migrations/squashed/0065_mentat_drop_auto.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 2.0.13 on 2021-04-16 16:51

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


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion ddcz/migrations/squashed/0066_mentat_fix_autoincrement.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 2.0.13 on 2021-04-16 16:52

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


class Migration(migrations.Migration):
Expand Down
9 changes: 5 additions & 4 deletions ddcz/migrations/squashed/0081_taverntable_access_migration.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Generated by Django 2.0.13 on 2021-05-05 12:32

from django.db import migrations
from ddcz.tavern import migrate_tavern_access


def migrate_access(apps, schema_editor):
table_visitor_model = apps.get_model("ddcz", "TavernTableVisitor")
tavern_access_model = apps.get_model("ddcz", "TavernAccess")
user_profile_model = apps.get_model("ddcz", "UserProfile")
# Because of our model rename migration, we would have to have a frozen copy of
# the function here. Given the production is migrated, let's mark it as noop now
# table_visitor_model = apps.get_model("ddcz", "TavernTableVisitor")
# tavern_access_model = apps.get_model("ddcz", "TavernAccess")
# user_profile_model = apps.get_model("ddcz", "UserProfile")

# migrate_tavern_access(
# print_progress=True,
# table_visitor_model=table_visitor_model,
# tavern_access_model=tavern_access_model,
# user_profile_model=user_profile_model,
# )
pass


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.0.13 on 2023-09-17 17:10

import ddcz.models.magic
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("ddcz", "0131_letter_encoding_20240225_1412"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("ddcz", "0132_editor_article_20240225_1530"),
]
Expand Down
5 changes: 4 additions & 1 deletion ddcz/models/used/creations.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ class Creation(models.Model):
# with a nickname that relies on being string equal with `UserProfile.nick_uzivatele`
# Should be NOT NULL in the future, null allowed for transition period
author = models.ForeignKey(
Author, on_delete=models.SET_NULL, blank=True, null=True # , db_column="author"
Author,
on_delete=models.SET_NULL,
blank=True,
null=True, # , db_column="author"
)

# section = models.ForeignKey(CreativePageSection, on_delete=models.SET_NULL, null=True, blank=True)
Expand Down
1 change: 0 additions & 1 deletion ddcz/models/used/notifications.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from base64 import urlsafe_b64decode
from enum import Enum
from secrets import token_urlsafe

Expand Down
3 changes: 0 additions & 3 deletions ddcz/models/used/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse

from django.contrib.auth.models import User
Expand Down Expand Up @@ -276,7 +274,6 @@ class Rune(models.Model):

@property
def image_url(self):
id = self.graphics
return staticfiles_storage.url(
"common/runes/runa%(rune)s.gif" % {"rune": self.graphics}
)
Expand Down
6 changes: 1 addition & 5 deletions ddcz/templatetags/creations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

from django import template
from django.contrib.staticfiles.storage import staticfiles_storage
from django.db.models import (
OuterRef,
Subquery,
)

from ..creations import RATING_DESCRIPTIONS
from ..models import CreationVote, UserProfile
from ..models import CreationVote

logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion ddcz/templatetags/pages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django import template
from django.http import request

register = template.Library()

Expand Down
2 changes: 0 additions & 2 deletions ddcz/tests/model_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
bookmark_table,
)

from .attack_strings import SCRIPT_ALERT_INPUT


def get_valid_article_chain():
user = UserProfile(nick="Author", email="[email protected]")
Expand Down
2 changes: 0 additions & 2 deletions ddcz/tests/test_integration/test_legacy_redirects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any
from django.template import Context, Template
from django.test import Client, TestCase

from ddcz.models import (
Expand Down
1 change: 0 additions & 1 deletion ddcz/tests/test_integration/test_tavern/test_listing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.contrib.auth.models import User
from django.urls import reverse
from django.test import Client, TestCase

Expand Down
2 changes: 0 additions & 2 deletions ddcz/tests/test_templatetags/test_creations_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from .case import TemplateTestCase
from ..model_generator import get_valid_article_chain

from ddcz.models import Author, CommonArticle, UserProfile


class TestAuthorLinkRender(TemplateTestCase):
fixtures = ["pages"]
Expand Down
3 changes: 0 additions & 3 deletions ddcz/tests/test_ui/test_crativepages_rendered.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from urllib.request import urlopen
from django.conf import settings

from .cases import SeleniumTestCase
from selenium.webdriver.common.by import By

Expand Down
1 change: 0 additions & 1 deletion ddcz/tests/test_ui/test_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from selenium.webdriver.common.by import By

from .cases import SeleniumTestCase, MainPage
from ..attack_strings import SCRIPT_ALERT_INPUT
from ..model_generator import create_market_entries


Expand Down
1 change: 0 additions & 1 deletion ddcz/tests/test_ui/test_news.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from urllib.request import urlopen
from django.conf import settings

from selenium.webdriver.common.by import By

Expand Down
Loading

0 comments on commit 8fb65e0

Please sign in to comment.