This module contains various helpers for the other modules.
Return a string that identifies the current platform. This is used mainly to distinguish platform-specific build directories and platform-specific built distributions. Typically includes the OS name and version and the architecture (as supplied by ‘os.uname()’), although the exact information included depends on the OS; e.g. for IRIX the architecture isn’t particularly important (IRIX only runs on SGI hardware), but for Linux the kernel version isn’t particularly important.
Examples of returned values:
For non-POSIX platforms, currently just returns sys.platform.
For Mac OS X systems the OS version reflects the minimal version on which binaries will run (that is, the value of MACOSX_DEPLOYMENT_TARGET during the build of Python), not the OS version of the current system.
For universal binary builds on Mac OS X the architecture value reflects the univeral binary status instead of the architecture of the current processor. For 32-bit universal binaries the architecture is fat, for 64-bit universal binaries the architecture is fat64, and for 4-way universal binaries the architecture is universal. Starting from Python 2.7 and Python 3.2 the architecture fat3 is used for a 3-way universal build (ppc, i386, x86_64) and intel is used for a univeral build with the i386 and x86_64 architectures
Examples of returned values on Mac OS X:
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.
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.
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:
Search the path for a given executable name.
Perform some action that affects the outside world (for instance, 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.
Return true if source exists and is more recently modified than target, or if source exists and target doesn’t. Return false if both exist and target is the same age or newer than source. Raise PackagingFileError if source does not exist.
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.
Byte-compile a collection of Python source files to either .pyc or .pyo files in a __pycache__ subdirectory (see PEP 3147), or to the same directory when using the distutils2 backport on Python versions older than 3.2.
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:
This function is independent from the running Python’s -O or -B options; it is fully controlled by the parameters passed in.
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.