Skip to content

Commit

Permalink
ci: Replace flake8 with ruff
Browse files Browse the repository at this point in the history
Dealing with non-upgradable flake8 because of plugins is annoying.

See wemake-services/flake8-eradicate#269
  • Loading branch information
nijel committed Mar 22, 2023
1 parent 9989f27 commit d5378ec
Show file tree
Hide file tree
Showing 30 changed files with 88 additions and 196 deletions.
1 change: 1 addition & 0 deletions .github/.kodiak.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is maintained in https://github.com/WeblateOrg/meta/
# Configuration for https://kodiakhq.com/

version = 1

[merge]
Expand Down
17 changes: 0 additions & 17 deletions .github/matchers/flake8.json

This file was deleted.

14 changes: 6 additions & 8 deletions .github/workflows/flake8.yml → .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Flake8
name: ruff

on:
push:
Expand All @@ -8,8 +8,8 @@ on:
pull_request:

jobs:
flake8:
runs-on: ubuntu-20.04
ruff:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
Expand All @@ -22,13 +22,11 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install -r requirements-lint.txt
- name: Run flake8
- name: Run ruff
run: |
echo "::add-matcher::.github/matchers/flake8.json"
pre-commit run flake8 --all
echo "::remove-matcher owner=flake8::"
pre-commit run ruff --all
27 changes: 9 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,11 @@ repos:
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.257"
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- flake8-comprehensions
- flake8-django
- flake8-docstrings
- flake8-eradicate
- flake8-executable
- flake8-logging-format
- flake8-mutable
- flake8-polyfill
- flake8-print
- flake8-return
- flake8-self
- pep8-naming
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
Expand All @@ -57,6 +43,11 @@ repos:
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.8.0
hooks:
- id: pretty-format-toml
args: [--autofix]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.6
hooks:
Expand Down
3 changes: 1 addition & 2 deletions admin/pendingpo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
"""
Script to automatically merge pending translations from Pootle into po files.
"""Script to automatically merge pending translations from Pootle into po files.
It only accepts those, which are not translated or fuzzy.
"""
Expand Down
7 changes: 2 additions & 5 deletions donate/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
This file demonstrates two different styles of tests (one doctest and one
"""This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
Expand All @@ -10,9 +9,7 @@

class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
"""Tests that 1 + 1 always equals 2."""
self.assertEqual(1 + 1, 2)


Expand Down
2 changes: 1 addition & 1 deletion downloads/management/commands/add_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class Command(BaseCommand):
help = "adds file to the release"
help = "adds file to the release" # noqa: A003

def add_arguments(self, parser):
super().add_arguments(parser)
Expand Down
2 changes: 1 addition & 1 deletion downloads/migrations/0005_auto_20170317_0930.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def add_sha256(apps, schema_editor):
filename = os.path.join(settings.FILES_ROOT, download.location.lstrip("/"))

if not os.path.exists(filename):
print(f"File not found: {filename}")
print(f"File not found: {filename}") # noqa: T201
continue

with open(filename) as handle:
Expand Down
16 changes: 6 additions & 10 deletions downloads/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@


def get_latest_releases(program):
"""
Returns tuple with last release information for given program.
"""Returns tuple with last release information for given program.
First is stable, second is testing, which can be None.
"""
releases = Release.objects.filter(program=program)
Expand All @@ -57,12 +56,10 @@ def get_program(name):


def get_current_downloads(program):
"""
Gets list of tuples for currently active downloads. The first one
"""Gets list of tuples for currently active downloads. The first one
is always present and it's the stable one, the second one is
testing if available.
"""

downloads = []

stable_release, testing_release = get_latest_releases(program)
Expand Down Expand Up @@ -150,11 +147,10 @@ def get_description(self):
"program": self.get_program(),
"version": self.version,
}
else:
return _("%(program)s testing release %(version)s") % {
"program": self.get_program(),
"version": self.version,
}
return _("%(program)s testing release %(version)s") % {
"program": self.get_program(),
"version": self.version,
}

def get_program(self):
return get_program(self.program)
Expand Down
7 changes: 2 additions & 5 deletions downloads/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
This file demonstrates two different styles of tests (one doctest and one
"""This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
Expand All @@ -10,9 +9,7 @@

class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
"""Tests that 1 + 1 always equals 2."""
self.assertEqual(1 + 1, 2)


Expand Down
4 changes: 1 addition & 3 deletions downloads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def pad(request, program):


def padmap(request):
"""
Public list of PAD files.
"""
"""Public list of PAD files."""
response = HttpResponse(content_type="text/plain")
response.write("https://wammu.eu/api/pad/gammu.xml\n")
response.write("https://wammu.eu/api/pad/wammu.xml\n")
Expand Down
7 changes: 2 additions & 5 deletions links/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
This file demonstrates two different styles of tests (one doctest and one
"""This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
Expand All @@ -10,9 +9,7 @@

class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
"""Tests that 1 + 1 always equals 2."""
self.assertEqual(1 + 1, 2)


Expand Down
2 changes: 1 addition & 1 deletion news/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class RssNewsFeed(Feed):
link = "/news/"
copyright = "Copyright © 2003 - 2021 Michal Čihař"
copyright = "Copyright © Michal Čihař" # noqa: A003
item_copyright = copyright
title_template = "feeds/news_title.html"
description_template = "feeds/news_description.html"
Expand Down
5 changes: 1 addition & 4 deletions news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@


class Category(models.Model):
"""
A category that an entry can belong to.
"""
"""A category that an entry can belong to."""

title = models.CharField(max_length=250)
slug = models.SlugField(
Expand Down
7 changes: 2 additions & 5 deletions news/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
This file demonstrates two different styles of tests (one doctest and one
"""This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
Expand All @@ -10,9 +9,7 @@

class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
"""Tests that 1 + 1 always equals 2."""
self.assertEqual(1 + 1, 2)


Expand Down
2 changes: 1 addition & 1 deletion phonedb/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class RssPhonesFeed(Feed):
link = "/phones/"
copyright = "Copyright © 2003 - 2021 Michal Čihař"
copyright = "Copyright © Michal Čihař" # noqa: A003
item_copyright = copyright
title_template = "feeds/phones_title.html"
description_template = "feeds/phones_description.html"
Expand Down
2 changes: 1 addition & 1 deletion phonedb/management/commands/update_charts_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class Command(BaseCommand):
help = "updates chart URL"
help = "updates chart URL" # noqa: A003

def handle(self, *args, **options):
get_chart_url(force=True)
18 changes: 8 additions & 10 deletions phonedb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,14 @@ def get_absolute_url(self):
def get_author_email(self):
if self.author_email == "":
return None
elif self.email_garble == "hide":
if self.email_garble == "hide":
return None
elif self.email_garble == "none":
if self.email_garble == "none":
return self.author_email
elif self.email_garble == "atdot":
if self.email_garble == "atdot":
return self.author_email.replace("@", "[at]").replace(".", "[dot]")
else:
pos = random.randint(0, len(self.author_email))
return self.author_email[:pos] + "NOSPAM" + self.author_email[pos:]
pos = random.randint(0, len(self.author_email))
return self.author_email[:pos] + "NOSPAM" + self.author_email[pos:]

def get_author_name(self):
if self.author_name == "":
Expand All @@ -229,7 +228,6 @@ def get_author(self, html=True):

if html:
return f'<a href="mailto:{mail}">{name}</a>'
else:
if mail == name:
return mail
return f"{name} ({mail})"
if mail == name:
return mail
return f"{name} ({mail})"
Loading

0 comments on commit d5378ec

Please sign in to comment.