I would like to share my data model between different Elixir/SQLAlchemy applications, one of which would be a Camelot UI and the others stuff like web interfaces and so on. They would all connect to the same underlying database.
As far as I know, to build a Camelot app my model would do from camelot import blah
and that would prevent it to run in any environment without Camelot installed.
I would like to know if there is a recommended way / best practice to do that. The idea is of course to maintain a single code base for my model and not to replicate it with subtle differences between different apps (like importing from SA/Elixir here, and from Camelot there, and so on).
My project is currently laid out with a model/ python package:
model/__init__.py
foo.py
bar.py
...
init.py looks like this:
from foo import a, b, c
from bar import d, e, f
__all__ = ('a', 'b', 'c', 'd', 'e', 'f')
and python modules foo.py, bar.py, and so on actually implement the various parts. Every one of these modules starts like this:
from sqlalchemy import Integer, Numeric, Date, Unicode, LargeBinary
from elixir import Entity, Field, ManyToOne, OneToMany, ManyToMany
from elixir import using_options
An idea could be to do something like:
try:
from camelot import Integer, Numeric, ...
except ImportError:
from elixir import Integer, Numeric, ...
would that be actually a good idea or there's something I'm missing? Also, ideally I'd do that kind of "environment initialization" stuff in some central place, like in model/__init__.py
, but how would I pass my imports to the underlying modules?