Login
Back to bricks list
Introduction Version

PipShellProxy

Shell task proxy.

This class is a proxy to Shell commandes. It allow running commands in a shell and get the output and stdout.

Attributes

CONFIG_FILE_NAME: strenv_file_path: strenv_hash: strenv_name: strworking_dir: str

Functions

__INIT__

summary

                  will be used to create the env. If the env file has changed, the env will be recreated and
                  previous env will be deleted.
                If not provided, an new temp directory is created. defaults to None
                      Can be useful to log command outputs in task's logs. defaults to None

:raises Exception: description :raises Exception: description

Parameters:
NameTypeDefault valueDescription
env_namestr Name of the environment. this name will be shown in the env list. if not provided, a name is generated
env_file_pathUnion Path to the env file. this file must contained dependencies for the virtual env and str
working_dirstr Working directory for the shell (all command will be executed from this dir). , optional
message_dispatcherMessageDispatcher If provided, the output of the command will be redirected to the dispatcher. , optional
ATTACH_OBSERVER

Attach a custom observer to the shell proxy. The logs of the proxy will be dispatch to the observer

Parameters:
NameTypeDefault valueDescription
observerMessageObserver
ATTACH_PROGRESS_BAR

Attach a progress_bar to the shell proxy. The logs of the proxy will be dispatch to the progress_bar logs

Parameters:
NameTypeDefault valueDescription
progress_barProgressBar
BUILD_OS_ENV

Creates the OS environment variables that are passed to the shell command

Return type:
dict
CHECK_OUTPUT

Run a command in a shell and return the output.

:raises Exception: description

Parameters:
NameTypeDefault valueDescription
cmdUnion Command to run [list, str]
envdict Environment variables to pass to the shell, defaults to none , optional
shell_modebool False If true, the command is run in a shell, defaults to false , optional
textbool True If true, the output is returned as a string, defaults to true , optional
Return type:
Any
CLEAN_WORKING_DIR
CREATE_ENV_DIR

Create the env dir.

Return type:
Path
DISPATCH_WAITING_MESSAGES
ENV_IS_INSTALLED

Returns True if the virtual env is installed. False otherwise

Return type:
bool
FORMAT_COMMAND

This method builds the command to execute.

Parameters:
NameTypeDefault valueDescription
user_cmdUnion
Return type:
str
GET_CONFIG_FILE_PATH

Returns the path of the config file used to create the env

Return type:
str
GET_ENV_DIR_PATH

Returns the absolute path for the env dir base on a dir name. All env are in the global env dir.

Return type:
str
GET_MESSAGE_DISPATCHER

Get the message dispatcher

Return type:
MessageDispatcher
GET_PIP_FILE_PATH
Return type:
str
INSTALL_ENV

Install the virtual env. Return True if the env was installed, False if it was already installed, or an error occured.

Return type:
bool
LOG_ERROR_MESSAGE

Log an error message using the dispatcher

Parameters:
NameTypeDefault valueDescription
messagestr
LOG_INFO_MESSAGE

Log an info message using the dispatcher

Parameters:
NameTypeDefault valueDescription
messagestr
LOG_WARNING_MESSAGE

Log a warining message using the dispatcher

Parameters:
NameTypeDefault valueDescription
messagestr
RUN

Run a command in a shell. The logs of the command will be dispatched to the message dispatcher during the execution.

Parameters:
NameTypeDefault valueDescription
cmdUnion Command to run [list, str]
envdict Environment variables to pass to the shell, defaults to none , optional
shell_modebool True If true, the command is run in a shell, defaults to false , optional
Return type:
int
UNINSTALL_ENV

Uninstall the virtual env. Return true if the env was uninstalled, False if it was already uninstalled or an error occured.

Return type:
bool
FOLDER_IS_ENV - @classmethod

return true if the folder is a valid env folder

Parameters:
NameTypeDefault valueDescription
folder_pathstr
Return type:
bool
FROM_ENV_STR - @classmethod

Create the virtual environment from a string containing the environment definition.

The env dir name is generated from an hash of the env_str. So if the env_str is the same, the env dir name will be the same.

Parameters:
NameTypeDefault valueDescription
env_strstr
message_dispatcherMessageDispatcher
Return type:
BaseEnvShell
GET_CREATION_INFO - @classmethod

Returns the json info file content

Parameters:
NameTypeDefault valueDescription
folder_pathstr
Return type:
VEnvCreationInfo
GET_ENV_TYPE - @classmethod

Returns the type of the env

Return type:
Literal
HASH_ENV_STR - @classmethod

Create a hash from the env_str to generate a unique env dir name.

Parameters:
NameTypeDefault valueDescription
env_strstr
Return type:
str