MCPcopy
hub / github.com/scrapy/scrapy / _replace_custom_settings

Method _replace_custom_settings

tests/test_commands.py:139–151  ·  view source on GitHub ↗

Replace custom_settings in the given spider file with the given text.

(
        proj_mod_path: Path, spider_name: str, text: str
    )

Source from the content-addressed store, hash-verified

137
138 @staticmethod
139 def _replace_custom_settings(
140 proj_mod_path: Path, spider_name: str, text: str
141 ) -> None:
142 """Replace custom_settings in the given spider file with the given text."""
143 spider_path = proj_mod_path / "spiders" / f"{spider_name}.py"
144 with spider_path.open("r+", encoding="utf-8") as f:
145 content = f.read()
146 content = content.replace(
147 "custom_settings = {}", f"custom_settings = {text}"
148 )
149 f.seek(0)
150 f.write(content)
151 f.truncate()
152
153 def _assert_spider_works(self, msg: str, proj_path: Path, *args: str) -> None:
154 """The command uses the expected *CrawlerProcess, the spider works."""

Calls 4

readMethod · 0.80
openMethod · 0.45
replaceMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected