Doc fixes.

This commit is contained in:
Andrey Rakhmatullin 2023-07-18 19:52:27 +04:00
parent 5c34f34ecb
commit 90dae3ee60
1 changed files with 18 additions and 10 deletions

View File

@ -34,7 +34,7 @@ This is an example where two add-ons are enabled in a project's
Writing your own add-ons
========================
Add-ons are (any) Python objects that include the following method:
Add-ons are Python classes that include the following method:
.. method:: update_settings(settings)
@ -54,9 +54,9 @@ They can also have the following method:
If present, this class method is called to create an addon instance
from a :class:`~scrapy.crawler.Crawler`. It must return a new instance
of the addon. Crawler object provides access to all Scrapy core
components like settings and signals; it is a way for pipeline to
access them and hook its functionality into Scrapy.
of the addon. The crawler object provides access to all Scrapy core
components like settings and signals; it is a way for the addon to access
them and hook its functionality into Scrapy.
:param crawler: The crawler that uses this addon
:type crawler: :class:`~scrapy.crawler.Crawler`
@ -82,7 +82,7 @@ modify :setting:`ITEM_PIPELINES`::
Fallbacks
---------
Some components provided by addons need to fallback to "default"
Some components provided by addons need to fall back to "default"
implementations, e.g. a custom download handler needs to send the request that
it doesn't handle via the default download handler, or a stats collector that
includes some additional processing but otherwise uses the default stats
@ -102,7 +102,7 @@ recommend that such custom components should be written in the following way:
the default setting (e.g. ``DOWNLOAD_HANDLERS``) in their
``update_settings()`` methods, save that value into the fallback setting
(``MY_FALLBACK_DOWNLOAD_HANDLER`` mentioned earlier) and set the default
setting to the component provided byt the addon (e.g.
setting to the component provided by the addon (e.g.
``MyDownloadHandler``). If the fallback setting is already set by the user,
they shouldn't change it.
3. This way, if there are several addons that want to modify the same setting,
@ -114,14 +114,18 @@ recommend that such custom components should be written in the following way:
Add-on examples
===============
Set some basic configuration::
Set some basic configuration:
.. code-block:: python
class MyAddon:
def update_settings(self, settings):
settings["ITEM_PIPELINES"]["path.to.mypipeline"] = 200
settings.set("DNSCACHE_ENABLED", True, "addon")
Check dependencies::
Check dependencies:
.. code-block:: python
class MyAddon:
def update_settings(self, settings):
@ -131,7 +135,9 @@ Check dependencies::
raise RuntimeError("MyAddon requires the boto library")
...
Access the crawler instance::
Access the crawler instance:
.. code-block:: python
class MyAddon:
def __init__(self, crawler) -> None:
@ -145,7 +151,9 @@ Access the crawler instance::
def update_settings(self, settings):
...
Use a fallback component::
Use a fallback component:
.. code-block:: python
from scrapy.core.downloader.handlers.http import HTTPDownloadHandler