[Grok-dev] the grok package becoming an "import hub"
Martijn Faassen
faassen at startifact.com
Sun Feb 20 05:38:38 EST 2011
On 02/16/2011 10:10 AM, Sylvain Viollon wrote:
> In five.grok, I just do from grokcore.component import *, and __all__
> is defined in both packages using the API interfaces. In five.grok,
> the API interface inherit from the one of grokcore.component.
Cool, then we already have an example of this working.
> Like that, if you add an import or a feature in grokcore.component,
> and it is described in its API interface, it will be exported via
> __all__ in both packages. So I don't need to touch five.grok to get
> the new features of grokcore.component. I was thinking Grok did the
> same, and I think * import with __all__ are the perfect use-case for
> 'hub-packages'.
>
> After if you want to get a more 'magical hub', I am not sure of best
> way of doing it: you could list the packages starting with grokcore
> using pkg_resources, and automatically import names defined in their
> __all__ variable, but some packages might redefined components
> provided by other, so you like to be able to order this import step.
Yeah, I think this is too magic, also hard to understand for the reader.
I'd like to see something like:
try:
from grokcore.foo import *
except ImportError:
print "Report: grokcore.foo could not be imported"
(with better logging integration for the reporting, perhaps simply a
notify log so that it doesn't show up by default?)
I believe the grok package itself also defines an __all__ so it'd be
good to construct that from the __all__ of the underlying packages
somehow too.
Regards,
Martijn
More information about the Grok-dev
mailing list