xonsh.procs.specs¶
Subprocess specification and related utilities.
- class xonsh.procs.specs.DecoratorAlias[source]¶
Decorator alias base class.
- descr = 'DecoratorAlias base.'¶
- class xonsh.procs.specs.SpecAttrDecoratorAlias(set_attributes: dict, descr='')[source]¶
Decorator Alias for spec attributes.
- decorate_spec_pre_run(pipeline, spec, spec_num)¶
Modify spec before run.
- descr = 'DecoratorAlias base.'¶
- class xonsh.procs.specs.SubprocSpec(cmd, cls=<class 'subprocess.Popen'>, stdin=None, stdout=None, stderr=None, universal_newlines=False, close_fds=False, captured=False, env=None)[source]¶
A container for specifying how a subprocess command should be executed.
- Parameters:
- cmdlist of str
Command to be run.
- clsPopen-like
Class to run the subprocess with.
- stdinfile-like
Popen file descriptor or flag for stdin.
- stdoutfile-like
Popen file descriptor or flag for stdout.
- stderrfile-like
Popen file descriptor or flag for stderr.
- universal_newlinesbool
Whether or not to use universal newlines.
- close_fdsbool
Whether or not to close the file descriptors when the process exits.
- capturedbool or str, optional
The flag for if the subprocess is captured, may be one of: False for $[], ‘stdout’ for $(), ‘hiddenobject’ for ![], or ‘object’ for !().
- envdict
Replacement environment to run the subporcess in.
- Attributes:
- argslist of str
Arguments as originally supplied.
- aliaslist of str, callable, or None
The alias that was resolved for this command, if any.
- binary_locstr or None
Path to binary to execute.
- is_proxybool
Whether or not the subprocess is or should be run as a proxy.
- backgroundbool
Whether or not the subprocess should be started in the background.
- threadablebool
Whether or not the subprocess is able to be run in a background thread, rather than the main thread.
- pipeline_indexint or None
The index number of this sepc into the pipeline that is being setup.
- last_in_pipelinebool
Whether the subprocess is the last in the execution pipeline.
- captured_stdoutfile-like
Handle to captured stdin
- captured_stderrfile-like
Handle to captured stderr
- stacklist of FrameInfo namedtuples or None
The stack of the call-site of alias, if the alias requires it. None otherwise.
- classmethod build(cmd, *, cls=<class 'subprocess.Popen'>, **kwargs)[source]¶
Creates an instance of the subprocess command, with any modifications and adjustments based on the actual cmd that was received.
- add_decorator(mod: DecoratorAlias)[source]¶
Add spec modifier to the specification.
- close()[source]¶
Release any pipe wrappers and channels held by this spec.
Required when a spec is created via
cmds_to_specsbut never executed (noCommandPipeline._close_procis invoked). The wrappers fromPipeChannel.open_writer/open_readeruseclosefd=False, so leaving them for GC produces aResourceWarning: unclosed fileon Python 3.12+. Idempotent.
- kwnames = ('stdin', 'stdout', 'stderr', 'universal_newlines', 'close_fds')¶
- property stderr¶
- property stdin¶
- property stdout¶
- xonsh.procs.specs.cmds_to_specs(cmds, captured=False, envs=None, in_boolop=False)[source]¶
Converts a list of cmds to a list of SubprocSpec objects that are ready to be executed.
in_boolopis propagated from the parser; it is True when the whole pipeline is a direct operand of a&&/||chain. Each spec gets the flag stored on it so downstream code (e.g.CommandPipeline,_raise_subproc_error) can decide whether to short-circuit on returncode or raise.
- xonsh.procs.specs.get_script_subproc_command(fname, args)[source]¶
Given the name of a script outside the path, returns a list representing an appropriate subprocess command to execute the script or None if the argument is not readable or not a script. Raises PermissionError if the script is not executable.
- xonsh.procs.specs.is_app_execution_alias(fname)[source]¶
App execution aliases behave strangly on Windows and Python. Here we try to detect if a file is an app execution alias.
- xonsh.procs.specs.no_pg_xonsh_preexec_fn()[source]¶
Default subprocess preexec function for when there is no existing pipeline group.
- xonsh.procs.specs.parse_shebang_from_file(filepath)[source]¶
Returns shebang for a file or None. Doc: https://www.gnu.org/software/guile/manual/html_node/The-Meta-Switch.html
- xonsh.procs.specs.run_subproc(cmds, captured=False, envs=None, in_boolop=False)[source]¶
Runs a subprocess, in its many forms. This takes a list of ‘commands,’ which may be a list of command line arguments or a string, representing a special connecting character. For example:
$ ls | grep wakkais represented by the following cmds:
[['ls'], '|', ['grep', 'wakka']]Lastly, the captured argument affects only the last real command.
in_boolopis forwarded from the parser; True when this whole pipeline is a direct operand of a&&/||chain. Each spec receivesspec.in_boolopso downstream consumers can act on it (e.g. let a non-zero return short-circuit instead of raising).