Skip to content

Commit

Permalink
Implemented #25 by adding a '--packages' option to ./bin/resources.py
Browse files Browse the repository at this point in the history
  • Loading branch information
siebenkopf committed Jul 11, 2016
1 parent f19871c commit 9b8bac5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion bob/bio/base/script/resources.py
Expand Up @@ -15,12 +15,14 @@ def resources(command_line_parameters = None):

parser.add_argument("--details", '-d', action='store_true', help = "Prints the complete configuration for all resources")

parser.add_argument("--packages", '-p', nargs='+', help = "If given, shows only resources defined in the given package(s)")

parser.add_argument("--no-strip-dummy", '-s', action = 'store_true',
help = "If given, the dummy elements (usually used for testing purposes only) are **not** removed from the list.")

args = parser.parse_args(command_line_parameters)

kwargs = {'verbose' : args.details}
kwargs = {'verbose' : args.details, "packages" : args.packages}
if args.no_strip_dummy:
kwargs['strip'] = []

Expand Down
2 changes: 1 addition & 1 deletion bob/bio/base/test/test_scripts.py
Expand Up @@ -369,7 +369,7 @@ def test_resources():
# simply test that the collect_results script works
from bob.bio.base.script.resources import resources, databases
with utils.Quiet():
resources(['--types', 'database', 'preprocessor', 'extractor', 'algorithm', 'grid', '--details'])
resources(['--types', 'database', 'preprocessor', 'extractor', 'algorithm', 'grid', '--details', '--packages', 'bob.bio.base'])
databases([])


Expand Down
9 changes: 6 additions & 3 deletions bob/bio/base/utils/resources.py
Expand Up @@ -194,7 +194,7 @@ def resource_keys(keyword, exclude_packages=[], package_prefix='bob.bio.', strip
if entry_point.dist.project_name not in exclude_packages])


def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.', verbose=False):
def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.', verbose=False, packages=None):
"""Returns a string containing a detailed list of resources that are registered with the given keyword."""
if keyword not in valid_keywords:
raise ValueError("The given keyword '%s' is not valid. Please use one of %s!" % (str(keyword), str(valid_keywords)))
Expand All @@ -204,7 +204,10 @@ def list_resources(keyword, strip=['dummy'], package_prefix='bob.bio.', verbose=
retval = ""
length = max(len(entry_point.name) for entry_point in entry_points) if entry_points else 1

for entry_point in sorted(entry_points, key=lambda p: p.dist.project_name):
if packages is not None:
entry_points = [entry_point for entry_point in entry_points if entry_point.dist.project_name in packages]

for entry_point in sorted(entry_points, key=lambda p: (p.dist.project_name, p.name)):
if last_dist != str(entry_point.dist):
retval += "\n- %s @ %s: \n" % (str(entry_point.dist), str(entry_point.dist.location))
last_dist = str(entry_point.dist)
Expand All @@ -224,7 +227,7 @@ def database_directories(strip=['dummy'], replacements = None, package_prefix='b
entry_points = _get_entry_points('database', strip, package_prefix=package_prefix)

dirs = {}
for entry_point in sorted(entry_points, key=lambda entry_point: entry_point.name):
for entry_point in sorted(entry_points, key=lambda entry_point: entry_point.name):
try:
db = load_resource(entry_point.name, 'database')
db.replace_directories(replacements)
Expand Down

0 comments on commit 9b8bac5

Please sign in to comment.