BaseEnvShell
Base class for shell proxies that manage virtual environments.
This abstract class extends ShellProxy to provide functionality for creating, managing, and executing commands within isolated virtual environments. It handles:
- Virtual environment installation and uninstallation
- Environment file hashing for version tracking
- Command formatting for environment activation
- Environment metadata management
Subclasses must implement environment-specific methods for different package managers (conda, mamba, pip).
Example: Running a Python script in a virtual environment
⚠️ IMPORTANT: Scripts or folders must start with '_' (underscore) to be ignored during lab start ⚠️
Example structure: bricks/ my_brick/ scripts/ # ← Folder starts with '' to be ignored env.yml my_script.py # ← Script starts with '' to be ignored
Usage example:
from gws_core import MambaShellProxy
shell = MambaShellProxy(
env_file_path="/path/to/_scripts/env.yml",
env_name="my_script_env", # Optional: custom name )
## Run your Python script
## The virtual environment will be automatically installed if not already present
exit_code = shell.run("python _my_script.py")
Note: Files and folders starting with '_' are ignored by the lab system during startup, preventing them from being loaded as bricks or modules. This is essential for utility scripts, test scripts, or any code that should not be part of the main application.
CONFIG_FILE_NAME: strenv_file_path: strenv_hash: strenv_name: strworking_dir: strInitialize a BaseEnvShell instance.
pathlib.Path | strstr | Nonestr | Nonegws_core.core.classes.observer.message_dispatcher.MessageDispatcher | NoneAttach a custom observer to the shell proxy.
The logs of the proxy will be dispatched to the observer.
MessageObserverAttach a progress bar to the shell proxy.
The logs of the proxy will be dispatched to the progress bar logs.
ProgressBarRun a command in a shell and return the output. There logs of the command are ignored.
list | strdict | NoneShellProxyEnvVariableMode - ShellProxyEnvVariableMode.MERGEbool | Nonebool - TrueAnyDelete the working directory and all its contents.
Create the environment directory if it doesn't exist.
PathForce the message dispatcher to send all buffered messages immediately.
Check if the virtual environment is installed.
boolFormat the user command for execution within the virtual environment.
Subclasses must implement this to wrap commands with environment activation logic. If the command is a list, must return a list. If it's a string, must return a string.
list | strlist | strGet the path of the configuration file used to create the environment.
strGet the default environment variables for the shell proxy. To override in subclasses to provide custom additional default environment variables.
dictGet the absolute path for the environment directory.
All environments are stored in the global env directory, with subdirectories named by their environment hash.
strGet the message dispatcher instance.
MessageDispatcherInstall the virtual env. Return True if the env was installed, False if it was already installed, or an error occured.
boolList all installed packages with their versions in the virtual environment.
Returns a dictionary where keys are package names and values are version strings. Only works if the environment is installed.
dictLog an error message using the dispatcher.
strLog an info message using the dispatcher.
strLog a warning message using the dispatcher.
strRead the environment configuration file and return its content.
strRun a command in a shell. The logs of the command will be dispatched to the message dispatcher during the execution.
list | strdict | NoneShellProxyEnvVariableMode - ShellProxyEnvVariableMode.MERGEbool | Nonebool - Falsebool - TrueintRun a command in a shell without blocking the thread. There logs of the command are ignored.
list | strdict | NoneShellProxyEnvVariableMode - ShellProxyEnvVariableMode.MERGEbool | NoneSysProcConvert the ShellProxy instance to a data transfer object.
ShellProxyDTOUninstall the virtual env. Return true if the env was uninstalled, False if it was already uninstalled or an error occured.
boolReturns the name of the class
bool - Falsebool - Falsebool - FalsestrCheck if a folder is a valid environment folder.
strboolCreate a virtual environment from a string containing the environment definition.
The environment directory name is generated from a hash of the env_str, so identical environment strings will share the same environment directory.
strgws_core.core.classes.observer.message_dispatcher.MessageDispatcher | NoneBaseEnvShellTypeReturns the full name of the class
bool - Falsebool - FalsestrstrVersionGet the environment creation information from the metadata file.
strVEnvCreationInfoGet the type of environment manager used.
LiteralGet the human name of the object
strGet the short description of the object
strGet the style of the object
TypingStyleGet the typing name of the object Ex: 'RESOURCE.gws_core.Table'
strTypingNameObjCreate an MD5 hash from the environment string.
Removes whitespace and newlines before hashing to ensure consistent hashes for equivalent environment definitions.
strstrGet all the classes that inherit this class
list