-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from Gallaecio/add-on
Add an add-on, cover ZyteLogFormatter in the docs
- Loading branch information
Showing
10 changed files
with
143 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
def setup(app): | ||
# https://stackoverflow.com/a/13663325 | ||
# | ||
# Scrapy’s | ||
# https://github.com/scrapy/scrapy/blob/dba37674e6eaa6c2030c8eb35ebf8127cd488062/docs/_ext/scrapydocs.py#L90C16-L110C6 | ||
app.add_crossref_type( | ||
directivename="setting", | ||
rolename="setting", | ||
indextemplate="pair: %s; setting", | ||
) | ||
app.add_crossref_type( | ||
directivename="signal", | ||
rolename="signal", | ||
indextemplate="pair: %s; signal", | ||
) | ||
app.add_crossref_type( | ||
directivename="command", | ||
rolename="command", | ||
indextemplate="pair: %s; command", | ||
) | ||
app.add_crossref_type( | ||
directivename="reqmeta", | ||
rolename="reqmeta", | ||
indextemplate="pair: %s; reqmeta", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ Reference | |
components | ||
converters | ||
adapter | ||
pipelines | ||
scrapy |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
================= | ||
Scrapy components | ||
================= | ||
|
||
Item pipelines | ||
============== | ||
|
||
.. autoclass:: zyte_common_items.pipelines.AEPipeline | ||
.. autoclass:: zyte_common_items.pipelines.DropLowProbabilityItemPipeline | ||
|
||
|
||
Log formatters | ||
============== | ||
|
||
.. autoclass:: zyte_common_items.log_formatters.ZyteLogFormatter | ||
.. autoclass:: zyte_common_items.log_formatters.InfoDropItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from collections import deque | ||
|
||
from itemadapter import ItemAdapter | ||
from scrapy.settings import BaseSettings | ||
from scrapy.utils.misc import load_object | ||
|
||
from . import ZyteItemAdapter, ZyteItemKeepEmptyAdapter | ||
from .log_formatters import ZyteLogFormatter | ||
|
||
|
||
def _setdefault(settings, setting, cls, pos): | ||
setting_value = settings[setting] | ||
if not setting_value: | ||
settings[setting] = {cls: pos} | ||
return | ||
if cls in setting_value: | ||
return | ||
for cls_or_path in setting_value: | ||
if isinstance(cls_or_path, str): | ||
_cls = load_object(cls_or_path) | ||
if _cls == cls: | ||
return | ||
settings[setting][cls] = pos | ||
|
||
|
||
class Addon: | ||
def update_settings(self, settings: BaseSettings) -> None: | ||
if not any( | ||
issubclass(cls, (ZyteItemAdapter, ZyteItemKeepEmptyAdapter)) | ||
for cls in ItemAdapter.ADAPTER_CLASSES | ||
): | ||
ItemAdapter.ADAPTER_CLASSES = deque( | ||
(ZyteItemAdapter,) + tuple(ItemAdapter.ADAPTER_CLASSES) | ||
) | ||
|
||
settings.set("LOG_FORMATTER", ZyteLogFormatter, priority="addon") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters