ci_utils.py - Utilities supporting continuous integration tests¶
Imports¶
These are listed in the order prescribed by PEP 8.
Standard library¶
OS detection¶
This follows the Python recommendations.
Copied from https://docs.python.org/3.5/library/platform.html#cross-platform.
Support code¶
xqt¶
Pronounced “execute”: provides a simple way to execute a system command.
Commands to run. For example, 'foo -param firstArg secondArg', 'bar |
grep alpha'
.
This is passed directly to subprocess.run
.
This is passed directly to subprocess.run
.
Optional keyword arguments to pass on to subprocess.run.
Although https://docs.python.org/3/library/subprocess.html#subprocess.Popen
states, “The only time you need to specify shell=True
on Windows is
when the command you wish to execute is built into the shell (e.g.
dir or copy). You do not need shell=True
to run a batch file
or console-based executable.”, use shell=True
to both allow shell
commands and to support simple redirection (such as blah > nul
,
instead of passing stdout=subprocess.DEVNULL
to check_call
).
Per http://stackoverflow.com/questions/15931526/why-subprocess-stdout-to-a-file-is-written-out-of-order,
the run
below will flush stdout and stderr, causing all
the subprocess output to appear first, followed by all the Python
output (such as the print statement above). So, flush the buffers to
avoid this.
Use bash instead of sh, so that source
and other bash syntax
works. See https://docs.python.org/3/library/subprocess.html#subprocess.Popen.
Return a list only if there were multiple commands to execute.
env¶
Transforms os.environ["ENV_VAR"]
to the more compact env.ENV_VAR
. Returns None
if the env var doesn’t exist.
pushd¶
A context manager for pushd.
The path to change to upon entering the context manager.
Common tools¶
chdir¶
mkdir¶
flush_print¶
Anything sent to print
won’t be printed until Python flushes its buffers,
which means what CI logs report may be reflect what’s actually being executed
– until the buffers are flushed.
Flush both buffers, just in case there’s something in stdout
.