rez.shells#
Pluggable API for creating subshells using different programs, such as bash.
- rez.shells.get_shell_types()#
Returns the available shell types: bash, tcsh etc.
Returns: List of str: Shells.
- rez.shells.get_shell_class(shell=None)#
Get the plugin class associated with the given or current shell.
- Returns:
Plugin class for shell.
- Return type:
class
- rez.shells.create_shell(shell=None, **kwargs)#
Returns a Shell of the given or current type.
- Returns:
Instance of given shell.
- Return type:
Shell
- class rez.shells.Shell#
Class representing a shell, such as bash or tcsh.
- classmethod name()#
Plugin name.
- classmethod executable_name()#
Name of executable to create shell instance.
- classmethod executable_filepath()#
Get full filepath to executable, or raise if not found.
- classmethod is_available()#
Determine if the shell is available to instantiate.
- Returns:
True if the shell can be created.
- Return type:
- classmethod file_extension()#
Get the file extension associated with the shell.
- Returns:
Shell file extension.
- Return type:
- classmethod startup_capabilities(rcfile=False, norc=False, stdin=False, command=False)#
Given a set of options related to shell startup, return the actual options that will be applied. @returns 4-tuple representing applied value of each option.
- __init__()#
- get_output(style=<OutputStyle.file: ('Code as it would appear in a script file.', )>)#
Returns any implementation specific data.
- Parameters:
style (OutputStyle) – Style affecting output format.
- Returns:
Depends on implementation, but usually a code string.
- new_shell()#
Returns A new, reset shell of the same type.
- classmethod find_executable(name, check_syspaths=False)#
Find an executable.
- spawn_shell(context_file, tmpdir, rcfile=None, norc=False, stdin=False, command=None, env=None, quiet=False, pre_command=None, add_rez=True, package_commands_sourced_first=None, **Popen_args)#
Spawn a possibly interactive subshell. :param context: _file File that must be sourced in the new shell, this
configures the Rez environment.
- Parameters:
tmpdir – Tempfiles, if needed, should be created within this path.
rcfile – Custom startup script.
norc – Don’t run startup scripts. Overrides rcfile.
stdin – If True, read commands from stdin in a non-interactive shell. If a different non-False value, such as subprocess.PIPE, the same occurs, but stdin is also passed to the resulting subprocess.Popen object.
command – If not None, execute this command in a non-interactive shell. If an empty string, don’t run a command, but don’t open an interactive shell either.
env – Environ dict to execute the shell within; uses the current environment if None.
quiet – If True, don’t show the configuration summary, and suppress any stdout from startup scripts.
pre_command – Command to inject before the shell command itself. This is for internal use.
add_rez – If True, assume this shell is being used with rez, and do things such as set the prompt etc.
package_commands_sourced_first – If True, source the context file before sourcing startup scripts (such as .bashrc). If False, source the context file AFTER. If None, use the configured setting.
popen_args – args to pass to the shell process object constructor.
- Returns:
A subprocess.Popen object representing the shell process.
- classmethod convert_tokens(value)#
Converts any token like ${VAR} and $VAR to shell specific form. Uses the ENV_VAR_REGEX to correctly parse tokens.
- Parameters:
value – str to convert
- Returns:
str with shell specific variables
- classmethod get_key_token(key)#
Encodes the environment variable into the shell specific form. Shells might implement multiple forms, but the most common/safest should be returned here.
- Parameters:
key – Variable name to encode
- Returns:
str of encoded token form
- classmethod get_all_key_tokens(key)#
Encodes the environment variable into the shell specific forms. Shells might implement multiple forms, but the most common/safest should be always returned at index 0.
- Parameters:
key – Variable name to encode
- Returns:
list of str with encoded token forms
- classmethod join(command)#
Note: Default to unix sh/bash- friendly behaviour.
- Parameters:
command – A sequence of program arguments to be joined into a single string that can be executed in the current shell.
- Returns:
A string object representing the command.
- class rez.shells.UnixShell#
A base class for common *nix shells, such as bash and tcsh.
- classmethod get_startup_sequence(rcfile, norc, stdin, command)#
Return a dict containing: - ‘stdin’: resulting stdin setting. - ‘command’: resulting command setting. - ‘do_rcfile’: True if a file should be sourced directly. - ‘envvar’: Env-var that points at a file to source at startup. Can be None. - ‘files’: Existing files that will be sourced (non-user-expanded), in source
order. This may also incorporate rcfile, and file pointed at via envvar. Can be empty.
- ‘bind_files’: Files to inject Rez binding into, even if that file doesn’t
already exist.
‘source_bind_files’: Whether to source bind files, if they exist.
- spawn_shell(context_file, tmpdir, rcfile=None, norc=False, stdin=False, command=None, env=None, quiet=False, pre_command=None, add_rez=True, package_commands_sourced_first=None, **Popen_args)#
Spawn a possibly interactive subshell. :param context: _file File that must be sourced in the new shell, this
configures the Rez environment.
- Parameters:
tmpdir – Tempfiles, if needed, should be created within this path.
rcfile – Custom startup script.
norc – Don’t run startup scripts. Overrides rcfile.
stdin – If True, read commands from stdin in a non-interactive shell. If a different non-False value, such as subprocess.PIPE, the same occurs, but stdin is also passed to the resulting subprocess.Popen object.
command – If not None, execute this command in a non-interactive shell. If an empty string, don’t run a command, but don’t open an interactive shell either.
env – Environ dict to execute the shell within; uses the current environment if None.
quiet – If True, don’t show the configuration summary, and suppress any stdout from startup scripts.
pre_command – Command to inject before the shell command itself. This is for internal use.
add_rez – If True, assume this shell is being used with rez, and do things such as set the prompt etc.
package_commands_sourced_first – If True, source the context file before sourcing startup scripts (such as .bashrc). If False, source the context file AFTER. If None, use the configured setting.
popen_args – args to pass to the shell process object constructor.
- Returns:
A subprocess.Popen object representing the shell process.
- classmethod get_all_key_tokens(key)#
Encodes the environment variable into the shell specific forms. Shells might implement multiple forms, but the most common/safest should be always returned at index 0.
- Parameters:
key – Variable name to encode
- Returns:
list of str with encoded token forms