From ac201d310b812c53465ad6a27b033f22206dae4b Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Wed, 13 Sep 2023 16:17:52 +0400 Subject: [PATCH] Small improvements, --- docs/topics/spiders.rst | 3 ++- scrapy/addons.py | 2 +- scrapy/crawler.py | 6 ++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/topics/spiders.rst b/docs/topics/spiders.rst index 3197daf65..1ca7eda7b 100644 --- a/docs/topics/spiders.rst +++ b/docs/topics/spiders.rst @@ -142,7 +142,8 @@ scrapy.Spider method, which is handy if you want to modify them based on arguments. As a consequence, these settings aren't the final values as they can be modified later by e.g. :ref:`add-ons - `. The settings become final when the spider starts. + `. The final settings are available in the + :meth:`start_requests` method and later. :param crawler: crawler to which the spider will be bound :type crawler: :class:`~scrapy.crawler.Crawler` instance diff --git a/scrapy/addons.py b/scrapy/addons.py index 389a3cdde..9060d4f3f 100644 --- a/scrapy/addons.py +++ b/scrapy/addons.py @@ -19,7 +19,7 @@ class AddonManager: self.crawler: "Crawler" = crawler self.addons: List[Any] = [] - def apply_settings(self, settings: Settings) -> None: + def load_settings(self, settings: Settings) -> None: """Load add-ons and configurations from a settings object and apply them. This will load the add-on for every add-on path in the diff --git a/scrapy/crawler.py b/scrapy/crawler.py index ee4d6fd59..22fd65be7 100644 --- a/scrapy/crawler.py +++ b/scrapy/crawler.py @@ -79,7 +79,6 @@ class Crawler: self._init_reactor: bool = init_reactor self.crawling: bool = False - self._settings_loaded: bool = False self._started: bool = False self.extensions: Optional[ExtensionManager] = None @@ -95,11 +94,10 @@ class Crawler: install_scrapy_root_handler(self.settings) def _apply_settings(self) -> None: - if self._settings_loaded: + if self.settings.frozen: return - self._settings_loaded = True - self.addons.apply_settings(self.settings) + self.addons.load_settings(self.settings) self.stats = load_object(self.settings["STATS_CLASS"])(self) handler = LogCounterHandler(self, level=self.settings.get("LOG_LEVEL"))