Skip to content

Commit

Permalink
chore(refactor): Move activate_egg function into caller
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 19, 2024
1 parent 091f3a5 commit 6a21c9a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
22 changes: 0 additions & 22 deletions scrapyd/eggutils.py

This file was deleted.

20 changes: 19 additions & 1 deletion scrapyd/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,28 @@
import tempfile
from contextlib import contextmanager

import pkg_resources
from scrapy.utils.misc import load_object

from scrapyd import Config
from scrapyd.eggutils import activate_egg
from scrapyd.exceptions import BadEggError


def activate_egg(eggpath):
"""Activate a Scrapy egg file. This is meant to be used from egg runners
to activate a Scrapy egg file. Don't use it from other code as it may
leave unwanted side effects.
"""
distributions = pkg_resources.find_distributions(eggpath)
if isinstance(distributions, tuple):
raise BadEggError
try:
d = next(distributions)
except StopIteration:
raise BadEggError from None
d.activate()
settings_module = d.get_entry_info("scrapy", "settings").module_name
os.environ.setdefault("SCRAPY_SETTINGS_MODULE", settings_module)


@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dont_load_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SettingsSafeModulesTest(unittest.TestCase):
"scrapy.utils.project",
"scrapy.utils.conf",
"scrapyd.interfaces",
"scrapyd.eggutils",
"scrapyd.runner",
)

def test_modules_that_shouldnt_load_settings(self):
Expand Down

0 comments on commit 6a21c9a

Please sign in to comment.