Utilities and platform-specific fixes
The portability fixes try to provide a consistent behavior of the Waf API through Python versions 2.5 to 3.X and across different platforms (win32, linux, etc)
Arbitrary null value for hashes. Modify this value according to the hash function in use
Constant representing the permissions for regular files (0644 raises a syntax error on python 3)
Constant representing the permissions for executable files (0755 raises a syntax error on python 3)
List of characters to use when displaying the throbber (progress bar)
Index of the current throbber character (progress bar)
Bases: dict
Ordered dictionary that provides iteration from the most recently inserted keys first
Bases: object
Used by waflib.Utils.lru_cache
Bases: object
A simple least-recently used cache with lazy allocation
Maximum amount of elements in the cache
Mapping key-value
Whether this system is a Windows series
Reads an entire file into a string. See also waflib.Node.Node.readf():
def build(ctx):
from waflib import Utils
txt = Utils.readf(self.path.find_node('wscript').abspath())
txt = ctx.path.find_node('wscript').read()
Parameters: |
|
---|---|
Return type: | string |
Returns: | Content of the file |
Writes an entire file from a string. See also waflib.Node.Node.writef():
def build(ctx):
from waflib import Utils
txt = Utils.writef(self.path.make_node('i_like_kittens').abspath(), 'some data')
self.path.make_node('i_like_kittens').write('some data')
Parameters: |
|
---|
Computes a hash value for a file by using md5. Use the md5_tstamp extension to get faster build hashes if necessary.
Parameters: | fname (string) – path to the file to hash |
---|---|
Returns: | hash of the file contents |
Return type: | string or bytes |
Reads an entire file into a string. See also waflib.Node.Node.readf():
def build(ctx):
from waflib import Utils
txt = Utils.readf(self.path.find_node('wscript').abspath())
txt = ctx.path.find_node('wscript').read()
Parameters: |
|
---|---|
Return type: | string |
Returns: | Content of the file |
Writes an entire file from a string. See also waflib.Node.Node.writef():
def build(ctx):
from waflib import Utils
txt = Utils.writef(self.path.make_node('i_like_kittens').abspath(), 'some data')
self.path.make_node('i_like_kittens').write('some data')
Parameters: |
|
---|
Computes a hash value for a file by using md5. Use the md5_tstamp extension to get faster build hashes if necessary.
Parameters: | fname (string) – path to the file to hash |
---|---|
Returns: | hash of the file contents |
Return type: | string or bytes |
Return the hexadecimal representation of a string
Parameters: | s (string) – string to convert |
---|
Lists the contents of a folder in a portable manner. On Win32, returns the list of drive letters: [‘C:’, ‘X:’, ‘Z:’] when an empty string is given.
Parameters: | s (string) – a string, which can be empty on Windows |
---|
Converts a string, tuple or version number into an integer. The number is supposed to have at most 4 digits:
from waflib.Utils import num2ver
num2ver('1.3.2') == num2ver((1,3,2)) == num2ver((1,3,2,0))
Parameters: | ver (string or tuple of numbers) – a version number |
---|
Converts a string argument to a list by splitting it by spaces. Returns the object if not a string:
from waflib.Utils import to_list
lst = to_list('a b c d')
Parameters: | val – list of string or space-separated string |
---|---|
Return type: | list |
Returns: | Argument converted to list |
Splits a path by / or ; do not confuse this function with with os.path.split
Parameters: | path (string) – path to split |
---|---|
Returns: | list of string |
Splits a path by / or ; do not confuse this function with with os.path.split
Parameters: | path (string) – path to split |
---|---|
Returns: | list of string |
Ensures that a directory exists (similar to mkdir -p).
Parameters: | path (string) – Path to directory |
---|---|
Raises : | waflib.Errors.WafError if the folder cannot be added. |
Ensures that a program exists
Parameters: |
|
---|---|
Returns: | path of the program or None |
Raises : | waflib.Errors.WafError if the folder cannot be added. |
Sets default attributes on a class instance
Parameters: |
|
---|
Converts a string into an identifier suitable for C defines.
Parameters: | s (string) – String to convert |
---|---|
Return type: | string |
Returns: | Identifier suitable for C defines |
Regexp used for shell_escape below
Escapes a command: [‘ls’, ‘-l’, ‘arg space’] -> ls -l ‘arg space’
Hashes lists of ordered data.
Using hash(tup) for tuples would be much more efficient, but Python now enforces hash randomization
Parameters: | lst (list of strings) – list to hash |
---|---|
Returns: | hash of the list |
Hash functions
Parameters: | fun (function) – function to hash |
---|---|
Returns: | hash of the function |
Return type: | string or bytes |
Hashes objects recursively
Parameters: | ins (string or list or tuple or function) – input object |
---|---|
Return type: | string or bytes |
Replaces ${VAR} with the value of VAR taken from a dict or a config set:
from waflib import Utils
s = Utils.subst_vars('${PREFIX}/bin', env)
Parameters: |
|
---|
Returns the binary format based on the unversioned platform name, and defaults to elf if nothing is found.
Parameters: | key (string) – platform name |
---|---|
Returns: | string representing the binary format |
Returns the unversioned platform name. Some Python platform names contain versions, that depend on the build environment, e.g. linux2, freebsd6, etc. This returns the name without the version number. Exceptions are os2 and win32, which are returned verbatim.
Return type: | string |
---|---|
Returns: | Unversioned platform name |
Bases: object
Simple object for timing the execution of commands. Its string representation is the duration:
from waflib.Utils import Timer
timer = Timer()
a_few_operations()
s = str(timer)
Reads property files, used by msvc.py
Parameters: | path (string) – file to read |
---|
Decorator: let a function cache its results, use like this:
@run_once
def foo(k):
return 345*2343
Note
in practice this can cause memory leaks, prefer a waflib.Utils.lru_cache
Parameters: | fun (function) – function to execute |
---|---|
Returns: | the return value of the function executed |
Returns the value of a registry key for an executable
Guess the default /usr/lib extension for 64-bit applications
Returns: | ‘64’ or ‘’ |
---|---|
Return type: | string |
List of processes started to execute sub-process commands
Delegates process execution to a pre-forked process instance.
Change the owner/group of a path, raises an OSError if the ownership change fails.
Parameters: |
|
---|
Executes a subprocess command by using subprocess.Popen
Executes a subprocess by using a pre-forked process when possible or falling back to subprocess.Popen. See waflib.Utils.run_prefork_process() and waflib.Utils.run_regular_process()
Returns a process object that can execute commands as sub-processes
Return type: | subprocess.Popen |
---|
Allocates an amount of processes to the default pool so its size is at least n. It is useful to call this function early so that the pre-forked processes use as little memory as possible.
Parameters: |
|
---|