question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Are optional dependencies really optional?

See original GitHub issue

This is probably related to #88.

It seems to me that if you want to use spidermon with Scrapy you need to use spidermon.contrib.scrapy.extensions.Spidermon. That requires at least jsonschema (imported via spidermon.python.factory) from the optional validation feature. On the other hand, the contents of the optional monitoring feature look important for any spidermon usage. Are there real use cases where one or both optional features can be skipped?

Disclaimer: I’m not familiar with optional installation features that much, as most modules I’ve used don’t use them.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
raphapassinicommented, Feb 18, 2019

Or we can fix the problem by optionally import the jsonschema. IMHO I can see Spidermon being used without the validation, but doesn’t make sense if an error raises if you don’t install it

1reaction
andrewbaxtercommented, Feb 13, 2019

FWIW I’m getting an exception since it seems like jsonschema gets imported when using the extension:

Traceback (most recent call last):
  File "/myproject/env/bin/scrapy", line 11, in <module>
    sys.exit(execute())
  File "/myproject/env/lib/python3.6/site-packages/scrapy/cmdline.py", line 150, in execute
    _run_print_help(parser, _run_command, cmd, args, opts)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/cmdline.py", line 90, in _run_print_help
    func(*a, **kw)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/cmdline.py", line 157, in _run_command
    cmd.run(args, opts)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/commands/crawl.py", line 57, in run
    self.crawler_process.crawl(spname, **opts.spargs)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/crawler.py", line 170, in crawl
    crawler = self.create_crawler(crawler_or_spidercls)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/crawler.py", line 198, in create_crawler
    return self._create_crawler(crawler_or_spidercls)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/crawler.py", line 203, in _create_crawler
    return Crawler(spidercls, self.settings)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/crawler.py", line 55, in __init__
    self.extensions = ExtensionManager.from_crawler(self)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/middleware.py", line 58, in from_crawler
    return cls.from_settings(crawler.settings, crawler)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/middleware.py", line 34, in from_settings
    mwcls = load_object(clspath)
  File "/myproject/env/lib/python3.6/site-packages/scrapy/utils/misc.py", line 44, in load_object
    mod = import_module(module)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/myproject/env/lib/python3.6/site-packages/spidermon/contrib/scrapy/extensions.py", line 11, in <module>
    from spidermon.python import factory
  File "/myproject/env/lib/python3.6/site-packages/spidermon/python/__init__.py", line 3, in <module>
    from . import factory
  File "/myproject/env/lib/python3.6/site-packages/spidermon/python/factory.py", line 3, in <module>
    from jsonschema import validate
ModuleNotFoundError: No module named 'jsonschema'

I’m not using the item validation tools in this project, just item count/error count monitors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Are NPM's Optional Dependencies and When Should ...
Finally, optionalDependencies are dependencies that don't necessarily need to be installed. If a dependency can be used, but you would like npm ...
Read more >
What are Optional Dependencies and when should we use them
What are Optional Dependencies? Dependencies are libraries on which a project depends to function properly. The term optional dependencies ...
Read more >
Maven – Optional Dependencies and Dependency Exclusions
This section discusses optional dependencies and dependency exclusions. This will help users to understand what they are and when and how to use...
Read more >
What is an "optional" dependency as distinguished from a ...
Optional dependencies are not optional for your project, but when another project depends on your project, these now transitive dependencies ...
Read more >
Optional dependencies are not optional - The Gradle Blog
Conclusion. In this blog post, we've highlighted that: Optional dependencies are not optional: they are always required if you use a specific ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found