This package contains a number of utilities that are used inside of openmdao. It does not depend on any other openmdao package.
Importing this file will fix problems we’ve found in distutils.
Current fixes are:
Update the library_dir_option function in MSVCCompiler to add quotes around /LIBPATH entries.
A utility to extract Traits information from the code and get it into the Sphinx documentation.
If run as main, dumpdistmeta.py will print out either a pretty-printed dict full of the metadata found in the specified distribution or just the value of a single piece of metadata if metadata-item is specified on the command line. The distribution can be in the form of an installed egg, a zipped egg, or a gzipped tar file containing a distutils distribution.
usage: dumpdistmeta.py distribution [metadata-item]
Example output:
$ dumpdistmeta.py pyparsing-1.5.1-py2.5.egg
{'SOURCES': ['README',
'pyparsing.py',
'setup.py',
'pyparsing.egg-info/PKG-INFO',
'pyparsing.egg-info/SOURCES.txt',
'pyparsing.egg-info/dependency_links.txt',
'pyparsing.egg-info/top_level.txt'],
'author': 'Paul McGuire',
'author-email': 'ptmcg@users.sourceforge.net',
'classifier': 'Programming Language :: Python',
'dependency_links': [],
'description': 'UNKNOWN',
'download-url': 'http://sourceforge.net/project/showfiles.php?group_id=97203',
'entry_points': {},
'home-page': 'http://pyparsing.wikispaces.com/',
'license': 'MIT License',
'metadata-version': '1.0',
'name': 'pyparsing',
'platform': None,
'py_version': '2.5',
'summary': 'Python parsing module',
'top_level': ['pyparsing'],
'version': '1.5.1',
'zip-safe': False}
Example output:
$ dumpdistmeta.py pyparsing-1.5.1-py2.5.egg license
MIT License
Retrieve metadata from within a distribution. Returns a dict.
Egg loading utilities.
Load object(s) from an input stream (or filename). If instream is a string that is not an existing filename or absolute path, then it is searched for using pkg_resources. Returns the root object.
Extract files in egg to a subdirectory matching the saved object name. Optionally installs distributions the egg depends on and then loads object graph state by invoking the given entry point. Returns the root object.
Bases: object
Provides a convenient API for calling an observer of egg operations. observer will be called with:
Observe add of file. If observer returns False, raises RuntimeError.
Observe analysis of file. If observer returns False, raises RuntimeError.
Observe copy of file. If observer returns False, raises RuntimeError.
Observe extraction of file. If observer returns False, raises RuntimeError.
Egg save utilities.
Note that pickle can’t save references to functions that aren’t defined at the top level of a module, and there doesn’t appear to be a viable workaround. Normally pickle won’t handle instance methods either, but there is code in place to work around that.
When saving to an egg, the module named __main__ changes when reloading. This requires finding the real module name and munging references to __main__. References to old-style class types can’t be restored correctly.
Also note that YAML format doesn’t handle more than one layer of back-pointers, so it’s only suitable for very flat object networks.
Save the state of root and its children to an output stream (or filename). If outstream is a string, then it is used as a filename. The format can be supplied in case something other than cPickle is needed. For the pickle formats, a proto of -1 means use the highest protocol.
Save state and other files to an egg. Analyzes the objects saved for distribution dependencies. Modules not found in any distribution are recorded in an ‘egg-info/openmdao_orphans.txt’ file. Also creates and saves loader scripts for each entry point.
Returns (egg_filename, required_distributions, orphan_modules).
Write Python egg files, either directly or via setuptools. Supports what’s needed for saving and loading components/simulations.
Returns name for egg file as generated by setuptools.
Write egg in the manner of setuptools, with some differences:
Returns the egg’s filename.
Misc. file utility routines
Return a list of files (using a generator) that match the given glob pattern. Walks an entire directory structure.
Creates missing directories for the given path and returns a normalized absolute version of the path.
from holger@trillke.net 2002/03/18
Utilities for file wrapping.
Note: This is a work in progress.
Bases: object
Utility to locate and read data from a file.
Marks the location of a landmark, which lets you describe data by relative position. Note that a forward search begins at the old anchor location. If you want to restart the search for the anchor at the file beginning, then call reset_anchor() before mark_anchor.
anchor: The text you want to search for.
occurence: find nth instance of text; default is 1 (first). Use -1 to find last occurence. Reverse searches always start at the end of the file no matter the state of any previous anchor.
Lets you change the delimiter that is used to identify field boundaries.
Grabs an array of variables relative to the current anchor.
Searches for a key relative to the current anchor and then grabs a field from that line.
field – Which field to transfer. Field 0 is the key.
occurrence – find nth instance of text; default is 1 (first value field). Use -1 to find last occurence. Position 0 is the key field, so it should not be used as a value for occurrence.
rowoffset – Optional row offset from the occurrence of key. This can also be negative.
You can do the same thing with a call to mark_anchor and transfer_var. This function just combines them for convenience.
Returns a whole line, relative to current anchor.
row - number of lines offset from anchor line (0 is anchor line). This can be negative.
Grabs a single variable relative to the current anchor.
— If the delimiter is ” ” —
row - number of lines offset from anchor line (0 is anchor line). This can be negative.
field - which word in line to retrieve.
fieldend - IGNORED
— If the delimiter is “columns” —
row - number of lines offset from anchor line (0 is anchor line). This can be negative.
field - character position to start
fieldend - position of last character to return
Bases: object
Utility to generate an input file from a template. Substitution of values is supported. Data is located with a simple API.
Replace the contents of a row with the newline character.
row - row number to clear, relative to current anchor.
Marks the location of a landmark, which lets you describe data by relative position.
anchor: text to search for
occurence: find nth instance of text; default is 1 (first). Use -1 to find last occurence.
Lets you change the delimiter that is used to identify field boundaries.
Changes the values of a 2D array in the template relative to the current anchor. This method is specialized for 2D arrays, where each row of the array is on its own line.
value - array of values to insert.
row_start - Starting row for inserting the array. This is relative to the anchor, and can be negative.
row_end - Final row for the array, relative to the anchor.
field_start - starting field in the given row_start as denoted by delimiter(s).
field_end - the final field the array uses in row_end. We need this to figure out if the template is too small or large
sep - Optional. Separator to use if we go beyond the template
Changes the values of an array in the template relative to the current anchor. This should generally be used for one-dimensional or free form arrays.
value - array of values to insert.
row_start - starting row for inserting the array. This is relative to the anchor, and can be negative.
field_start - starting field in the given row_start as denoted by delimiter(s).
field_end - the final field the array uses in row_end. We need this to figure out if the template is too small or large
row_end - Optional. Use if the array wraps to cover additional lines.
sep - Optional. Separator to use if we go beyond the template
Transfer a file from one place to another.
If src_server or dst_server is None, then the os module is used for the source or destination respectively. Otherwise the respective object must support open(), stat(), and chmod().
mode specifies any open() mode settings in addition to ‘r’ or ‘w’.
After the copy has completed, permission bits from stat() are set via chmod().
Downloads a distribution from the given package index(s) based on the given requirement string(s). Downloaded distributions are placed in the specified destination or the current directory if no destination is specified. If a distribution cannot be found in the given index(s), the Python Package Index will be searched as a last resort unless search_pypi is False. This does NOT install the distribution.
Requirements may be supplied as strings or as Requirement objects.
This is just a wrapper for the logging module. Messages can be routed to the console via enable_console(). If the file ‘logger.cfg’ exists, it can be used to configure logging. See the Python documentation for logging.config for details. The example below is equivalent to calling enable_console():
[loggers]
keys=root
[handlers]
keys=consoleHandler
[formatters]
keys=consoleFormatter
[logger_root]
level=DEBUG
handlers=consoleHandler
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=consoleFormatter
args=(sys.stderr,)
[formatter_consoleFormatter]
format=%(levelname)s %(name)s: %(message)s
Configure logging to receive log messages at the console.
Bases: object
Pickle-able logger. Mostly a pass-through to a real logger.
Logging message level.
Math related utility functions used by OpenMDAO.
Calculates a random latin hypercube set of n points in k dimensions within [0,1]^k hypercube.
Returns an n by k numpy array.
A script to package into a distribution a single module containing OpenMDAO plugin classes. The script imports the module in order to determine its contents, so all dependencies must be on sys.path.
Bases: exceptions.RuntimeError
Utility to simplify the packaging of a single module containing OpenMDAO plugin classes into a source distribution.
Use mod2dist -h to see all of the options.
The only required options are the desired version of the distribution and the module to use to generate the distribution. For example:
mod2dist -v 1.0 simple_adder.py
Utilities for reading and writing Fortran namelists.
Bases: object
Data object that stores the value of a single card for a namelist.
Bases: object
Utility to ease the task of constructing a formatted output file.
Add a new group to the namelist. Any variables added after this are added to this new group.
Parses the variable definition section of a Phoenix Integration ModelCenter component wrapper.
Generates a dummy component given a Phoenix Integration Modelcenter script wrapper. The first section of this wrapper is parsed, and the appropriate variables and containers are placed in the new OpenMDAO component.
infile - ModelCenter scriptwrapper.
outfile - File containing new OpenMDAO component skeleton.
compname - Name for new component.
Utility functions related to plotting data
Retrieve the values of specified variables from a sqlite DB containing Case data.
Returns a dict containing a list of values for each entry, keyed on variable name.
Based on command line options, display an XY plot using data from a sqlite Case DB.
Display an XY plot using Case data from a sqlite DB.
Return the set of the names of the variables found in the specified case DB file.
Bases: subprocess.CalledProcessError
subprocess.CalledProcessError plus errormsg attribute.
Bases: subprocess.Popen
A slight modification to subprocess.Popen. Sets the shell argument True, updates a copy of os.environ with env, and opens files for any stream which is a basestring.
Run command with arguments. Returns (return_code, error_msg).
Run command with arguments. If non-zero return_code, raises CalledProcessError.
Bases: object
Wrapper of standard Python file object. Supports reading/writing int and float arrays in various formats.
Returns next float. If full_record, then read surrounding recordmarks. Only meaningful if unformatted.
Returns floats as a numpy array of shape. If full_record, then read surrounding recordmarks. Only meaningful if unformatted.
Returns next integer. If full_record, then read surrounding recordmarks. Only meaningful if unformatted.
Returns integers as a numpy array of shape. If full_record, then read surrounding recordmarks. Only meaningful if unformatted.
Writes numpy array data as text. If order is ‘C’, the data is written in row-major order. If order is ‘Fortran’, the data is written in column-major order. If linecount is > zero, then at most linecount values are written per line.
Writes a float. If full_record, then write surrounding recordmarks. Only meaningful if unformatted.
Writes numpy float array data. If order is ‘C’, the data is written in row-major order. If order is ‘Fortran’, the data is written in column-major order. If linecount is > zero, then at most linecount values are written per line. If full_record, then write surrounding recordmarks. Only meaningful if unformatted.
Writes an integer. If full_record, then write surrounding recordmarks. Only meaningful if unformatted.
Writes numpy integer array data. If order is ‘C’, the data is written in row-major order. If order is ‘Fortran’, the data is written in column-major order. If linecount is > zero, then at most linecount values are written per line. If full_record, then write surrounding recordmarks. Only meaningful if unformatted.
Determine that code raises err_type with err_msg.
Determine that code raises exception with msg. globals and locals are arguments for eval(). If use_exec, then evaluate code with exec rather than eval(). This is necessary for testing statements that are not expressions.
A script (openmdao_docs) points to this. It just pops up a browser to view the openmdao Sphinx docs. If the docs are not already built, it builds them before viewing; but if the docs already exist, it’s not smart enough to rebuild them if they’ve changed since the last build.
If this is run from a non-developer install, i.e., there is no local copy of the docs, it just looks for the docs on the openmdao.org website.
Bases: object
Pool of worker threads; grows as necessary.