I tend to use a venusian scan (a pyramid config scan does the same thing) which spiders your package and makes sure everything is imported

Check out my mortar_rdb package for some more fun and games in this area, although I need to give it a re-write to use alembic instead of the terrible sqlalchemy-migrate...

cheers,

Chris

On 01/08/2012 17:30, Michael Bayer wrote:
usually the pattern is you just import one module, like "from myapp
import model". "model/__init__.py" then has imports for everything
within, and the pattern repeats as you descend through the directory
tree, that is, every top level __init__.py imports the important bits
from within that package.

the only other way would be to do a find of .py files within a model
directory and then import them with importlib or similar, which is more
complicated, non-deterministic as far as ordering and more prone to
import resolution issues. Adding per-package imports as you go along
just creates this same traversal as part of the code.

if the Python interpreter is never told of the existence of some .py
file, it doesn't exist. it doesn't matter that "Base" is used in that
file, the classes within don't exist until their owning module is imported.



On Aug 1, 2012, at 12:07 PM, John Anderson wrote:

In my pyramid apps I have a create script that generates my database
for production and a different script that generates my database for
my tests.

But if I don't import the module the models are in then they aren't
discovered even though they all share the same Base which is the class
I get the metadata from to call create_all, like:

Base.metadata.create_all(engine)

If I import them then they are picked up but I don't want to have to
remember to import every new module I create. Is there a good way to
do model discovery for this?

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/r95QN9vJ_IgJ.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.

--
Simplistix - Content Management, Batch Processing & Python Consulting
            - http://www.simplistix.co.uk

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to