rez.shells

Pluggable API for creating subshells using different programs, such as bash.

class rez.shells.Shell[source]

Bases: rez.rex.ActionInterpreter

Class representing a shell, such as bash or tcsh.

classmethod convert_tokens(value)[source]

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

property executable
classmethod executable_filepath()[source]

Get full filepath to executable, or raise if not found.

classmethod executable_name()[source]

Name of executable to create shell instance.

classmethod file_extension()[source]

Get the file extension associated with the shell.

Returns

Shell file extension.

Return type

str

classmethod find_executable(name, check_syspaths=False)[source]

Find an executable.

Parameters
  • name (str) – Program name.

  • check_syspaths (bool) – If True, check the standard system paths as well, if program was not found on current $PATH.

Returns

Full filepath of executable.

Return type

str

classmethod get_all_key_tokens(key)[source]

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 get_key_token(key)[source]

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

get_output(style=<OutputStyle.file: ('Code as it would appear in a script file.', )>)[source]

Returns any implementation specific data.

Parameters

style (OutputStyle) – Style affecting output format.

Returns

Depends on implementation, but usually a code string.

classmethod get_syspaths()[source]
classmethod is_available()[source]

Determine if the shell is available to instantiate.

Returns

True if the shell can be created.

Return type

bool

classmethod join(command)[source]

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.

classmethod line_terminator()[source]
Returns

default line terminator

Return type

str

classmethod name()[source]

Plugin name.

new_shell()[source]

Returns A new, reset shell of the same type.

schema_dict = {'prompt': <class 'str'>}
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)[source]

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 startup_capabilities(rcfile=False, norc=False, stdin=False, command=False)[source]

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.

class rez.shells.UnixShell[source]

Bases: rez.shells.Shell

A base class for common *nix shells, such as bash and tcsh.

command(value)[source]
command_arg = '-c'
comment(value)[source]
error(value)[source]
classmethod get_all_key_tokens(key)[source]

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 get_startup_sequence(rcfile, norc, stdin, command)[source]

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.

histfile = None
histvar = None
info(value)[source]
last_command_status = '$?'
classmethod line_terminator()[source]
Returns

default line terminator

Return type

str

norc_arg = None
rcfile_arg = None
resetenv(key, value, friends=None)[source]
shebang()[source]
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)[source]

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.

stdin_arg = '-s'
classmethod supports_command()[source]
classmethod supports_norc()[source]
classmethod supports_stdin()[source]
syspaths = None
rez.shells.create_shell(shell=None, **kwargs)[source]

Returns a Shell of the given or current type.

Returns

Instance of given shell.

Return type

Shell

rez.shells.get_shell_class(shell=None)[source]

Get the plugin class associated with the given or current shell.

Returns

Plugin class for shell.

Return type

class

rez.shells.get_shell_types()[source]

Returns the available shell types: bash, tcsh etc.

Returns: List of str: Shells.