file_utils.py

Utilities for working with files.

openmdao.utils.file_utils.files_iter(start_dir='.', dir_includes=None, dir_excludes=(), file_includes=None, file_excludes=(), package_only=False)[source]

Iterate over files (recursively) starting in start_dir.

NOTE: all _includes and *_excludes are applied to *local directory and file names.

Parameters
start_dirstr

Starting directory.

dir_includesiter of str or None

Glob patterns for directory inclusion. Be careful here because dir names are local, so, for example, if includes=(‘foo’,), then directory ‘foo’ would be included, but any subdirectories of ‘foo’ that were not also named ‘foo’ would not.

dir_excludesiter of str

Glob patterns for directory exclusion.

file_includesiter of str or None

Glob patterns for file inclusion.

file_excludesiter of str

Glob patterns for file exclusion.

package_onlybool

If True, only yield files that are contained in a python package.

openmdao.utils.file_utils.get_module_path(fpath)[source]

Given a module filename, return its full Python module path.

This includes enclosing packages and is based on existence of __init__.py files.

Parameters
fpathstr

Pathname of file.

Returns
str or None

Full module path of the given file. Returns None if the file is not part of a package.

openmdao.utils.file_utils.package_iter(start_dir='.', dir_includes=None, dir_excludes=(), file_includes=None, file_excludes=())[source]

Iterate over python files in packages (recursively) starting in start_dir.

NOTE: all _includes and *_excludes are applied to *local directory and file names.

Parameters
start_dirstr

Starting directory.

dir_includesiter of str or None

Glob patterns for directory inclusion. Be careful here because dir names are local, so, for example, if includes=(‘foo’,), then directory ‘foo’ would be included, but any subdirectories of ‘foo’ that were not also named ‘foo’ would not.

dir_excludesiter of str

Glob patterns for directory exclusion.

file_includesiter of str or None

Glob patterns for file inclusion.

file_excludesiter of str

Glob patterns for file exclusion.