def _dummy_environment() -> Environment: """Create an environment object, add the common config source data""" if "dummy" not in environment_names(): logger.info("Creating new environment for DUMMY test suite") environment = new_environment(name="dummy", additional_metta_bootstraps=["metta_dummy"]) environment.config().add_source(PLUGIN_ID_SOURCE_DICT).set_data(CONFIG_DATA) # this looks magical, but it works because we have structured the # fixtures DICT to match expected values properly environment.add_fixtures_from_config() return get_environment(name="dummy")
def _environment(self) -> Environment: """Create an environment object, add the common config source data.""" if "default" not in environment_names(): logger.debug("Creating new environment for BINHELPER test suite") environment = new_environment(name="default") environment.config().add_source(PLUGIN_ID_SOURCE_DICT).set_data( self.config) # this looks magical, but it works because we have structured the # fixtures DICT to match default values environment.add_fixtures_from_config() return get_environment(name="default")
def main(): """Main entrypoint.""" # Tell metta to scan for automatic configuration of itself. # It starts my looking in paths upwards for a 'metta.yml' file; if it finds # one then it uses that path as a root source of config discover() env = get_environment() fixture = env.fixtures.get(interfaces=[METTA_PLUGIN_INTERFACE_ROLE_CLIENT], plugin_id="my_client") my_client = fixture.plugin while len(my_client): print(my_client.get_message())
def __init__(self, bootstrapper: str = DEFAULT_BOOTSTRAPPER, environment: str = "", state: str = ""): """Configure initial root object. Parameters: ----------- environment (str) : Environment name in case you want to switch to an alternate environment. state (str) : Environment state to consider active. Will throw an error if the state doesn't exist for the selected environment. """ # Try to make an environment using the core discover approach. This looks for a metta.yml # file and uses it as a config source, to load all other configuration. discover(boostrapper_plugin_id=bootstrapper) try: if environment == "": environment = environment_names()[0] except (KeyError, IndexError): logger.warning( "No environment object has been defined (making one now.) " "Are you in a project folder?") environment = "empty" new_environment(environment) try: self._environment = get_environment(environment) if state: self._environment.set_state(state) except KeyError as err: raise ValueError( f"Could not load environment '{environment}', not found" ) from err # collect any comands from all discovered cli plugins self._collect_commands()
def environment(environment_discover) -> Environment: """get the metta environment""" # we don't use the discover fixture, we just need it to run first # we don't pass an environment name, which gives us the default environment return get_environment()
def _dummy_environment(name: str) -> Environment: """Create an environment object, add the common config source data""" if name not in environment_names(): new_environment(name=name, additional_metta_bootstraps=[]) return get_environment(name=name)