pcdshub / happi

Heuristic Access to Positions of Photon Instruments
https://pcdshub.github.io/happi/master
Other
13 stars 29 forks source link

Direct dependency for mongo backend 'bson' not listed as dev-requirement #325

Closed klauer closed 1 year ago

klauer commented 1 year ago

Expected Behavior

Any import which is directly imported should be represented in our requirements.txt for package-wide requirements or dev-requirements.txt for "full functionality" with optional dependencies (such as here in the mongo backend)

bson is used in the (optional) mongo backend ~so it should be a dev-requirement~ (see below)

Current Behavior

bson is used in the mongo backend but is not listed as a requirement anywhere. ~It's likely assumed to come from a dependency-of-a-dependency.~ (It's a vendored dep from mongo per Robert below)

Possible Solution

Steps to Reproduce (for bugs)

Without mongo installed, the backend fails with this first:

ERROR happi/tests/test_backends.py::test_multi_backend - ModuleNotFoundError: No module named 'bson'

Context

Testing Python 3.11-related issues

Your Environment

OSX + conda

klauer commented 1 year ago

I think this was user error (PATH was finding the wrong Python) That said, it still should be in our dev-requirements in my opinion

tangkong commented 1 year ago

I think this is actually a dependency / component of pymongo, in which case pymongo instructs us to explicitly not install bson from pypi or otherwise https://github.com/mongodb/mongo-python-driver/blob/master/pyproject.toml#installation (pymongo packages/vendors a version of bson)

klauer commented 1 year ago

Oh, huh... Good catch! I think it might be wise to have a commented-out version of "bson" in our requirements making note of that. It'd be rather easy to forget the reason

tangkong commented 1 year ago

100% agreed, this is quite the strange edge case

klauer commented 1 year ago

On that note it'd probably be good to raise something different if bson isn't found "ImportError: bson" is weird when you import the mongo backend. Something like: raise ImportError("Optional dependency mongodb not found; the mongodb backend is unavailable")

tangkong commented 1 year ago

Given that bson is supposed to come with pymongo I'm a little confused about why it didn't make it into your environment though...

klauer commented 1 year ago

Given that bson is supposed to come with pymongo I'm a little confused about why it didn't make it into your environment though...

User error 😁 Sometimes my fancy development environment is too magical even for me...