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 [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. -- 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.
