Coverage for src/bob/bio/base/script/resources.py: 0%
42 statements
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-14 21:41 +0100
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-14 21:41 +0100
1"""Prints a detailed list of all resources that are registered, including the modules, where they have been registered."""
3import os
4import warnings
6import click
8import bob.bio.base
11@click.command()
12@click.option(
13 "--types",
14 "-t",
15 type=click.Choice(
16 ["database", "annotator", "pipeline", "config", "dask"],
17 case_sensitive=False,
18 ),
19 multiple=True,
20 default=["database", "annotator", "pipeline", "config", "dask"],
21 help="Select the resource types that should be listed.",
22)
23@click.option(
24 "--details",
25 "-d",
26 is_flag=True,
27 default=False,
28 help="Prints the complete configuration for all resources",
29)
30@click.option(
31 "--packages",
32 "-p",
33 multiple=True,
34 help="If given, shows only resources defined in the given package(s)",
35)
36@click.option(
37 "--no-strip-dummy",
38 "-s",
39 is_flag=True,
40 default=False,
41 help="If given, the dummy elements (usually used for testing purposes only) are **not** removed from the list.",
42)
43def resources(types, details, packages, no_strip_dummy):
44 """Lists the currently registered configurations for this environment."""
46 # TODO This needs to be updated!
48 kwargs = {"verbose": details, "packages": packages}
49 if no_strip_dummy:
50 kwargs["strip"] = []
52 if "database" in types:
53 print(
54 "\nList of registered databases (can be used after the --database "
55 "option):"
56 )
57 print(bob.bio.base.list_resources("database", **kwargs))
59 if "annotator" in types:
60 print(
61 "\nList of registered annotators (can be used after the "
62 "--annotator option):"
63 )
64 print(bob.bio.base.list_resources("annotator", **kwargs))
66 if "pipeline" in types:
67 print(
68 "\nList of registered pipelines (can be used after the --pipeline "
69 "option):"
70 )
71 print(bob.bio.base.list_resources("pipeline", **kwargs))
73 if "config" in types:
74 print(
75 "\nList of registered configs. Configs may contain multiple "
76 "resources and they also allow chain loading (see bob.extension "
77 "docs on chain loading). Configs are used as arguments to commands "
78 "such as simple):"
79 )
80 print(bob.bio.base.list_resources("config", **kwargs))
82 if "dask" in types:
83 print("\nList of registered dask clients")
84 print(
85 bob.bio.base.list_resources(
86 "client", package_prefix="dask.", **kwargs
87 )
88 )
90 print()
93def databases(command_line_parameters=None):
94 warnings.warn(
95 "The databases command is deprecated. You should not be using it!"
96 )
97 import argparse
99 database_replacement = "%s/.bob_bio_databases.txt" % os.environ["HOME"]
101 parser = argparse.ArgumentParser(
102 description="Prints a list of directories for registered databases",
103 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
104 )
105 parser.add_argument(
106 "-D",
107 "--database-directories-file",
108 metavar="FILE",
109 default=database_replacement,
110 help="The file, where database directories are stored (to avoid changing the database configurations)",
111 )
113 args = parser.parse_args(command_line_parameters)
115 # get registered databases
116 databases = bob.bio.base.utils.resources.database_directories(
117 replacements=args.database_directories_file
118 )
120 # print directories for all databases
121 for d in sorted(databases):
122 print("\n%s:" % d)
124 print("Original data: %s" % databases[d][0])
125 if len(databases[d]) > 1:
126 print("Annotations: %s" % databases[d][1])