1.20. startup

This module provides generic functions for the early initialization of the project’s environment. This is primarily used for the management of external dependencies.

Note

This is a “Clean Room” module and is suitable for use during initialization.

1.20.1. Functions

argp_add_client(parser)[source]

Add client-specific arguments to a new argparse.ArgumentParser instance.

Parameters:parser (argparse.ArgumentParser) – The parser to add arguments to.
argp_add_default_args(parser, default_root='')[source]

Add standard arguments to a new argparse.ArgumentParser instance. Used to add the utilities argparse options to the wrapper for display.

Parameters:
argp_add_server(parser)[source]

Add server-specific arguments to a new argparse.ArgumentParser instance.

Parameters:parser (argparse.ArgumentParser) – The parser to add arguments to.
pipenv_entry(parser, entry_point)[source]

Run through startup logic for a Pipenv script (see Pipenv: Custom Script Shortcuts for more information). This sets up a basic stream logging configuration, establishes the Pipenv environment and finally calls the actual entry point using os.execve().

Note

Due to the use of os.execve(), this function does not return.

Note

Due to the use of os.execve() and os.EX_* exit codes, this function is not available on Windows.

Parameters:
  • parser – The argument parser to use. Arguments are added to it and extracted before passing the remainder to the entry point.
  • entry_point (str) – The name of the entry point using Pipenv.
run_process(process_args, cwd=None, tee=False, encoding='utf-8')[source]

Run a subprocess, wait for it to complete and return a ProcessResults object. This function differs from start_process() in the type it returns and the fact that it always waits for the subprocess to finish before returning.

Changed in version 1.15.0: Added the tee parameter.

Parameters:
  • process_args (tuple) – The arguments for the processes including the binary.
  • cwd (bool) – An optional current working directory to use for the process.
  • tee (bool) – Whether or not to display the console output while the process is running.
  • encoding (str) – The encoding to use for strings.
Returns:

The results of the process including the status code and any text printed to stdout or stderr.

Return type:

ProcessResults

start_process(process_args, wait=True, cwd=None)[source]

Start a subprocess and optionally wait for it to finish. If not wait, a handle to the subprocess is returned instead of True when it exits successfully. This function differs from run_process() in that it optionally waits for the subprocess to finish, and can return a handle to it.

Parameters:
  • process_args (tuple) – The arguments for the processes including the binary.
  • wait (bool) – Whether or not to wait for the subprocess to finish before returning.
  • cwd (str) – The optional current working directory.
Returns:

If wait is set to True, then a boolean indication success is returned, else a handle to the subprocess is returened.

which(program)[source]

Examine the PATH environment variable to determine the location for the specified program. If it can not be found None is returned. This is fundamentally similar to the Unix utility of the same name.

Parameters:program (str) – The name of the program to search for.
Returns:The absolute path to the program if found.
Return type:str

1.20.2. Classes

class ProcessResults(stdout, stderr, status)[source]

A named tuple for holding the results of an executed external process.

stdout[source]

A string containing the data the process wrote to stdout.

stderr[source]

A string containing the data the process wrote to stderr.

status[source]

An integer representing the process’s exit code.