-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Allow to pass objects in Settings? #3870
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
Comments
Thanks for bringing it up, I don't think we have a dedicated ticket for this. +1 to add this feature. It has been discussed in #1215, #1032; I recall https://github.com/scrapy/scrapy/pull/1272/files also has an implementation for this. |
Oh, now that you bring those links, I faintly remember... # haxx: sad monkeypatch, might break
from importlib import import_module
def load_object(path):
try:
dot = path.rindex('.')
except ValueError:
raise ValueError("Error loading object '%s': not a full path" % path)
except AttributeError:
return path # hax
module, name = path[:dot], path[dot+1:]
mod = import_module(module)
try:
obj = getattr(mod, name)
except AttributeError:
raise NameError("Module '%s' doesn't define any object named '%s'" % (module, name))
return obj
scrapy.utils.misc.load_object = load_object
# end haxx @kmike, I see there were some reservations about this in #1215. Would you say they continue to apply? |
It was years ago, but as I recall I had reservations about instantiated objects (they look tricky because they often need to be tied to Crawler, or be created with |
Closes: scrapy#1215, scrapy#1032, scrapy#3870 Thanks
Okay in that case, have fun reviewing once more, in #3873 :) That one doesn't load instanced objects, if I tried, I'd get |
Closes: scrapy#1215, scrapy#1032, scrapy#3870 Thanks
Closes: scrapy#1215, scrapy#1032, scrapy#3870 Thanks
Done in #3873 |
See code example; why can I not reference plain objects into
Settings()
, but need to let Scrapy handle the import magic?Would it make sense to have this? it seems "unclean" to do this in the usual
settings.py
environment, but in a single-script setup it looks less convoluted than to refer scrapy to import from current module?The text was updated successfully, but these errors were encountered: