module documentation

distutils.util Miscellaneous utility functions -- anything that doesn't fit into one of the other *util.py modules.

Function byte_compile Byte-compile a collection of Python source files to .pyc files in a __pycache__ subdirectory. 'py_files' is a list of files to compile; any files that don't end in ".py" are silently skipped. 'optimize' must be one of the following: 0 - don't optimize 1 - normal optimization (like "python -O") 2 - extra optimization (like "python -OO") If 'force' is true, all files are recompiled regardless of timestamps.
Function change_root Return 'pathname' with 'new_root' prepended. If 'pathname' is relative, this is equivalent to "os.path.join(new_root,pathname)". Otherwise, it requires making 'pathname' relative and then joining the two, which is tricky on DOS/Windows and Mac OS.
Function check_environ Ensure that 'os.environ' has all the environment variables we guarantee that users can use in config files, command-line options, etc. Currently this includes: HOME - user's home directory (Unix only) PLAT - description of the current platform, including hardware and OS (see 'get_platform()')...
Function convert_path Return 'pathname' as a name that will work on the native filesystem, i.e. split it on '/' and put it back together again using the current directory separator. Needed because filenames in the setup script are always supplied in Unix style, and have to be converted to the local convention before we can actually use them in the filesystem...
Function execute Perform some action that affects the outside world (eg. by writing to the filesystem). Such actions are special because they are disabled by the 'dry_run' flag. This method takes care of all that bureaucracy for you; all you have to do is supply the function to call and an argument tuple for it (to embody the "external action" being performed), and an optional message to print.
Function get_host_platform Return a string that identifies the current platform. Use this function to distinguish platform-specific build directories and platform-specific built distributions.
Function get_macosx_target_ver Return the version of macOS for which we are building.
Function get_macosx_target_ver_from_syscfg Get the version of macOS latched in the Python interpreter configuration. Returns the version as a string or None if can't obtain one. Cached.
Function get_platform Undocumented
Function grok_environment_error Undocumented
Function rfc822_escape Return a version of the string escaped for inclusion in an RFC-822 header, by ensuring there are 8 spaces space after each newline.
Function split_quoted Split a string up according to Unix shell-like rules for quotes and backslashes. In short: words are delimited by spaces, as long as those spaces are not escaped by a backslash, or inside a quoted string...
Function split_version Convert a dot-separated string into a list of numbers for comparisons
Function strtobool Convert a string representation of truth to true (1) or false (0).
Function subst_vars Perform variable substitution on 'string'. Variables are indicated by format-style braces ("{var}"). Variable is substituted by the value found in the 'local_vars' dictionary or in 'os.environ' if it's not in 'local_vars'...
Constant MACOSX_VERSION_VAR Undocumented
Function _clear_cached_macosx_ver For testing only. Do not call.
Function _init_regex Undocumented
Function _subst_compat Replace shell/Perl-style variable substitution with format-style. For compatibility.
Variable _dquote_re Undocumented
Variable _squote_re Undocumented
Variable _syscfg_macosx_ver Undocumented
Variable _wordchars_re Undocumented
def byte_compile(py_files, optimize=0, force=0, prefix=None, base_dir=None, verbose=1, dry_run=0, direct=None): (source)

Byte-compile a collection of Python source files to .pyc files in a __pycache__ subdirectory. 'py_files' is a list of files to compile; any files that don't end in ".py" are silently skipped. 'optimize' must be one of the following: 0 - don't optimize 1 - normal optimization (like "python -O") 2 - extra optimization (like "python -OO") If 'force' is true, all files are recompiled regardless of timestamps. The source filename encoded in each bytecode file defaults to the filenames listed in 'py_files'; you can modify these with 'prefix' and 'basedir'. 'prefix' is a string that will be stripped off of each source filename, and 'base_dir' is a directory name that will be prepended (after 'prefix' is stripped). You can supply either or both (or neither) of 'prefix' and 'base_dir', as you wish. If 'dry_run' is true, doesn't actually do anything that would affect the filesystem. Byte-compilation is either done directly in this interpreter process with the standard py_compile module, or indirectly by writing a temporary script and executing it. Normally, you should let 'byte_compile()' figure out to use direct compilation or not (see the source for details). The 'direct' flag is used by the script generated in indirect mode; unless you know what you're doing, leave it set to None.

def change_root(new_root, pathname): (source)

Return 'pathname' with 'new_root' prepended. If 'pathname' is relative, this is equivalent to "os.path.join(new_root,pathname)". Otherwise, it requires making 'pathname' relative and then joining the two, which is tricky on DOS/Windows and Mac OS.

@functools.lru_cache()
def check_environ(): (source)

Ensure that 'os.environ' has all the environment variables we guarantee that users can use in config files, command-line options, etc. Currently this includes: HOME - user's home directory (Unix only) PLAT - description of the current platform, including hardware and OS (see 'get_platform()')

def convert_path(pathname): (source)

Return 'pathname' as a name that will work on the native filesystem, i.e. split it on '/' and put it back together again using the current directory separator. Needed because filenames in the setup script are always supplied in Unix style, and have to be converted to the local convention before we can actually use them in the filesystem. Raises ValueError on non-Unix-ish systems if 'pathname' either starts or ends with a slash.

def execute(func, args, msg=None, verbose=0, dry_run=0): (source)

Perform some action that affects the outside world (eg. by writing to the filesystem). Such actions are special because they are disabled by the 'dry_run' flag. This method takes care of all that bureaucracy for you; all you have to do is supply the function to call and an argument tuple for it (to embody the "external action" being performed), and an optional message to print.

def get_host_platform(): (source)

Return a string that identifies the current platform. Use this function to distinguish platform-specific build directories and platform-specific built distributions.

def get_macosx_target_ver(): (source)

Return the version of macOS for which we are building. The target version defaults to the version in sysconfig latched at time the Python interpreter was built, unless overridden by an environment variable. If neither source has a value, then None is returned

def get_macosx_target_ver_from_syscfg(): (source)

Get the version of macOS latched in the Python interpreter configuration. Returns the version as a string or None if can't obtain one. Cached.

def get_platform(): (source)

Undocumented

def grok_environment_error(exc, prefix='error: '): (source)

Undocumented

def rfc822_escape(header): (source)

Return a version of the string escaped for inclusion in an RFC-822 header, by ensuring there are 8 spaces space after each newline.

def split_quoted(s): (source)

Split a string up according to Unix shell-like rules for quotes and backslashes. In short: words are delimited by spaces, as long as those spaces are not escaped by a backslash, or inside a quoted string. Single and double quotes are equivalent, and the quote characters can be backslash-escaped. The backslash is stripped from any two-character escape sequence, leaving only the escaped character. The quote characters are stripped from any quoted string. Returns a list of words.

def split_version(s): (source)

Convert a dot-separated string into a list of numbers for comparisons

def strtobool(val): (source)

Convert a string representation of truth to true (1) or false (0). True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else.

def subst_vars(s, local_vars): (source)

Perform variable substitution on 'string'. Variables are indicated by format-style braces ("{var}"). Variable is substituted by the value found in the 'local_vars' dictionary or in 'os.environ' if it's not in 'local_vars'. 'os.environ' is first checked/augmented to guarantee that it contains certain values: see 'check_environ()'. Raise ValueError for any variables not found in either 'local_vars' or 'os.environ'.

MACOSX_VERSION_VAR: str = (source)

Undocumented

Value
'MACOSX_DEPLOYMENT_TARGET'
def _clear_cached_macosx_ver(): (source)

For testing only. Do not call.

def _init_regex(): (source)

Undocumented

def _subst_compat(s): (source)

Replace shell/Perl-style variable substitution with format-style. For compatibility.

_dquote_re = (source)

Undocumented

_squote_re = (source)

Undocumented

_syscfg_macosx_ver = (source)

Undocumented

_wordchars_re = (source)

Undocumented