ramble.util package
Subpackages
Submodules
ramble.util.class_attributes module
- ramble.util.class_attributes.convert_class_attributes(obj)[source]
Convert class attributes defined from directives to instance attributes Class attributes that are valid for conversion are stored in the _directive_names attribute.
- Parameters:
obj (Object) – Input object instance to convert attributes in
ramble.util.colors module
ramble.util.command_runner module
- class ramble.util.command_runner.CommandRunner(name=None, command=None, shell='bash', dry_run=False, path=None)[source]
Bases:
objectRunner for executing external commands
This class provides a generic wrapper on external commands, to provide a unified way to handle dry-run execution of external commands.
Can be inherited to construct custom command runners.
- execute(executable, args: List[str], return_output: bool = False)[source]
Wrapper around execution of a command
Handles execution of a command when the execution path is dependent on whether dry run is enabled or disabled.
- exception ramble.util.command_runner.NoPathRunnerError[source]
Bases:
RunnerErrorRaised when a runner is used that does not have a path set
- exception ramble.util.command_runner.RunnerError[source]
Bases:
ExceptionRaised when a problem occurs with a spack environment
- exception ramble.util.command_runner.ValidationFailedError[source]
Bases:
RunnerErrorRaised when a package manager requirement was not met
ramble.util.conversions module
ramble.util.directives module
- ramble.util.directives.define_directive_methods(obj_inst)[source]
Create class methods that execute directives
Wrap each directive, and inject it into this class instance as a class method.
This allows:
self.<directive_name>(<directive_args>) to be called. As in:
self.archive_pattern(’*.log’)
Which can be called within def __init__(self, file_path) instead of having to call archive_pattern(‘*.log’) at the class definition level.
This function requires the object instance to have internal attributes: - ‘_directive_classes’ - Dictionary mapping a directive to the class the
directive is defined for
‘_directive_functions’ - Dictionary mapping a directive to the decorated function that defines the directive
‘_language_classes’ - A list of classes that language features should be “imported” from
Both ‘_directive_classes’ and ‘_directive_functions’ are defined for all classes that use the DirectiveMeta meta-class.
The ‘_language_classes’ attribute is defined in ApplicationBase and ModifierBase.
ramble.util.editor module
Module for finding the user’s preferred text editor.
Defines one function, editor(), which invokes the editor defined by the user’s VISUAL environment variable if set. We fall back to the editor defined by the EDITOR environment variable if VISUAL is not set or the specified editor fails (e.g. no DISPLAY for a graphical editor). If neither variable is set, we fall back to one of several common editors, raising an EnvironmentError if we are unable to find one.
- ramble.util.editor.editor(*args, **kwargs)[source]
Invoke the user’s editor.
This will try to execute the following, in order:
$VISUAL <args> # the “visual” editor (per POSIX)
$EDITOR <args> # the regular editor (per POSIX)
some default editor (see
_default_editors) with <args>
If an environment variable isn’t defined, it is skipped. If it points to something that can’t be executed, we’ll print a warning. And if we can’t find anything that can be executed after searching the full list above, we’ll raise an error.
- Optional Arguments:
_exec_func (function): invoke this function instead of
os.execv()
ramble.util.env module
ramble.util.executable module
- class ramble.util.executable.CommandExecutable(name, template, use_mpi=False, mpi=False, variables=None, redirect='{log_file}', output_capture=OUTPUT_CAPTURE.ALL, run_in_background=False, **kwargs)[source]
Bases:
objectCommandExecutable class This class is used to represent internal executables in Ramble.
These executables are portions of an experiment definition. They are generally used to group one or more commands together into an executable name.
- exception ramble.util.executable.CommandExecutableError(message, long_message=None)[source]
Bases:
RambleErrorClass for errors when using command executable classes
- class ramble.util.executable.PrefixedExecutable(name)[source]
Bases:
ExecutableA version of spack.util.executable.Executable that allows command prefixes to be added
ramble.util.file_cache module
- exception ramble.util.file_cache.CacheError(message, long_message=None)[source]
Bases:
RambleError
- class ramble.util.file_cache.FileCache(root, timeout=120)[source]
Bases:
objectThis class manages cached data in the filesystem.
Cache files are fetched and stored by unique keys. Keys can be relative paths, so that there can be some hierarchy in the cache.
The FileCache handles locking cache files for reading and writing, so client code need not manage locks for cache entries.
- init_entry(key)[source]
Ensure we can access a cache file. Create a lock for it if needed.
Return whether the cache file exists yet or not.
- mtime(key)[source]
Return modification time of cache file, or 0 if it does not exist.
Time is in units returned by os.stat in the mtime field, which is platform-dependent.
ramble.util.file_util module
- ramble.util.file_util.create_symlink(base, link)[source]
Create symlink of a file to give a known and predictable path
ramble.util.foms module
- class ramble.util.foms.BetterDirection(*values)[source]
Bases:
Enum- HIGHER = 1
- INAPPLICABLE = 4
- INDETERMINATE = 3
- LOWER = 2
ramble.util.graph module
- class ramble.util.graph.GraphNode(key, attribute=None, obj_inst=None)[source]
Bases:
objectClass representing a node of a graph, where the node can have an attribute attached to it.
This allows nodes to be added into a graph, have the topological order of the graph returned, and be able to refer to the attribute of the original node easily.
- order_after(key)[source]
Adds information that this node should come after another node
- Parameters:
key (str) – Key of node that should come before this node.
ramble.util.hashing module
ramble.util.install_cache module
Provide data structures to assist with caching operations
ramble.util.lock module
Wrapper for llnl.util.lock allows locking to be enabled/disabled.
- class ramble.util.lock.Lock(*args, **kwargs)[source]
Bases:
LockLock that can be disabled.
This overrides the
_lock()and_unlock()methods fromllnl.util.lockso that all the lock API calls will succeed, but the actual locking mechanism can be disabled via_enable_locks.
- ramble.util.lock.check_lock_safety(path)[source]
Do some extra checks to ensure disabling locks is safe.
This will raise an error if
pathcan is group- or world-writable AND the current user can write to the directory (i.e., if this user AND others could write to the path).This is intended to run on the Ramble prefix, but can be run on any path for testing.
ramble.util.logger module
- class ramble.util.logger.Logger[source]
Bases:
objectLogger class
This class providers additional functionality on top of LLNL’s tty utility. Namely, this class provides a stack of log files, and allows errors to be printed to all log files instead of only one.
- active_log()[source]
Return the path for the active log
If any logs are in the log stack, return the filepath of the active log. Otherwise, return the string ‘stdout’
- active_stream()[source]
Return the stream for the active log
If any logs are in the log stack, return the stream object of the active log. Otherwise, return None to indicate the system is handling printing.
- add_log(path)[source]
Add a log to the current log stack
Opens (with ‘a+’ permissions) the file provided by the ‘path’ argument, and stores both the path, and the opened stream object in the current stack in the active position.
- Parameters:
path – File path for the new log file
- all_msg(*args, **kwargs)[source]
Print a message to all logs
Pass all args and kwargs to tty.info (which will concatenate and print). Perform this action for all logs and the default log (to screen).
- debug(*args, **kwargs)[source]
Print a debug message to the active log
Pass all args and kwargs to tty.debug (which will concatenate and print). Perform this action for the active log only.
- die(*args, **kwargs)[source]
Print an error message and terminate execution
Pass all args and kwargs to tty.error (which will concatenate and print). Perform this action all logs. After all logs are printed to, terminate execution (and error) using tty.die.
- error(*args, **kwargs)[source]
Print an error message
Pass all args and kwargs to tty.error (which will concatenate and print). Perform this action all logs, and the default stream (print to screen).
- info(*args, **kwargs)[source]
Print a message to the active log
Pass all args and kwargs to tty.info (which will concatenate and print). Perform this action for the active log only.
- msg(*args, **kwargs)[source]
Print a message to the active log
Pass all args and kwargs to tty.info (which will concatenate and print). Perform this action for the active log only.
- remove_log()[source]
Remove the active stack
Pop the active log from the log stack, and close the log stream.
ramble.util.matrices module
- ramble.util.matrices.extract_matrices(action, name, in_dict)[source]
Extract matrix definitions from a dictionary
- Parameters:
action – The action of an object definition where matrices are being extracted from
name – The name of the object
in_dict – The dictionary containing definitions
- Returns:
list of matrix definitions
ramble.util.naming module
- ramble.util.naming.mod_to_class(mod_name)[source]
Convert a name from module style to class name style. Ramble mostly follows PEP-8:
Module and package names use lowercase_with_underscores.
Class names use the CapWords convention.
Regular source code follows these conventions. Ramble is a bit more liberal with its Application names:
They can contain ‘-’ as well as ‘_’, but cannot start with ‘-‘.
They can start with numbers, e.g. “3proxy”.
This function converts from the module convention to the class convention by removing _ and - and converting surrounding lowercase text to CapWords. If mod_name starts with a number, the class name returned will be prepended with ‘_’ to make a valid Python identifier.
- ramble.util.naming.possible_ramble_module_names(python_mod_name)[source]
Given a Python module name, return a list of all possible ramble module names that could correspond to it.
- ramble.util.naming.ramble_module_to_python_module(mod_name)[source]
Given a Ramble module name, returns the name by which it can be imported in Python.
- ramble.util.naming.simplify_name(name)[source]
Simplify package name to only lowercase, digits, and dashes.
Simplifies a name which may include uppercase letters, periods, underscores, and pluses. In general, we want our package names to only contain lowercase letters, digits, and dashes.
- ramble.util.naming.valid_fully_qualified_module_name(mod_name)[source]
Return whether mod_name is a valid namespaced module name.
- ramble.util.naming.valid_module_name(mod_name)[source]
Return whether mod_name is valid for use in Ramble.
ramble.util.output_capture module
ramble.util.path module
Utilities for managing paths in ramble.
TODO: this is really part of ramble.config. Consolidate it.
- ramble.util.path.canonicalize_path(path)[source]
Same as substitute_path_variables, but also take absolute path.
- ramble.util.path.substitute_config_variables(path, local_replacements)[source]
Substitute placeholders into paths.
Ramble allows paths in configs to have some placeholders, as follows:
$ramble The ramble instance’s prefix
$user The current user’s username
$tempdir Default temporary directory returned by tempfile.gettempdir()
These are substituted case-insensitively into the path, and users can use either
$varor${var}syntax for the variables.
ramble.util.shell_utils module
Utils for handling shell specialization
- exception ramble.util.shell_utils.UnsupportedError(message, long_message=None)[source]
Bases:
RambleErrorError when certain shell features are not supported.
- ramble.util.shell_utils.cmd_sub_str(shell, cmd: str)[source]
Get the command substitution string of the given shell
ramble.util.spec_utils module
ramble.util.stats module
- class ramble.util.stats.StatsCoefficientOfVariation[source]
Bases:
StatsBase- min_count = 2
- name = 'cv'
ramble.util.version module
ramble.util.web module
- class ramble.util.web.LinkParser[source]
Bases:
HTMLParserThis parser just takes an HTML page and strips out the hrefs on the links. Good enough for a really simple spider.
- exception ramble.util.web.NoNetworkConnectionError(message, url)[source]
Bases:
SpackWebErrorRaised when an operation can’t get an internet connection.
- ramble.util.web.SPACK_USER_AGENT = 'Spackbot/0.18.0'
User-Agent used in Request objects
- exception ramble.util.web.SpackWebError(message, long_message=None)[source]
Bases:
SpackErrorSuperclass for Spack web spidering errors.
- ramble.util.web.find_versions_of_archive(archive_urls, list_url=None, list_depth=0, concurrency=32, reference_package=None)[source]
Scrape web pages for new versions of a tarball. This function prefers URLs in the following order: links found on the scraped page that match a url generated by the reference package, found and in the archive_urls list, found and derived from those in the archive_urls list, and if none are found for a version then the item in the archive_urls list is included for the version.
- Parameters:
archive_urls (str or list or tuple) – URL or sequence of URLs for different versions of a package. Typically these are just the tarballs from the package file itself. By default, this searches the parent directories of archives.
list_url (str or None) – URL for a listing of archives. Spack will scrape these pages for download links that look like the archive URL.
list_depth (int) – max depth to follow links on list_url pages. Defaults to 0.
concurrency (int) – maximum number of concurrent requests
reference_package (spack.package.Package or None) – a spack package used as a reference for url detection. Uses the url_for_version method on the package to produce reference urls which, if found, are preferred.
- ramble.util.web.get_header(headers, header_name)[source]
Looks up a dict of headers for the given header value.
Looks up a dict of headers, [headers], for a header value given by [header_name]. Returns headers[header_name] if header_name is in headers. Otherwise, the first fuzzy match is returned, if any.
This fuzzy matching is performed by discarding word separators and capitalization, so that for example, “Content-length”, “content_length”, “conTENtLength”, etc., all match. In the case of multiple fuzzy-matches, the returned value is the “first” such match given the underlying mapping’s ordering, or unspecified if no such ordering is defined.
If header_name is not in headers, and no such fuzzy match exists, then a KeyError is raised.
- ramble.util.web.push_to_url(local_file_path, remote_path, keep_original=True, extra_args=None)[source]
ramble.util.yaml_generation module
Module representing utility functions for managing YAML configuration files within application definition files
These functions are intended to help read, write, and manipulate YAML based configuration files that an experiment might use as input.
Workload variables that represent configuration files should be defined using a ‘.’ delimiter between YAML object names. As an example:
``` foo:
- bar:
baz: 1.0
Would translate to foo.bar.baz = 1.0 in Ramble syntax.
- ramble.util.yaml_generation.all_config_options(config_data: Dict)[source]
Extract all config options from config_data dictionary
- ramble.util.yaml_generation.apply_default_config_values(config_data, app_inst, default_config_string)[source]
Apply default config values (from config_data) to an experiment
Process all workloads variables (for the current workload in app_inst). Any variable who’s expanded value is equal to default_config_string will have its value overwritten to the value in the config_dict dictionary.
- ramble.util.yaml_generation.get_config_value(config_data: Dict, option_name: str)[source]
Get a config option based on dictionary attribute syntax
Given an option_name of the format: attr1.attr2.attr3 return its value from config_data.
- ramble.util.yaml_generation.read_config_file(conf_path: str)[source]
Read an existing YAML file and return its data as a dictionary
- ramble.util.yaml_generation.remove_config_value(config_data: Dict, option_name: str)[source]
Remove a config option based on dictionary attribute syntax
Given an option_name of the format: attr1.attr2.attr3 remote it from config_data. Also, remove any parent scopes that are empty.