Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grant additional control to determine what logging settings should be honored #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/scrapyscript/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Processor(Process):
Blocks until all have finished.
"""

def __init__(self, settings=None):
def __init__(self, settings=None, install_root_handler=True):
"""
Parms:
settings (scrapy.settings.Settings) - settings to apply. Defaults
Expand All @@ -51,6 +51,7 @@ def __init__(self, settings=None):
self.results = Queue(**kwargs)
self.items = []
self.settings = settings or Settings()
self.install_root_handler = install_root_handler
dispatcher.connect(self._item_scraped, signals.item_scraped)

def _item_scraped(self, item):
Expand All @@ -62,7 +63,10 @@ def _crawl(self, requests):
requests (Request) - One or more Jobs. All will
be loaded into a single invocation of the reactor.
"""
self.crawler = CrawlerProcess(self.settings)
self.crawler = CrawlerProcess(
settings=self.settings,
install_root_handler=self.install_root_handler,
)

# crawl can be called multiple times to queue several requests
for req in requests:
Expand Down
8 changes: 5 additions & 3 deletions tests/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ def celery_job(url):


@app.task
def celery_job_with_custom_settings(url, settings):
def celery_job_with_custom_settings(url, settings, install_root_handler):
job = Job(ItemSpider, url=url)
return Processor(settings=settings).run(job)
return Processor(settings=settings, install_root_handler=install_root_handler).run(
job
)


class TestScrapyScriptCelery:
Expand All @@ -32,7 +34,7 @@ def test_celery_job_with_settings(self):
settings["BOT_NAME"] = "alpha"

task = celery_job_with_custom_settings.s(
"https://www.python.org", settings
"https://www.python.org", settings, False
).apply()
print(task.result[0])
assert task.result[0]["bot"] == "alpha"