diff --git a/bob/bio/base/test/test_extractor.py b/bob/bio/base/test/test_extractor.py index f283eac9157e9c3449dac894cac399f8e9495218..488997354c75bd57033dd3beb8677b1f7f31b59c 100644 --- a/bob/bio/base/test/test_extractor.py +++ b/bob/bio/base/test/test_extractor.py @@ -28,7 +28,8 @@ def test_linearize(): assert (extracted == extracted2).all() finally: - os.remove(filename) + if os.path.exists(filename): + os.remove(filename) # extract with dtype extractor = bob.bio.base.extractor.Linearize(dtype=numpy.complex128) diff --git a/bob/bio/base/test/test_utils.py b/bob/bio/base/test/test_utils.py index b1067308350dbfb86e33c09500a29cb9bae246de..72ebfbbd641f584740cdd3ab320fa979d82a6138 100644 --- a/bob/bio/base/test/test_utils.py +++ b/bob/bio/base/test/test_utils.py @@ -21,6 +21,11 @@ def test_resources(): cls = bob.bio.base.load_resource("bob.bio.base.algorithm.PCA(10, distance_function=scipy.spatial.distance.euclidean)", "algorithm", imports=['bob.bio.base', 'scipy.spatial']) assert isinstance (cls, bob.bio.base.algorithm.PCA) + # get list of extensions + extensions = bob.bio.base.extensions() + assert isinstance(extensions, list) + assert 'bob.bio.base' in extensions + def test_grid(): # try to load the grid configurations diff --git a/bob/bio/base/tools/command_line.py b/bob/bio/base/tools/command_line.py index 0a49bd75b6550ac5ba63f00b8947b944e350fe58..68c83797205e277c1bf3405dca572f4b6e0e21a7 100644 --- a/bob/bio/base/tools/command_line.py +++ b/bob/bio/base/tools/command_line.py @@ -48,6 +48,7 @@ def command_line_parser(description=__doc__, exclude_resources_from=[]): is_idiap = os.path.isdir("/idiap") temp = "/idiap/temp/%s/database-name/sub-directory" % os.environ["USER"] if is_idiap else "temp" results = "/idiap/user/%s/database-name/sub-directory" % os.environ["USER"] if is_idiap else "results" + database_replacement = "/idiap/home/%s/.bob_bio_databases.txt" % os.environ["USER"] if is_idiap else "/home/%s/.bob_bio_databases.txt" % os.environ["USER"] dir_group = parser.add_argument_group('\nDirectories that can be changed according to your requirements') dir_group.add_argument('-T', '--temp-directory', metavar = 'DIR', @@ -66,6 +67,8 @@ def command_line_parser(description=__doc__, exclude_resources_from=[]): help = 'The database file in which the submitted jobs will be written; relative to the current directory (only valid with the --grid option).') file_group.add_argument('--experiment-info-file', metavar = 'FILE', default = 'Experiment.info', help = 'The file where the configuration of all parts of the experiments are written; relative to te --result-directory.') + file_group.add_argument('--database-directories-file', metavar = 'FILE', default = database_replacement, + help = 'An optional file, where database directories are stored (to avoid changing the database configurations)') sub_dir_group = parser.add_argument_group('\nSubdirectories of certain parts of the tool chain. You can specify directories in case you want to reuse parts of the experiments (e.g. extracted features) in other experiments. Please note that these directories are relative to the --temp-directory, but you can also specify absolute paths') sub_dir_group.add_argument('--preprocessed-directory', metavar = 'DIR', default = 'preprocessed', @@ -183,40 +186,30 @@ def initialize(parsers, command_line_parameters = None, skips = []): model_sub_dir = protocol if args.database.models_depend_on_protocol else enroller_sub_dir - # IDIAP-Private directories, which should be automatically replaced - if is_idiap: - images = { - 'ARFACE' : "/idiap/resource/database/AR_Face/images", - 'ATNT' : "/idiap/group/biometric/databases/orl", - 'BANCA' : "/idiap/group/biometric/databases/banca/english/images/images", - 'CAS-PEAL' : "/idiap/resource/database/CAS-PEAL", - 'FRGC' : "/idiap/resource/database/frgc/FRGC-2.0-dist", - 'MBGC-V1' : "/idiap/resource/database/MBGC-V1", - 'LFW' : "/idiap/resource/database/lfw/all_images_aligned_with_funneling", - 'MOBIO_IMAGE' : "/idiap/resource/database/mobio/IMAGES_PNG", - 'MULTI-PIE_IMAGE' : "/idiap/resource/database/Multi-Pie/data", - 'SC_FACE' : "/idiap/group/biometric/databases/scface/images", - 'XM2VTS' : "/idiap/resource/database/xm2vtsdb/images", - } - - annotations = { - 'MOBIO_ANNOTATION' : "/idiap/resource/database/mobio/IMAGE_ANNOTATIONS", - 'MULTI-PIE_ANNOTATION' : "/idiap/group/biometric/annotations/multipie", - } + # Database directories, which should be automatically replaced + if os.path.exists(args.database_directories_file): + # + replacements = {} + with open(args.database_directories_file) as f: + for line in f: + if line.strip() and not line.startswith("#"): + splits = line.split("=") + assert len(splits) == 2 + replacements[splits[0].strip()] = splits[1].strip() try: - for d in images: - if args.database.original_directory == "[YOUR_%s_DIRECTORY]" % d: - args.database.original_directory = images[d] - args.database.database.original_directory = images[d] + for d in replacements: + if args.database.original_directory == d: + args.database.original_directory = replacements[d] + args.database.database.original_directory = replacements[d] except AttributeError: pass try: - for d in annotations: - if args.database.annotation_directory == "[YOUR_%s_DIRECTORY]" % d: - args.database.annotation_directory = annotations[d] - args.database.database.annotation_directory = annotations[d] + for d in replacements: + if args.database.annotation_directory == d: + args.database.annotation_directory = replacements[d] + args.database.database.annotation_directory = replacements[d] except AttributeError: pass @@ -261,6 +254,8 @@ def command_line(cmdline): def write_info(args, command_line_parameters, executable): + if command_line_parameters is None: + command_line_parameters = sys.argv[1:] # write configuration try: bob.io.base.create_directories_safe(os.path.dirname(args.info_file)) diff --git a/bob/bio/base/utils/resources.py b/bob/bio/base/utils/resources.py index a2a5d8dd1dcbf30b046a8d1521a8e3e07b1307ec..641645997765ceef171c645cea542b011b3ae565 100644 --- a/bob/bio/base/utils/resources.py +++ b/bob/bio/base/utils/resources.py @@ -59,7 +59,7 @@ def read_config_file(filename, keyword = None): def _get_entry_points(keyword, strip = []): """Returns the list of entry points for registered resources with the given keyword.""" - return [entry_point for entry_point in pkg_resources.iter_entry_points('bob.bio.' + keyword) if entry_point.name not in strip] + return [entry_point for entry_point in pkg_resources.iter_entry_points('bob.bio.' + keyword) if not entry_point.name.startswith(tuple(strip))] def load_resource(resource, keyword, imports = ['bob.bio.base'], preferred_distribution = None): @@ -154,6 +154,12 @@ def read_file_resource(resource, keyword): raise ImportError("Under the desired name '%s', there are multiple entry points defined: %s" %(resource, [entry_point.module_name for entry_point in entry_points])) +def extensions(keywords=valid_keywords): + """Returns a list of packages that define extensions using the given keywords, which default to all keywords.""" + entry_points = [entry_point for keyword in keywords for entry_point in _get_entry_points(keyword)] + return sorted(list(set(entry_point.dist.project_name for entry_point in entry_points))) + + def resource_keys(keyword, exclude_packages=[], strip=['dummy']): """Reads and returns all resources that are registered with the given keyword. Entry points from the given ``exclude_packages`` are ignored."""