Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
53 changes: 0 additions & 53 deletions .flake8

This file was deleted.

27 changes: 6 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
repos:
- hooks:
- id: black
language_version: python3
repo: https://github.com/ambv/black
rev: 24.10.0
- hooks:
- id: isort
language_version: python3
repo: https://github.com/PyCQA/isort
rev: 5.13.2
- hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-docstrings
- flake8-string-format
repo: https://github.com/pycqa/flake8
rev: 7.1.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.1
hooks:
- id: ruff-check
args: [ --fix ]
- id: ruff-format
7 changes: 3 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import pkgutil
import sys
from datetime import datetime
from pathlib import Path

sys.path.insert(0, os.path.abspath("../"))
sys.path.insert(0, str(Path(__file__).parent.parent))


def get_copyright(attribution, *, first_year):
Expand All @@ -29,7 +28,7 @@ def get_copyright(attribution, *, first_year):

def get_version_and_release():
try:
import scrapy_poet # noqa: F401
import scrapy_poet # noqa: F401,PLC0415
except ImportError:
return "", ""
version_bytes = pkgutil.get_data("scrapy_poet", "VERSION") or b""
Expand All @@ -42,7 +41,7 @@ def get_version_and_release():
# -- Project information -----------------------------------------------------

project = "scrapy-poet"
copyright = get_copyright("Zyte Group Ltd", first_year=2019)
project_copyright = get_copyright("Zyte Group Ltd", first_year=2019)
author = "Zyte"

version, release = get_version_and_release()
Expand Down
7 changes: 3 additions & 4 deletions example/example/autoextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
which even requires an API request.
"""

from typing import Any, Dict
from typing import Any

import attr
from scrapy import Request
Expand All @@ -18,7 +18,7 @@
class AutoextractProductResponse:
"""Input data"""

data: Dict[str, Any]
data: dict[str, Any]


class AutoextractProductProvider(PageObjectInputProvider):
Expand Down Expand Up @@ -51,5 +51,4 @@ def url(self):
return self.autoextract_resp.data["product"]["url"]

def to_item(self):
product = self.autoextract_resp.data["product"]
return product
return self.autoextract_resp.data["product"]
2 changes: 1 addition & 1 deletion example/example/spiders/books_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""

import scrapy
from example.autoextract import ProductPage

from example.autoextract import ProductPage
from scrapy_poet import callback_for


Expand Down
3 changes: 2 additions & 1 deletion example/example/spiders/books_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"""

import scrapy
from example.autoextract import ProductPage
from web_poet import WebPage

from example.autoextract import ProductPage


class BookListPage(WebPage):
def product_urls(self):
Expand Down
2 changes: 1 addition & 1 deletion example/example/spiders/books_05_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"""

import scrapy
from example.autoextract import ProductPage
from web_poet import WebPage

from example.autoextract import ProductPage
from scrapy_poet import DummyResponse


Expand Down
160 changes: 151 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[tool.black]
line-length = 88

[tool.bumpversion]
current_version = "0.26.0"
commit = true
Expand Down Expand Up @@ -34,12 +31,6 @@ exclude_also = [
"@(abc\\.)?abstractmethod",
]

[tool.isort]
profile = "black"
multi_line_output = 3
# scrapy_poet/__init__.py: Automatic sorting causes circular dependencies.
skip = ["scrapy_poet/__init__.py"]

[[tool.mypy.overrides]]
module = [
"tests.test_cache.*",
Expand All @@ -51,3 +42,154 @@ module = [
# when test cases are decorated with @inlineCallbacks. However, the
# tests doesn't return anything at all.
disable_error_code = "misc"

[tool.ruff.lint]
extend-select = [
# flake8-builtins
"A",
# flake8-async
"ASYNC",
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# flake8-commas
"COM",
# pydocstyle
"D",
# flake8-future-annotations
"FA",
# flynt
"FLY",
# refurb
"FURB",
# isort
"I",
# flake8-implicit-str-concat
"ISC",
# flake8-logging
"LOG",
# Perflint
"PERF",
# pygrep-hooks
"PGH",
# flake8-pie
"PIE",
# pylint
"PL",
# flake8-pytest-style
"PT",
# flake8-use-pathlib
"PTH",
# flake8-pyi
"PYI",
# flake8-quotes
"Q",
# flake8-return
"RET",
# flake8-raise
"RSE",
# Ruff-specific rules
"RUF",
# flake8-bandit
"S",
# flake8-simplify
"SIM",
# flake8-slots
"SLOT",
# flake8-debugger
"T10",
# flake8-type-checking
"TC",
# flake8-tidy-imports
"TID",
# pyupgrade
"UP",
# pycodestyle warnings
"W",
# flake8-2020
"YTT",
]
ignore = [
# Trailing comma missing
"COM812",
# Missing docstring in public module
"D100",
# Missing docstring in public class
"D101",
# Missing docstring in public method
"D102",
# Missing docstring in public function
"D103",
# Missing docstring in public package
"D104",
# Missing docstring in magic method
"D105",
# Missing docstring in __init__
"D107",
# One-line docstring should fit on one line with quotes
"D200",
# No blank lines allowed after function docstring
"D202",
# 1 blank line required between summary line and description
"D205",
# Multi-line docstring closing quotes should be on a separate line
"D209",
# First line should end with a period
"D400",
# First line should be in imperative mood; try rephrasing
"D401",
# First line should not be the function's "signature"
"D402",
# Too many return statements
"PLR0911",
# Too many branches
"PLR0912",
# Too many arguments in function definition
"PLR0913",
# Too many statements
"PLR0915",
# Magic value used in comparison
"PLR2004",
# String contains ambiguous {}.
"RUF001",
# Docstring contains ambiguous {}.
"RUF002",
# Comment contains ambiguous {}.
"RUF003",
# Mutable class attributes should be annotated with `typing.ClassVar`
"RUF012",
# Use of `assert` detected
"S101",
# Yoda condition detected
"SIM300",
# Add `from __future__ import annotations` to simplify
# (It's harder to keep annotations resolvable at the runtime with it.)
"FA100",
]

[tool.ruff.lint.flake8-tidy-imports]
banned-module-level-imports = [
"twisted.internet.reactor",
]

[tool.ruff.lint.isort]
split-on-trailing-comma = false

[tool.ruff.lint.per-file-ignores]
"example/*" = ["PLC0415"]
# scrapy_poet/__init__.py: Automatic import sorting causes circular dependencies.
"scrapy_poet/__init__.py" = ["F401", "I"]
"scrapy_poet/page_inputs/__init__.py" = ["F401"]
"tests/*" = ["SLOT000", "S"]

# we need to use typing.Set[] over modern alternatives with web-poet<0.19.0 && Python<3.11
# see https://github.com/scrapinghub/web-poet/pull/219
"scrapy_poet/page_input_providers.py" = ["UP006", "UP035"]
"tests/test_downloader.py" =["UP006", "UP035"]
"tests/test_providers.py" =["UP006", "UP035"]
"tests/test_request_fingerprinter.py" =["UP006", "UP035"]
"tests/test_web_poet_rules.py" =["UP006", "UP035"]

[tool.ruff.lint.pydocstyle]
convention = "pep257"
8 changes: 4 additions & 4 deletions scrapy_poet/_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def _replace_builtin(
f"{builtin_cls} entry with {new_cls}. Add {new_cls} manually to "
f"silence this warning."
)
return None
return

if new_cls in setting_value:
return None
return
for cls_or_path in setting_value:
if isinstance(cls_or_path, str):
_cls = load_object(cls_or_path)
if _cls == new_cls:
return None
return

builtin_entry: object = None
for _setting_value in (setting_value, settings[f"{setting}_BASE"]):
Expand All @@ -54,7 +54,7 @@ def _replace_builtin(
f"missing built-in entry {builtin_cls}. Cannot replace it with {new_cls}. "
f"Add {new_cls} manually to silence this warning."
)
return None
return

if pos is None:
logger.warning(
Expand Down
Loading