SubprocessCommand - libvcs._internal.subprocess¶

Invocable subprocess wrapper.

Defer running a subprocess, such as by handing to an executor.

Note

This is an internal API not covered by versioning policy.

Examples

  • SubprocessCommand: Wraps subprocess.Popen and subprocess.run() in a dataclass().

    Before:

    >>> import subprocess
    >>> subprocess.run(
    ...    ['echo', 'hi'],
    ...    capture_output=True, universal_newlines=True
    ... ).stdout
    'hi\n'
    

    With this:

    >>> cmd = SubprocessCommand(['echo', 'hi'])
    >>> cmd.args
    ['echo', 'hi']
    >>> cmd.run(capture_output=True, universal_newlines=True).stdout
    'hi\n'
    

    Tweak params before invocation:

    >>> cmd = SubprocessCommand(['echo', 'hi'])
    >>> cmd.args[1] = 'hello'
    >>> cmd.args
    ['echo', 'hello']
    >>> cmd.run(capture_output=True, universal_newlines=True).stdout
    'hello\n'
    
exception libvcs._internal.subprocess.SubprocessCheckOutputError
¶
exception[source]

Bases: Exception

libvcs._internal.subprocess._CMD: TypeAlias = str | bytes | os.PathLike[str] | os.PathLike[bytes] | collections.abc.Sequence[str | bytes | os.PathLike[str] | os.PathLike[bytes]]
¶
data

Command

class libvcs._internal.subprocess.SubprocessCommand
¶

Bases: SkipDefaultFieldsReprMixin

Wraps a subprocess request. Inspect, mutate, control before invocation.

Examples

>>> cmd = SubprocessCommand("ls")
>>> cmd.args
'ls'

With shell=True:

>>> cmd = SubprocessCommand("ls -l", shell=True)
>>> cmd.shell
True
>>> cmd.args
'ls -l'
>>> cmd.check_call()
0