def compile(self): """ This method will compile and prepare everything to start evaluation the configuration specification. This method will: - load all namespaces - compile the __config__ namespace - start resolving it and importing unknown namespaces """ project = Project.get() self.__root_ns = project.get_root_namespace() project.load() statements, blocks = project.get_complete_ast() # load plugins for name, cls in PluginMeta.get_functions().items(): mod_ns = cls.__module__.split(".") if mod_ns[0] != "inmanta_plugins": raise Exception( "All plugin modules should be loaded in the impera_plugins package not in %s" % cls.__module__) mod_ns = mod_ns[1:] ns = self.__root_ns for part in mod_ns: if ns is None: break ns = ns.get_child(part) if ns is None: raise Exception( "Unable to find namespace for plugin module %s" % (cls.__module__)) cls.namespace = ns name = name.split("::")[-1] statement = PluginStatement(ns, name, cls) statements.append(statement) # add the entity type (hack?) entity = DefineEntity(self.__root_ns.get_child_or_create("std"), "Entity", "The entity all other entities inherit from.", [], []) requires_rel = DefineRelation( ("std::Entity", "requires", [0, None], False), ("std::Entity", "provides", [0, None], False)) requires_rel.namespace = self.__root_ns.get_ns_from_string("std") statements.append(entity) statements.append(requires_rel) return (statements, blocks)
def p_relation_comment(p): "relation : class_ref ID multi REL multi class_ref ID mls" if not (p[4] == '--'): LOGGER.warning( "DEPRECATION: use of %s in relation definition is deprecated, use -- (in %s)" % (p[4], Location(file, p.lineno(4)))) rel = DefineRelation((p[1], p[2], p[3]), (p[6], p[7], p[5])) rel.comment = p[8] p[0] = rel attach_lnr(p, 2)
def p_relation_deprecated_comment(p: YaccProduction) -> None: "relation : class_ref ID multi REL multi class_ref ID MLS" if not (p[4] == "--"): LOGGER.warning( "DEPRECATION: use of %s in relation definition is deprecated, use -- (in %s)" % (p[4], Location(file, p.lineno(4)))) rel = DefineRelation((p[1], p[2], p[3]), (p[6], p[7], p[5])) rel.comment = str(p[8]) p[0] = rel attach_lnr(p, 2) deprecated_relation_warning(p)
def p_relation_annotated_unidir(p: YaccProduction) -> None: "relation_def : class_ref '.' ID multi operand_list class_ref" p[0] = DefineRelation((p[1], None, None), (p[6], p[3], p[4]), p[5]) attach_lnr(p, 2)
def p_relation_unidir(p: YaccProduction) -> None: "relation_def : class_ref '.' ID multi REL class_ref" p[0] = DefineRelation((p[1], None, None), (p[6], p[3], p[4])) attach_lnr(p, 2)
def compile(self) -> Tuple[List["Statement"], List["BasicBlock"]]: """ This method will parse and prepare everything to start evaluation the configuration specification. This method will: - load all modules using Project.get().get_complete_ast() - add all plugins - create std::Entity """ project = module.Project.get() self.__root_ns = project.get_root_namespace() project.load() statements, blocks = project.get_complete_ast() # load plugins for name, cls in PluginMeta.get_functions().items(): mod_ns = cls.__module__.split(".") if mod_ns[0] != const.PLUGINS_PACKAGE: raise Exception( "All plugin modules should be loaded in the %s package not in %s" % (const.PLUGINS_PACKAGE, cls.__module__) ) mod_ns = mod_ns[1:] ns: Optional[Namespace] = self.__root_ns for part in mod_ns: if ns is None: break ns = ns.get_child(part) if ns is None: raise Exception("Unable to find namespace for plugin module %s" % (cls.__module__)) name = name.split("::")[-1] statement = PluginStatement(ns, name, cls) statements.append(statement) # add the entity type (hack?) ns = self.__root_ns.get_child_or_create("std") nullrange = Range("internal", 1, 0, 0, 0) entity = DefineEntity( ns, LocatableString("Entity", nullrange, 0, ns), LocatableString("The entity all other entities inherit from.", nullrange, 0, ns), [], [], ) str_std_entity = LocatableString("std::Entity", nullrange, 0, ns) requires_rel = DefineRelation( (str_std_entity, LocatableString("requires", nullrange, 0, ns), (0, None)), (str_std_entity, LocatableString("provides", nullrange, 0, ns), (0, None)), ) requires_rel.namespace = self.__root_ns.get_ns_from_string("std") statements.append(entity) statements.append(requires_rel) return (statements, blocks)
def p_relation_new_annotated_unidir(p): "relationnew : class_ref '.' ID multi operand_list class_ref" p[0] = DefineRelation((p[1], None, None), (p[6], p[3], p[4]), p[5]) attach_lnr(p, 2)
def p_relation_new_unidir(p): "relationnew : class_ref '.' ID multi REL class_ref" p[0] = DefineRelation((p[1], None, None), (p[6], p[3], p[4])) attach_lnr(p, 2)
def p_relation_new(p): "relationnew : class_ref '.' ID multi REL class_ref '.' ID multi" p[0] = DefineRelation((p[1], p[8], p[9]), (p[6], p[3], p[4])) attach_lnr(p, 2)