Bases: object
Domain validator for modules.
Modules can be specified as module objects, by module name,
or by the path to the module’s file. If specified by path, the
path string has the same path expansion features supported by
the Path
class.
Note that modules imported by file path may not be recognized as
part of a package, and as such they should not use relative package
importing (such as from . import foo
).
- Parameters:
basePath (None, str, ConfigValue) – The base path that will be prepended to any non-absolute path
values provided. If None, defaults to Path.BasePath
.
expandPath (bool) – If True, then the value will be expanded and normalized. If
False, the string representation of the value will be used
unchanged. If None, expandPath will defer to the (negated)
value of Path.SuppressPathExpansion
.
Examples
The following code shows the three ways you can specify a module: by file
name, by module name, or by module object. Regardless of how the module is
specified, what is stored in the configuration is a module object.
from pyomo.common.config import (
ConfigDict, ConfigValue, Module
)
config = ConfigDict()
config.declare('my_module', ConfigValue(
domain=Module(),
))
# Set using file path
config.my_module = '../../pyomo/common/tests/config_plugin.py'
# Set using python module name, as a string
config.my_module = 'os.path'
# Set using an imported module object
import os.path
config.my_module = os.path
-
__init__(basePath=None, expandPath=None)[source]
Methods
Member Documentation