Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Swap from flake8 to ruff (#963)

Brandon Glowatskida0769e90df8
diff --git a/.flake8 b/.flake8
deleted file mode 100644
index 970f4d996..000000000
--- a/.flake8
+++ /dev/null
@@ -1,15 +0,0 @@
-[flake8]
-# match black formatter's behavior
-# https://www.flake8rules.com/rules/E203.html
-# https://www.flake8rules.com/rules/W503.html
-ignore = E203, W503
-per-file-ignores =
- # Ignore maximum line length rule for test files
- *test*:E501
- # https://www.flake8rules.com/rules/F401.html; init files act as re-exporters
- *__init__*:F401
- # https://www.flake8rules.com/rules/E402.html; patches are applied before all imports are finished
- *wsgi.py:E402
- # https://www.flake8rules.com/rules/F401.html; django settings holds global values
- *settings.py:F401
-max-line-length = 88
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 562e97b54..d53ef0e27 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -58,14 +58,10 @@ repos:
args:
- --py310-plus
- # Use the `.flake8` file to configure additional project-specific requirements.
- - repo: https://github.com/PyCQA/flake8
- rev: 3.9.2
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
+ rev: "v0.0.257"
hooks:
- - id: flake8
- args:
- - --extend-ignore=E203,W503
- - --max-line-length=88
+ - id: ruff
- repo: https://github.com/ambv/black
rev: 22.3.0
diff --git a/.ruff.toml b/.ruff.toml
new file mode 100644
index 000000000..4000dd4db
--- /dev/null
+++ b/.ruff.toml
@@ -0,0 +1,5 @@
+[per-file-ignores]
+"*test*" = ["E501"]
+"*__init__*" = ["F401"]
+"*wsgi.py" = ["E402"]
+"*settings.py" = ["F401"]
diff --git a/api/catalog/api/utils/exceptions.py b/api/catalog/api/utils/exceptions.py
index 1db366e73..51b939670 100644
--- a/api/catalog/api/utils/exceptions.py
+++ b/api/catalog/api/utils/exceptions.py
@@ -7,12 +7,12 @@ def exception_handler(ex, context):
Handle the exception raised in a DRF context.
See `DRF docs`_.
- .. _DRF docs: https://www.django-rest-framework.org/api-guide/exceptions/#custom-exception-handling # noqa: E501
+ .. _DRF docs: https://www.django-rest-framework.org/api-guide/exceptions/#custom-exception-handling
:param ex: the exception that has occurred
:param context: additional data about the context of the exception
:return: the response to show for the exception
- """
+ """ # noqa: E501
res = drf_exception_handler(ex, context)
if isinstance(ex, ValidationError):
diff --git a/api/test/unit/utils/watermark_test.py b/api/test/unit/utils/watermark_test.py
index c649140dd..6c5198e2c 100644
--- a/api/test/unit/utils/watermark_test.py
+++ b/api/test/unit/utils/watermark_test.py
@@ -21,7 +21,7 @@ _MOCK_IMAGE_INFO = json.loads((_MOCK_IMAGE_PATH / "sample-image-info.json").read
@dataclass
class RequestsFixture:
requests: list[Request]
- response_factory: Callable[
+ response_factory: Callable[ # noqa: E731
[Request], Response
] = lambda x: RequestsFixture._default_response_factory(x)
diff --git a/api/test/unit/utils/waveform_test.py b/api/test/unit/utils/waveform_test.py
index d0b70f152..0308dee44 100644
--- a/api/test/unit/utils/waveform_test.py
+++ b/api/test/unit/utils/waveform_test.py
@@ -19,7 +19,7 @@ _MOCK_AUDIO_INFO = json.loads((_MOCK_AUDIO_PATH / "sample-audio-info.json").read
@dataclass
class RequestsFixture:
requests: list[Request]
- response_factory: Callable[
+ response_factory: Callable[ # noqa: E731
[Request], Response
] = lambda x: RequestsFixture._default_response_factory(x)
diff --git a/api/test/unit/views/image_views_test.py b/api/test/unit/views/image_views_test.py
index a9580f01c..c463532d6 100644
--- a/api/test/unit/views/image_views_test.py
+++ b/api/test/unit/views/image_views_test.py
@@ -18,7 +18,7 @@ _MOCK_IMAGE_INFO = json.loads((_MOCK_IMAGE_PATH / "sample-image-info.json").read
@dataclass
class RequestsFixture:
requests: list[Request]
- response_factory: Callable[
+ response_factory: Callable[ # noqa: E731
[Request], Response
] = lambda x: RequestsFixture._default_response_factory(x)
diff --git a/templates/.pre-commit-config.yaml.jinja b/templates/.pre-commit-config.yaml.jinja
index cfa363e83..ac24915e5 100644
--- a/templates/.pre-commit-config.yaml.jinja
+++ b/templates/.pre-commit-config.yaml.jinja
@@ -54,14 +54,10 @@ repos:
args:
- --py310-plus
- # Use the `.flake8` file to configure additional project-specific requirements.
- - repo: https://github.com/PyCQA/flake8
- rev: 3.9.2
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
+ rev: "v0.0.257"
hooks:
- - id: flake8
- args:
- - --extend-ignore=E203,W503
- - --max-line-length=88
+ - id: ruff
- repo: https://github.com/ambv/black
rev: 22.3.0