Issue #1246 new

Config parser auto import full path

Nebojsa Tijanic
created an issue

Currently, reprconf builders attempt to import top level modules only. This allows for following options for values in config files:

module.variable # module will be imported by cherrypy
module.submodule.variable # This will only work if module.submodule was already imported beforehand
__import__('module.submodule', globals(), locals(), ['']).variable # This is ugly.

It would be awesome if option 2 imported the whole module path automatically.

It seems like this can be done in reprconf._Builder2.build_Getattr() function, e.g.:

class _Builder2:
    "..."
    def build_Getattr(self, o):
        parent = self.build(o.expr)
        if isinstance(parent, types.ModuleType) and not hasattr(parent, o.attrname):
            return modules('.'.join((parent.__name__, o.attrname)))
        return getattr(parent, o.attrname)

Let me know if you want me to submit a patch (I feel like there's a reason this wasn't done in the first place, heh).

Comments (0)

  1. Log in to comment