Download emk: .zip .tar.gz View On GitHub

Utils Module

This module provides various utility methods. It does not have any configurable properties.

Classes

utils.cd Context Manager

This is a simple context manager for changing to a directory, and always returning to the original directory.

Usage:

with utils.cd("some/path"):
    # do stuff; in here the working directory will be set to some/path
# the working directory will always be returned to its original state.

Methods

utils.flatten(args)

Convert a string, a list of strings, or a list of lists of … of strings into a single list of strings. Any iterable counts as a list (but a real list is returned). Returns a flattened version of the input, which is always a list containing only strings.

Arguments:

utils.unique_list(orig)

Create a new list from the input list, with duplicate items removed. Order is preserved. The list items must be hashable. Returns a copy of the original list with duplicate items removed.

Arguments:

utils.rm_list(thelist, item)

Remove an item from a list, if it is present. It is not an error if the item is not in the list.

Arguments:

utils.mkdirs(path)

Create all nonexistent directories in a path. It is not an error if the path already exists and is a directory. If the path already exists and is not a directory, an OSError will be raised.

Arguments:

utils.rm(path, print_msg=False)

Delete a file or directory tree. It is not an error if the file or directory does not exist.

Arguments:

utils.symlink(source, link_name)

Create a symbolic link pointing to source named link_name. If symbolic links are not supported, then the source will be copied to link_name.

Arguments:

* source: The file or directory that the link is to point to. * link_name: The name of the link to create.

utils.call(*args, **kwargs)

Call a subprocess. Returns a tuple (stdout, stderr, exit code).

The subprocess will run until it exits (normally or otherwise). The stdout, stderr, and exit code of the subprocess are returned if the process exits normally. Otherwise, the default behaviour is to raise a build error, but this can be suppressed using the “noexit” keyword argument.

Arguments:

Keyword arguments:

utils.mark_virtual_rule(produces, requires)

Define an emk rule to mark the productions as virtual.

Arguments:

utils.copy_rule(source, dest)

Define an emk rule to copy a file. The file will only be copied if the source differs from the destination (or the destination does not yet exist). Directories containing the destination that do not exist will be created.

Arguments:

utils.clean_rule(*patterns)

Add patterns for files to remove when “emk clean” is called. This attaches a rule to the “clean” target that will remove files matching the given patterns. Returns the product path generated by the new rule (in case you want to depend on it or whatever).

Arguments:

utils.get_environment_from_batch_command(env_cmd, initial)

Execute a Windows batch or command file and retrieve the resulting environment.

Arguments: