def __init__( self, n_tool_id: int, alteryx_engine: sdk.AlteryxEngine, output_anchor_mgr: sdk.OutputAnchorManager, ) -> None: # Initialization data self._engine_vars = SimpleNamespace() self._engine_vars.n_tool_id = n_tool_id self._engine_vars.alteryx_engine = alteryx_engine self._engine_vars.output_anchor_mgr = output_anchor_mgr self._raised_missing = False # Plugin State vars self._state_vars = SimpleNamespace( initialized=False, input_anchors={}, output_anchors={}, config_data=None, required_input_names=[], ) # Pull in the config XML data from conf file using the name of the tool xml_files = [ file for file in os.listdir(plugin_utils.get_tool_path(self.tool_name)) if file.lower().endswith(".xml") ] with open( os.path.join(plugin_utils.get_tool_path(self.tool_name), xml_files[0]) ) as fd: self._state_vars.config_data = xmltodict.parse(fd.read()) # Plugin Error Methods self.logging = SimpleNamespace( display_error_msg=partial( self._engine_vars.alteryx_engine.output_message, self._engine_vars.n_tool_id, sdk.EngineMessageType.error, ), display_warn_msg=partial( self._engine_vars.alteryx_engine.output_message, self._engine_vars.n_tool_id, sdk.EngineMessageType.warning, ), display_info_msg=partial( self._engine_vars.alteryx_engine.output_message, self._engine_vars.n_tool_id, sdk.EngineMessageType.info, ), ) # Default to no inputs or outputs for connection in plugin_utils.get_xml_config_input_connections( self._state_vars.config_data ): self._state_vars.input_anchors[connection["@Name"]] = [] # Track names of the inputs that are required for this tool to run if connection["@Optional"] == "False": self._state_vars.required_input_names.append(connection["@Name"]) for connection in plugin_utils.get_xml_config_output_connections( self._state_vars.config_data ): self._state_vars.output_anchors[connection["@Name"]] = OutputAnchor() # Custom data self.user_data = SimpleNamespace() # Configure managers, this must occur last so the instance # is properly configured self.input_manager = InputManager(self) self.output_manager = OutputManager(self)
def update_sys_path(self) -> None: """Update the sys path to include the current tools libs.""" # Add lib to sys path tool_path = plugin_utils.get_tool_path(self.tool_name) sys.path.append(tool_path) sys.path.append(os.path.join(tool_path, "Lib", "site-packages"))