rez.shells
Pluggable API for creating subshells using different programs, such as bash.
- class rez.shells.Shell[source]
Bases:
rez.rex.ActionInterpreterClass 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 file_extension()[source]
Get the file extension associated with the shell.
- Returns
Shell file extension.
- Return type
- 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 is_available()[source]
Determine if the shell is available to instantiate.
- Returns
True if the shell can be created.
- Return type
- 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.
- 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.
- class rez.shells.UnixShell[source]
Bases:
rez.shells.ShellA base class for common *nix shells, such as bash and tcsh.
- command_arg = '-c'
- 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
- last_command_status = '$?'
- norc_arg = None
- rcfile_arg = None
- 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'
- 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