1+ import logging
2+ from typing import List
3+
4+ import pkg_resources
15import yaml
26from click import command , option , Choice
37from jsonasobj2 import as_dict
48from linkml_runtime import SchemaView
9+
510from schemasheets .conf .configschema import ColumnSettings
611from schemasheets .schema_exporter import SchemaExporter
712from schemasheets .schemasheet_datamodel import TableConfig , ColumnConfig
8- import logging
9- import pkg_resources
13+ from typing import List , Dict
1014
1115# todo write tests
1216
@@ -75,29 +79,33 @@ def setup_logging(log_file=None, log_level=logging.INFO):
7579 )
7680
7781
78- def tabulate_unique_values (list_ ):
82+ def tabulate_unique_values (value_list ):
7983 """
8084 tabulate the number of appearances of each unique values in a list
8185
82- Args:
83- list_ (list): The list to tabulate.
84-
85- Returns:
86- dict: A dict mapping each unique value to the number of times it appears in the list.
86+ :param value_list: The list to tabulate, potentially with repeat occurrences of list items.
87+ :returns: A dict mapping each unique value to the number of times it appears in the list.
8788 """
8889
89- unique_values = set (list_ )
90+ unique_values = set (value_list )
9091 value_counts = {}
9192 for value in unique_values :
92- count = list_ .count (value )
93+ count = value_list .count (value )
9394 value_counts [value ] = count
9495
9596 sorted_value_counts = sorted (value_counts .items (), key = lambda x : x [1 ], reverse = True )
9697
9798 return sorted_value_counts
9899
99100
100- def discover_source_usage (source_view ):
101+ def discover_source_usage (source_view : SchemaView ) -> tuple [List [str ], List [str ]]:
102+ """
103+ Discover the meta slots and annotations used in the source code.
104+
105+ :param source_view: A SchemaView of the source schema.
106+ :returns: A tuple of the meta slots and annotations that were discovered as used in the source schema.
107+ """
108+
101109 discovered_meta_slots = []
102110 discovered_annotations = []
103111 source_classes = source_view .all_classes ()
@@ -125,9 +133,27 @@ def discover_source_usage(source_view):
125133 return discovered_meta_slots , discovered_annotations
126134
127135
128- def do_usage_report (style , meta_view , meta_type_names , meta_enum_names , discovered_annotations ,
129- discovered_source_slots , logger ):
130- logger .warning (style )
136+ def do_usage_report (
137+ style : str ,
138+ meta_view : SchemaView ,
139+ meta_type_names : List [str ],
140+ meta_enum_names : List [str ],
141+ discovered_annotations : List [str ],
142+ discovered_source_slots : List [str ],
143+ logger : logging .Logger ,
144+ ) -> tuple [TableConfig , Dict [str , Dict [str , str ]]]:
145+ """
146+ Perform a usage report on the metamodel.
147+
148+ :param style: The style of the usage report.
149+ :param meta_view: The metamodel to analyze.
150+ :param meta_type_names: The list of types discovered in the metamodel.
151+ :param meta_enum_names: The list of enums discovered in the metamodel.
152+ :param discovered_annotations: The list of annotations discovered in the source schema.
153+ :param discovered_source_slots: The list of metaslots used in the source 's SLotDefinitions and ClassDefinitions.
154+ :param logger: The logger to use.
155+ :returns: A tuple of the table config and the untemplateable metaslots.
156+ """
131157
132158 columns_dict = {}
133159
@@ -154,7 +180,11 @@ def do_usage_report(style, meta_view, meta_type_names, meta_enum_names, discover
154180 current_induced_slots = meta_view .class_induced_slots (current_root )
155181 for cis in current_induced_slots :
156182
157- temp_dict = {"range" : cis .range , "multivalued" : cis .multivalued , "type_range" : cis .range in meta_type_names }
183+ temp_dict = {
184+ "range" : cis .range ,
185+ "multivalued" : cis .multivalued ,
186+ "type_range" : cis .range in meta_type_names ,
187+ }
158188 if style == "exhaustive" or cis .name in discovered_source_slots :
159189 if cis .name not in slot_scan_results :
160190 slot_scan_results [cis .name ] = temp_dict
@@ -274,6 +304,13 @@ def do_usage_report(style, meta_view, meta_type_names, meta_enum_names, discover
274304def cli (source_path , output_path , debug_report_path , verbose , log_file , report_style ):
275305 """
276306 A CLI tool to generate a slot usage schemasheet from the LinkML metamodel and a source schema.
307+
308+ :param source_path: A filesystem or URL path to the schema that should be analysed and reported
309+ :param output_path: The filesystem path where the generated schemasheet will be written.
310+ :param debug_report_path: An optional filesystem path where a YAML report of excluded metaslots will be saved.
311+ :param verbose: If true, DEBUG logging will be used.
312+ :param log_file: An optional filesystem path where log messages will be saved.
313+ :param report_style: exhaustive means that all non-excluded metaslots will be included. concise means that only those metaslots used by the source schema will be included.
277314 """
278315
279316 # in some cases it will be better to get this from a local filesystem, not a URL...
0 commit comments