On Tue, 8 Apr 2008 22:40:40 -0400
Douglas Mayle <[EMAIL PROTECTED]> wrote:
> Hi everybody, I was hoping to ask for a bit of help...
>
> I've been trying various ways to share metadata between modules so
> that one module I import can use and improve upon the models I've
> created in a different module, and I can't seem to get it quite
> right...
>
> Files within the same module could always just import metadata from
> a single-shared location, but since they're different modules, I
> can't seem to find another solution than metaprogramming...
I'm not sure if this will help you at all, but I puzzled on something
similar where I wanted to split my model information across multiple
modules. I can't say if it's going to work for you, but I'll just
describe it anyway :)
One of my model dirs looks like this:
$ find
.
./__init__.py
./metadata.py
./parameter.py
./part.py
./part_enumerator.py
./part_number.py
./taxon.py
metadata.py is where I obtain or create the Metadata object. Then each
of the other files is a table/class/mapper trio. They outline something
like this:
import ... # SA stuff.
from metadata import meta
part_enumerators_table = Table('part_enumerators', meta, ... )
class PartEnumerator(object):
...
from part_number import PartNumber
mapper = mapper(PartEnumerator, part_enumerators_table,
# relations involving PartNumber ...)
The position of the part_number import is important (i.e. *after*
everything except the mapper which needs it). Since the various modules
in there circularly import each other, everything that might get
imported to somewhere else has to already be defined or you get an
ImportError saying it can't import the name [1]. I lost my objectivity
more than once trying to figure *that* one out. Don't know if that's a
good habit or not but it works like a champ.
Also of note is that metadata module can get the SA Metadata object from
somewhere else or construct one, it doesn't much matter to the rest of
the modules. That can probably be accomplished by importing metadata,
giving it some external Metadata instance, and then importing everything
else.
There may be something more subtle to your question that I'm missing,
and if so you could clarify and I'll try to assist, but I hope this
helps.
-Kyle
[1] Basic reason for this involves details of how the import statement
itself actually works, which took me awhile to uncover. I can
elaborate if you are interested :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---