Skip to content

Internal environment

InternalEnvironment

Bases: Environment

Methods:

Name Description
__init__

Use absolute path as name for micromamba to consider the activation from a folder path, not from a name

launch

Raise an exception. See Environment.launch and ExternalEnvironment.launch

execute

Executes a function in the given module

Source code in wetlands/internal_environment.py
class InternalEnvironment(Environment):
    def __init__(self, path: Path | None, environmentManager: "EnvironmentManager") -> None:
        """Use absolute path as name for micromamba to consider the activation from a folder path, not from a name"""
        name = str(path.resolve()) if isinstance(path, Path) else path
        super().__init__(name, environmentManager)

    def launch(self, additionalActivateCommands: Commands = {}, logOutputInThread: bool = True) -> None:
        """Raise an exception. See [`Environment.launch`][wetlands.environment.Environment.launch] and [`ExternalEnvironment.launch`][wetlands.external_environment.ExternalEnvironment.launch]"""
        raise Exception("Cannot launch the main environment.")

    def execute(self, modulePath: str | Path, function: str, args: tuple = (), kwargs: dict[str, Any] = {}) -> Any:
        """Executes a function in the given module

        Args:
                modulePath: the path to the module to import
                function: the name of the function to execute
                args: the argument list for the function
                kwargs: the keyword arguments for the function

        Returns:
                The result of the function
        """
        module = self._importModule(modulePath)
        if not self._isModFunction(module, function):
            raise Exception(f"Module {modulePath} has no function {function}.")
        return getattr(module, function)(*args)

__init__(path, environmentManager)

Use absolute path as name for micromamba to consider the activation from a folder path, not from a name

Source code in wetlands/internal_environment.py
def __init__(self, path: Path | None, environmentManager: "EnvironmentManager") -> None:
    """Use absolute path as name for micromamba to consider the activation from a folder path, not from a name"""
    name = str(path.resolve()) if isinstance(path, Path) else path
    super().__init__(name, environmentManager)

launch(additionalActivateCommands={}, logOutputInThread=True)

Raise an exception. See Environment.launch and ExternalEnvironment.launch

Source code in wetlands/internal_environment.py
def launch(self, additionalActivateCommands: Commands = {}, logOutputInThread: bool = True) -> None:
    """Raise an exception. See [`Environment.launch`][wetlands.environment.Environment.launch] and [`ExternalEnvironment.launch`][wetlands.external_environment.ExternalEnvironment.launch]"""
    raise Exception("Cannot launch the main environment.")

execute(modulePath, function, args=(), kwargs={})

Executes a function in the given module

Parameters:

Name Type Description Default
modulePath str | Path

the path to the module to import

required
function str

the name of the function to execute

required
args tuple

the argument list for the function

()
kwargs dict[str, Any]

the keyword arguments for the function

{}

Returns:

Type Description
Any

The result of the function

Source code in wetlands/internal_environment.py
def execute(self, modulePath: str | Path, function: str, args: tuple = (), kwargs: dict[str, Any] = {}) -> Any:
    """Executes a function in the given module

    Args:
            modulePath: the path to the module to import
            function: the name of the function to execute
            args: the argument list for the function
            kwargs: the keyword arguments for the function

    Returns:
            The result of the function
    """
    module = self._importModule(modulePath)
    if not self._isModFunction(module, function):
        raise Exception(f"Module {modulePath} has no function {function}.")
    return getattr(module, function)(*args)