diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b411f4927..ec8693c00 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,8 @@ repos: +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.1 + hooks: + - id: ruff - repo: https://github.com/PyCQA/bandit rev: 1.7.9 hooks: diff --git a/pyproject.toml b/pyproject.toml index f25715e76..b6c02472d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -232,4 +232,25 @@ markers = [ "requires_botocore: marks tests that need botocore (but not boto3)", "requires_boto3: marks tests that need botocore and boto3", ] -filterwarnings = [] \ No newline at end of file +filterwarnings = [] + +[tool.ruff.lint] +extend-select = [ +] +ignore = [ +] + +[tool.ruff.lint.per-file-ignores] +# Exclude files that are meant to provide top-level imports +"scrapy/__init__.py" = ["E402"] +"scrapy/core/downloader/handlers/http.py" = ["F401"] +"scrapy/http/__init__.py" = ["F401"] +"scrapy/linkextractors/__init__.py" = ["E402", "F401"] +"scrapy/selector/__init__.py" = ["F401"] +"scrapy/spiders/__init__.py" = ["E402", "F401"] + +# Issues pending a review: +"docs/conf.py" = ["E402"] +"scrapy/utils/url.py" = ["F403", "F405"] +"tests/CrawlerRunner/change_reactor.py" = ["E402"] +"tests/test_loader.py" = ["E741"] diff --git a/scrapy/http/request/form.py b/scrapy/http/request/form.py index 10ad1305e..b3c3d7c7a 100644 --- a/scrapy/http/request/form.py +++ b/scrapy/http/request/form.py @@ -186,7 +186,7 @@ def _get_inputs( if not dont_click: clickable = _get_clickable(clickdata, form) - if clickable and clickable[0] not in formdata and not clickable[0] is None: + if clickable and clickable[0] not in formdata and clickable[0] is not None: values.append(clickable) formdata_items = formdata.items() if isinstance(formdata, dict) else formdata diff --git a/tests/test_pipeline_crawl.py b/tests/test_pipeline_crawl.py index 7add27aa7..9e1b1ab5b 100644 --- a/tests/test_pipeline_crawl.py +++ b/tests/test_pipeline_crawl.py @@ -218,7 +218,7 @@ class FileDownloadCrawlTestCase(TestCase): skip_pillow: str | None try: - from PIL import Image # noqa: imported just to check for the import error + from PIL import Image # noqa: F401 except ImportError: skip_pillow = "Missing Python Imaging Library, install https://pypi.org/pypi/Pillow" else: diff --git a/tests/test_pipeline_media.py b/tests/test_pipeline_media.py index cb1e2f9a1..dd8f1084a 100644 --- a/tests/test_pipeline_media.py +++ b/tests/test_pipeline_media.py @@ -19,7 +19,7 @@ from scrapy.utils.signal import disconnect_all from scrapy.utils.test import get_crawler try: - from PIL import Image # noqa: imported just to check for the import error + from PIL import Image # noqa: F401 except ImportError: skip_pillow: str | None = ( "Missing Python Imaging Library, install https://pypi.org/pypi/Pillow"