Command helpers - libvcs._internal.run
#
Misc. legacy helpers subprocess
and finding VCS binaries.
libvcs._internal.run.run
will be deprecated by
libvcs._internal.subprocess
.
Note
This is an internal API not covered by versioning policy.
- libvcs._internal.run.console_to_str(s)[source]#
From pypa/pip project, pip.backwardwardcompat. License MIT.
- class libvcs._internal.run.CmdLoggingAdapter(bin_name, keyword, *args, **kwargs)[source]#
Bases:
LoggerAdapter
Adapter for additional command-related data to
logging
.Extends
logging.LoggerAdapter
βs functionality.Mixes in additional context via
logging.LoggerAdapter.process()
forlogging.Formatter
when emitting log entries.- Parameters:
Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.
You can effectively pass keyword arguments as shown in the following example:
adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=βv2β))
- bin_name#
bin_name
- keyword#
directory basename, name of repository, hint, etc.
- class libvcs._internal.run.ProgressCallbackProtocol(*args, **kwargs)[source]#
Bases:
Protocol
Callback to report subprocess communication.
- _abc_impl = <_abc._abc_data object>#
- _is_protocol = True#
- libvcs._internal.run.run(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=(), *, text=None, encoding=None, errors=None, user=None, group=None, extra_groups=None, umask=-1, log_in_real_time=False, check_returncode=True, callback=None)[source]#
Run a command.
Run βargsβ in a shell and return the combined contents of stdout and stderr (Blocking). Throws an exception if the command exits non-zero.
Keyword arguments are passthrough to
subprocess.Popen
.- Parameters:
args (list or str, or single str, if shell=True) β the command to run
shell (bool) β boolean indicating whether we are using advanced shell features. Use only when absolutely necessary, since this allows a lot more freedom which could be exploited by malicious code. See the warning here: http://docs.python.org/library/subprocess.html#popen-constructor
cwd (str) β dir command is run from. Defaults to
path
.log_in_real_time (bool) β boolean indicating whether to read stdout from the subprocess in real time instead of when the process finishes.
check_returncode (bool) β Indicate whether a libvcs.exc.CommandError should be raised if return code is different from 0.
callback (ProgressCallbackProtocol) β
callback to return output as a command executes, accepts a function signature of (output, timestamp). Example usage:
def progress_cb(output, timestamp): sys.stdout.write(output) sys.stdout.flush() run(['git', 'pull'], callback=progress_cb)
changes (Upcoming) β
---------------- β
3.10 (When minimum python >=) β
`pipesize β
bufsize (int) β
executable (str | bytes | PathLike[str] | PathLike[bytes] | None) β
close_fds (bool) β
env (Mapping[bytes, str | bytes | PathLike[str] | PathLike[bytes]] | Mapping[str, str | bytes | PathLike[str] | PathLike[bytes]] | None) β
universal_newlines (bool) β
startupinfo (Any | None) β
creationflags (int) β
restore_signals (bool) β
start_new_session (bool) β
pass_fds (Any) β
text (bool | None) β
encoding (str | None) β
errors (str | None) β
umask (int) β
- Return type: