implement 'globals' option
This commit is contained in:
@@ -110,6 +110,11 @@ def main():
|
||||
from . import formatter
|
||||
formatter._SEPARATOR = separator
|
||||
|
||||
# eval globals
|
||||
path = config.get((), "globals")
|
||||
if path:
|
||||
util.GLOBALS = util.import_file(path).__dict__
|
||||
|
||||
# loglevels
|
||||
output.configure_logging(args.loglevel)
|
||||
if args.loglevel >= logging.ERROR:
|
||||
|
||||
@@ -619,9 +619,28 @@ GLOBALS = {
|
||||
}
|
||||
|
||||
|
||||
def compile_expression(expr, name="<expr>", globals=GLOBALS):
|
||||
def compile_expression(expr, name="<expr>", globals=None):
|
||||
code_object = compile(expr, name, "eval")
|
||||
return functools.partial(eval, code_object, globals)
|
||||
return functools.partial(eval, code_object, globals or GLOBALS)
|
||||
|
||||
|
||||
def import_file(path):
|
||||
"""Import a Python module from a filesystem path"""
|
||||
path, name = os.path.split(path)
|
||||
|
||||
name, sep, ext = name.rpartition(".")
|
||||
if not sep:
|
||||
name = ext
|
||||
|
||||
if path:
|
||||
path = expand_path(path)
|
||||
sys.path.insert(0, path)
|
||||
try:
|
||||
return __import__(name)
|
||||
finally:
|
||||
del sys.path[0]
|
||||
else:
|
||||
return __import__(name)
|
||||
|
||||
|
||||
def build_duration_func(duration, min=0.0):
|
||||
|
||||
Reference in New Issue
Block a user