From 90dae3ee60b1f5ab5ea83d82ac8c00f1be54723e Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Tue, 18 Jul 2023 19:52:27 +0400 Subject: [PATCH] Doc fixes. --- docs/topics/addons.rst | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/topics/addons.rst b/docs/topics/addons.rst index cc96207bd..c432c64d2 100644 --- a/docs/topics/addons.rst +++ b/docs/topics/addons.rst @@ -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