Commit d9796ef7 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'bob-extension-config-file' into 'master'

Integrate the new bob.extension loading config mechanism

See merge request !119
parents 75ebdf5b 39a5713b
Pipeline #14592 passed with stages
in 16 minutes and 20 seconds
......@@ -241,7 +241,6 @@ def take_from_config_or_command_line(args, config, keyword, default, required=Tr
preferred_package=args.preferred_package))
elif config is not None and hasattr(config, keyword):
val = getattr(config, keyword)
if isinstance(val, str) and is_resource:
val = utils.load_resource(val, keyword, imports=args.imports, package_prefix=args.package_prefix,
......
......@@ -8,7 +8,7 @@ from __future__ import print_function
import imp
import os
import pkg_resources
import bob.extension.config
import sys
if sys.version_info[0] == 2:
from string import letters as ascii_letters
......@@ -45,45 +45,7 @@ def _collect_config(paths):
'''
def _attach_resources(src, dst):
for k in dir(src):
setattr(dst, k, getattr(src, k))
import random
name = "".join(random.sample(ascii_letters, 10))
retval = imp.new_module(name)
for path in paths:
# execute the module code on the context of previously import modules
for ep in pkg_resources.iter_entry_points('bob.bio.config'):
if ep.name == path:
tmp = ep.load() # loads the pointed module
_attach_resources(tmp, retval)
break
else:
# if you get to this point, then it is not a resource, maybe it is a module?
try:
tmp = __import__(path, retval.__dict__, retval.__dict__, ['*'])
_attach_resources(tmp, retval)
continue
except ImportError:
# module does not exist, ignore it
pass
except Exception as e:
raise IOError("The configuration module '%s' could not be loaded: %s" % (path, e))
# if you get to this point, then its not a resource nor a loadable module, is
# it on the file system?
if not os.path.exists(path):
raise IOError("The configuration file, resource or module '%s' could not be found, loaded or imported" % path)
name = "".join(random.sample(ascii_letters, 10))
tmp = imp.load_source(name, path)
_attach_resources(tmp, retval)
return retval
return bob.extension.config.load(paths, entry_point_group="bob.bio.config")
def read_config_file(filenames, keyword = None):
......
......@@ -94,6 +94,18 @@ Running the experiment is then as simple as:
.. note::
To be able to run exactly the command line from above, it requires to have :ref:`bob.bio.face <bob.bio.face>` installed.
.. note::
Chain loading is possible through configuration files, i.e., variables of each
config is available during evaluation of the preceding config file.
This allows us to spread our experiment setup in several configuration files and have a call similar to this::
$ verify.py config_1.py config_2.py config_n.py
For more information see *Chain Loading* in :ref:`bob.extension.config`.
Before running an experiment, it is recommended to add set the variable ``dry_run = True``, so that it will only print, which steps would be executed, without actually executing them, and make sure that everything works as expected.
The final result of the experiment will be one (or more) score file(s).
......@@ -102,7 +114,7 @@ By default, you can find them in a sub-directory the ``result`` directory, but y
.. note::
At Idiap_, the default result directory differs, see ``verify.py --help`` for your directory.
.. _bob.bio.base.command_line:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment