def getModuleBody(self): ast = [ Assign([Name('__name__', Store())], Str(self._module.getName())), Assign([Name('__file__', Store())], Str(self._module.getPath() or '')), ] + self._ast #replace the import statements res = str2ast('from importlib import import_module') + self.visit(ast) #affect values to the module moduleAffectation = str2ast("moduleObject = type('Module', (), {})()", moduleObject = self._moduleVar.name) res = moduleAffectation + ModuleAffectation(self._moduleVar).visit(res) print ast2str(res) return res
def genImportWithoutAsName(self, name): """ Import, the imported element is the first of the list toto.titi.tutu => toto """ objectName = name.split('.')[0] absName = self._moreImportObject.getAbsName(name, '.'.join(self._module.getNames())) #if absName is None: # return str2ast('raise ImportError("no module named %s")' % name) return str2ast("name = import_module('%s', None)" % absName, name = objectName)
def getModuleBody(self): ast = [ Assign([Name('__name__', Store())], Str(self._module.getName())), Assign([Name('__file__', Store())], Str(self._module.getPath() or '')), ] + self._ast #replace the import statements res = str2ast('from importlib import import_module') + self.visit(ast) #affect values to the module moduleAffectation = str2ast("moduleObject = type('Module', (), {})()", moduleObject=self._moduleVar.name) res = moduleAffectation + ModuleAffectation(self._moduleVar).visit(res) print ast2str(res) return res
def genImportWithoutAsName(self, name): """ Import, the imported element is the first of the list toto.titi.tutu => toto """ objectName = name.split('.')[0] absName = self._moreImportObject.getAbsName( name, '.'.join(self._module.getNames())) #if absName is None: # return str2ast('raise ImportError("no module named %s")' % name) return str2ast("name = import_module('%s', None)" % absName, name=objectName)