mirror of https://github.com/scrapy/scrapy.git
Merge remote-tracking branch 'origin/master' into sessions
This commit is contained in:
commit
2a70758ba5
|
|
@ -27,7 +27,7 @@ repos:
|
|||
hooks:
|
||||
- id: sphinx-lint
|
||||
- repo: https://github.com/scrapy/sphinx-scrapy
|
||||
rev: 0.8.10
|
||||
rev: 0.8.11
|
||||
hooks:
|
||||
- id: sphinx-scrapy
|
||||
- repo: https://github.com/zizmorcore/zizmor-pre-commit
|
||||
|
|
|
|||
|
|
@ -137,14 +137,6 @@ def source_role(
|
|||
return [node], []
|
||||
|
||||
|
||||
def issue_role(
|
||||
name, rawtext, text: str, lineno, inliner, options=None, content=None
|
||||
) -> tuple[list[Any], list[Any]]:
|
||||
ref = "https://github.com/scrapy/scrapy/issues/" + text
|
||||
node = nodes.reference(rawtext, "issue " + text, refuri=ref)
|
||||
return [node], []
|
||||
|
||||
|
||||
def commit_role(
|
||||
name, rawtext, text: str, lineno, inliner, options=None, content=None
|
||||
) -> tuple[list[Any], list[Any]]:
|
||||
|
|
@ -164,7 +156,6 @@ def rev_role(
|
|||
def setup(app: Sphinx) -> dict[str, Any]:
|
||||
app.add_role("source", source_role)
|
||||
app.add_role("commit", commit_role)
|
||||
app.add_role("issue", issue_role)
|
||||
app.add_role("rev", rev_role)
|
||||
|
||||
app.add_node(
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ middleware with a :ref:`custom downloader middleware
|
|||
|
||||
- If you can meet the installation requirements, use pyre2_ instead of
|
||||
Python’s re_ to compile your URL-filtering regular expression. See
|
||||
:issue:`1908`.
|
||||
:gh:`1908`.
|
||||
|
||||
See also `other suggestions at StackOverflow
|
||||
<https://stackoverflow.com/q/36440681>`__.
|
||||
|
|
@ -419,7 +419,7 @@ Running ``runspider`` I get ``error: No spider found in file: <filename>``
|
|||
This may happen if your Scrapy project has a spider module with a name that
|
||||
conflicts with the name of one of the `Python standard library modules`_, such
|
||||
as ``csv.py`` or ``os.py``, or any `Python package`_ that you have installed.
|
||||
See :issue:`2680`.
|
||||
See :gh:`2680`.
|
||||
|
||||
|
||||
.. _has been reported: https://github.com/scrapy/scrapy/issues/2905
|
||||
|
|
|
|||
4002
docs/news.rst
4002
docs/news.rst
File diff suppressed because it is too large
Load Diff
|
|
@ -6,4 +6,4 @@ sphinx-notfound-page
|
|||
sphinx-reredirects
|
||||
sphinx-rtd-theme
|
||||
sphinx-rtd-dark-mode
|
||||
sphinx-scrapy @ git+https://github.com/scrapy/sphinx-scrapy.git@0.8.10
|
||||
sphinx-scrapy @ git+https://github.com/scrapy/sphinx-scrapy.git@0.8.11
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ sphinx-rtd-theme==3.1.0
|
|||
# via
|
||||
# -r docs/requirements.in
|
||||
# sphinx-rtd-dark-mode
|
||||
sphinx-scrapy @ git+https://github.com/scrapy/sphinx-scrapy.git@fe176adc1a8577601bc3fa39b590ebed71a7e9b8
|
||||
sphinx-scrapy @ git+https://github.com/scrapy/sphinx-scrapy.git@6f8e5e0bbd171a857da480f7188f2a205041cb60
|
||||
# via -r docs/requirements.in
|
||||
sphinx-sitemap==2.9.0
|
||||
# via sphinx-scrapy
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
from datetime import datetime, timezone
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from scrapy import Spider, signals
|
||||
from scrapy.exceptions import NotConfigured
|
||||
from scrapy.exceptions import NotConfigured, ScrapyDeprecationWarning
|
||||
from scrapy.utils.asyncio import AsyncioLoopingCall, create_looping_call
|
||||
from scrapy.utils.serialize import ScrapyJSONEncoder
|
||||
|
||||
|
|
@ -38,6 +39,7 @@ class PeriodicLog:
|
|||
):
|
||||
self.stats: StatsCollector = stats
|
||||
self.interval: float = interval
|
||||
self._multiplier: float = 60.0 / interval
|
||||
self.task: AsyncioLoopingCall | LoopingCall | None = None
|
||||
self.encoder: JSONEncoder = ScrapyJSONEncoder(sort_keys=True, indent=4)
|
||||
self.ext_stats_enabled: bool = bool(ext_stats)
|
||||
|
|
@ -56,6 +58,24 @@ class PeriodicLog:
|
|||
)
|
||||
self.ext_timing_enabled: bool = ext_timing_enabled
|
||||
|
||||
@property
|
||||
def multiplier(self) -> float:
|
||||
warnings.warn(
|
||||
"The PeriodicLog.multiplier attribute is deprecated.",
|
||||
ScrapyDeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self._multiplier
|
||||
|
||||
@multiplier.setter
|
||||
def multiplier(self, value: float) -> None:
|
||||
warnings.warn(
|
||||
"The PeriodicLog.multiplier attribute is deprecated.",
|
||||
ScrapyDeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self._multiplier = value
|
||||
|
||||
@classmethod
|
||||
def from_crawler(cls, crawler: Crawler) -> Self:
|
||||
interval: float = crawler.settings.getfloat("LOGSTATS_INTERVAL")
|
||||
|
|
|
|||
|
|
@ -27,9 +27,7 @@ from twisted.internet.defer import Deferred, maybeDeferred
|
|||
from scrapy.exceptions import IgnoreRequest, NotConfigured, ScrapyDeprecationWarning
|
||||
from scrapy.http import Request, Response
|
||||
from scrapy.http.request import NO_CALLBACK
|
||||
from scrapy.pipelines.media import (
|
||||
FileException as FileException, # noqa: PLC0414 # re-exported for backward compatibility
|
||||
)
|
||||
from scrapy.pipelines.media import FileException as _FileException
|
||||
from scrapy.pipelines.media import (
|
||||
FileInfo,
|
||||
FileInfoOrError,
|
||||
|
|
@ -626,7 +624,7 @@ class FilesPipeline(MediaPipeline):
|
|||
f"{request} referred in <{referer}>: {failure.value}",
|
||||
extra={"spider": info.spider},
|
||||
)
|
||||
raise FileException
|
||||
raise _FileException
|
||||
|
||||
async def media_downloaded(
|
||||
self,
|
||||
|
|
@ -645,7 +643,7 @@ class FilesPipeline(MediaPipeline):
|
|||
{"status": response.status, "request": request, "referer": referer},
|
||||
extra={"spider": info.spider},
|
||||
)
|
||||
raise FileException("download-error")
|
||||
raise _FileException("download-error")
|
||||
|
||||
if not response.body:
|
||||
logger.warning(
|
||||
|
|
@ -654,7 +652,7 @@ class FilesPipeline(MediaPipeline):
|
|||
{"request": request, "referer": referer},
|
||||
extra={"spider": info.spider},
|
||||
)
|
||||
raise FileException("empty-content")
|
||||
raise _FileException("empty-content")
|
||||
|
||||
status = "cached" if "cached" in response.flags else "downloaded"
|
||||
logger.debug(
|
||||
|
|
@ -670,7 +668,7 @@ class FilesPipeline(MediaPipeline):
|
|||
checksum: str = await ensure_awaitable(
|
||||
self.file_downloaded(response, request, info, item=item)
|
||||
)
|
||||
except FileException as exc:
|
||||
except _FileException as exc:
|
||||
logger.warning(
|
||||
"File (error): Error processing file from %(request)s "
|
||||
"referred in <%(referer)s>: %(errormsg)s",
|
||||
|
|
@ -687,7 +685,7 @@ class FilesPipeline(MediaPipeline):
|
|||
exc_info=True,
|
||||
extra={"spider": info.spider},
|
||||
)
|
||||
raise FileException(str(exc)) from exc
|
||||
raise _FileException(str(exc)) from exc
|
||||
|
||||
return {
|
||||
"url": request.url,
|
||||
|
|
@ -770,3 +768,15 @@ class FilesPipeline(MediaPipeline):
|
|||
if media_type:
|
||||
media_ext = cast("str", mimetypes.guess_extension(media_type))
|
||||
return f"full/{media_guid}{media_ext}"
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
if name == "FileException":
|
||||
warnings.warn(
|
||||
"scrapy.pipelines.files.FileException is deprecated, use "
|
||||
"scrapy.pipelines.media.FileException instead.",
|
||||
ScrapyDeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return _FileException
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
|
|
|||
|
|
@ -18,13 +18,8 @@ from itemadapter import ItemAdapter
|
|||
from scrapy.exceptions import NotConfigured, ScrapyDeprecationWarning
|
||||
from scrapy.http import Request, Response
|
||||
from scrapy.http.request import NO_CALLBACK
|
||||
from scrapy.pipelines.files import (
|
||||
FileException,
|
||||
FilesPipeline,
|
||||
GCSFilesStore,
|
||||
S3FilesStore,
|
||||
_md5sum,
|
||||
)
|
||||
from scrapy.pipelines.files import FilesPipeline, GCSFilesStore, S3FilesStore, _md5sum
|
||||
from scrapy.pipelines.media import FileException
|
||||
from scrapy.utils.defer import ensure_awaitable
|
||||
from scrapy.utils.python import to_bytes
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Any
|
|||
|
||||
import pytest
|
||||
|
||||
from scrapy.exceptions import NotConfigured
|
||||
from scrapy.exceptions import NotConfigured, ScrapyDeprecationWarning
|
||||
from scrapy.extensions.periodic_log import PeriodicLog
|
||||
from scrapy.utils.misc import build_from_crawler
|
||||
from scrapy.utils.test import get_crawler
|
||||
|
|
@ -249,3 +249,17 @@ class TestPeriodicLog:
|
|||
assert data["time"]["log_interval_real"] >= 0
|
||||
assert data["time"]["elapsed"] >= 0
|
||||
assert data["time"]["start_time"] <= data["time"]["utcnow"]
|
||||
|
||||
def test_multiplier_deprecated(self) -> None:
|
||||
crawler = get_crawler(
|
||||
MetaSpider,
|
||||
{"PERIODIC_LOG_TIMING_ENABLED": True, "LOGSTATS_INTERVAL": 30},
|
||||
)
|
||||
crawler._apply_settings()
|
||||
ext = build_from_crawler(PeriodicLog, crawler)
|
||||
with pytest.warns(ScrapyDeprecationWarning):
|
||||
assert ext.multiplier == 2.0
|
||||
with pytest.warns(ScrapyDeprecationWarning):
|
||||
ext.multiplier = 3.0
|
||||
with pytest.warns(ScrapyDeprecationWarning):
|
||||
assert ext.multiplier == 3.0
|
||||
|
|
|
|||
|
|
@ -24,18 +24,18 @@ from twisted.internet.defer import Deferred
|
|||
from twisted.python.failure import Failure
|
||||
|
||||
from scrapy.crawler import Crawler
|
||||
from scrapy.exceptions import IgnoreRequest, NotConfigured
|
||||
from scrapy.exceptions import IgnoreRequest, NotConfigured, ScrapyDeprecationWarning
|
||||
from scrapy.http import Request, Response
|
||||
from scrapy.item import Field, Item
|
||||
from scrapy.pipelines import files
|
||||
from scrapy.pipelines.files import (
|
||||
FileException,
|
||||
FilesPipeline,
|
||||
FSFilesStore,
|
||||
FTPFilesStore,
|
||||
GCSFilesStore,
|
||||
S3FilesStore,
|
||||
)
|
||||
from scrapy.pipelines.media import _MediaRequestFiltered
|
||||
from scrapy.pipelines.media import FileException, _MediaRequestFiltered
|
||||
from scrapy.settings import Settings
|
||||
from scrapy.utils.asyncio import call_later
|
||||
from scrapy.utils.defer import maybe_deferred_to_future
|
||||
|
|
@ -1249,3 +1249,11 @@ def test_files_pipeline_raises_notconfigured_when_files_store_invalid(store):
|
|||
|
||||
with pytest.raises(NotConfigured):
|
||||
build_from_crawler(FilesPipeline, crawler)
|
||||
|
||||
|
||||
def test_file_exception_deprecated_import():
|
||||
with pytest.warns(ScrapyDeprecationWarning, match="FileException"):
|
||||
assert files.FileException is FileException
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
files.nonexistent
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ from twisted.python.failure import Failure
|
|||
from scrapy import signals
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
from scrapy.http import Request, Response
|
||||
from scrapy.pipelines.files import FileException
|
||||
from scrapy.pipelines.media import (
|
||||
FileException,
|
||||
FileInfo,
|
||||
FileInfoOrError,
|
||||
MediaPipeline,
|
||||
|
|
|
|||
4
tox.ini
4
tox.ini
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
[tox]
|
||||
requires =
|
||||
sphinx-scrapy[tox] @ git+https://github.com/scrapy/sphinx-scrapy.git@0.8.10
|
||||
sphinx-scrapy[tox] @ git+https://github.com/scrapy/sphinx-scrapy.git@0.8.11
|
||||
tox-uv
|
||||
envlist =
|
||||
pre-commit
|
||||
|
|
@ -124,7 +124,7 @@ commands =
|
|||
[testenv:twinecheck]
|
||||
basepython = python3
|
||||
deps =
|
||||
twine==6.2.0
|
||||
twine==7.0.0
|
||||
build==1.5.0
|
||||
commands =
|
||||
python -m build --sdist
|
||||
|
|
|
|||
Loading…
Reference in New Issue