Try not to do stuff at import
For unittest i expect to be able to load by module task to do some checks.
Here is what i got if i try to do so.
In [2]: import tomovis.ewoks.tomo_sinogram_reconstruction
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
Cell In [2], line 1
----> 1 import tomovis.ewoks.tomo_sinogram_reconstruction
File /nobackup/lvalls1/valls/workspace/daiquiri-tomo.git/tomovis.git/tomovis/ewoks/tomo_sinogram_reconstruction.py:13
11 except:
12 pass
---> 13 from sidecar.kombu.notify import notify
14 from sidecar.ewoks.exceptions import InfrastructureException
16 from silx.io import h5py_utils
File /nobackup/lvalls1/valls/workspace/daiquiri-tomo.git/sidecar.git/src/sidecar/kombu/notify.py:7
3 from typing import Any
5 from kombu import Connection, Exchange, Queue
----> 7 from ..settings import settings
10 def notify(beamline: str, message: dict[str, Any]) -> None:
11 with Connection(settings.celery_broker_url) as conn:
File /nobackup/lvalls1/valls/workspace/daiquiri-tomo.git/sidecar.git/src/sidecar/settings.py:54
50 return [x for x in raw_val.split(",")]
51 return cls.json_loads(raw_val)
---> 54 settings = Settings()
File /nobackup/lvalls1/valls/Software/miniconda3/envs/tomodemo-tomovis-env/lib/python3.9/site-packages/pydantic/env_settings.py:39, in pydantic.env_settings.BaseSettings.__init__()
File /nobackup/lvalls1/valls/Software/miniconda3/envs/tomodemo-tomovis-env/lib/python3.9/site-packages/pydantic/main.py:342, in pydantic.main.BaseModel.__init__()
ValidationError: 8 validation errors for Settings
ispyb_database_url
field required (type=value_error.missing)
ispyb_database_user
field required (type=value_error.missing)
ispyb_database_password
field required (type=value_error.missing)
celery_broker_url
field required (type=value_error.missing)
celery_backend_url
field required (type=value_error.missing)
celery_broker_queue
field required (type=value_error.missing)
ewoks_graph_location
field required (type=value_error.missing)
mimas_specifications
field required (type=value_error.missing)
I can mitigate the stuff by doing
try:
from sidecar.ispyb.autoproc import add_autoproc_attachment
from sidecar.kombu.notify import notify
except:
if os.environ["UNITTEST_CONTEXT"]:
pass
raise
Or by wrapping on my own notify
and add_autoproc_attachment
def notify(*args, **kwargs):
from sidecar.ispyb.autoproc import add_autoproc_attachment
from sidecar.kombu.notify import notify
return notify(*args, **kwargs)
But i would prefer not to do so.