Skip to content

Commit

Permalink
Merge pull request #112 from linkml/silence-not-impl
Browse files Browse the repository at this point in the history
nested ifs, not ands for table_config scanning when exporting
  • Loading branch information
turbomam authored Jul 14, 2023
2 parents 1314910 + d85a450 commit f3323b9
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions schemasheets/schema_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SchemaExporter:
"""
Exports a schema to Schema Sheets TSV format
"""
schemamaker: SchemaMaker = field(default_factory= lambda: SchemaMaker())
schemamaker: SchemaMaker = field(default_factory=lambda: SchemaMaker())
delimiter = '\t'
rows: List[ROW] = field(default_factory=lambda: [])

Expand Down Expand Up @@ -92,7 +92,8 @@ def export(self, schemaview: SchemaView, specification: str = None,
for row in self.rows:
writer.writerow(row)

def export_element(self, element: Element, parent: Optional[Element], schemaview: SchemaView, table_config: TableConfig):
def export_element(self, element: Element, parent: Optional[Element], schemaview: SchemaView,
table_config: TableConfig):
"""
Translates an individual schema element to a row
Expand Down Expand Up @@ -120,24 +121,39 @@ def export_element(self, element: Element, parent: Optional[Element], schemaview
pk_col = col_name
if isinstance(parent, ClassDefinition):
parent_pk_col = col_name
elif t == T_SLOT and isinstance(element, SlotDefinition):
pk_col = col_name
elif t == T_TYPE and isinstance(element, TypeDefinition):
pk_col = col_name
elif t == T_SUBSET and isinstance(element, SubsetDefinition):
pk_col = col_name
elif t == T_SLOT:
if isinstance(element, SlotDefinition):
pk_col = col_name
else:
continue
elif t == T_TYPE:
if isinstance(element, TypeDefinition):
pk_col = col_name
else:
continue
elif t == T_SUBSET:
if isinstance(element, SubsetDefinition):
pk_col = col_name
else:
continue
elif t == T_ENUM:
# permissible values MUST be contextualized by enums
if isinstance(element, EnumDefinition):
pk_col = col_name
if isinstance(parent, EnumDefinition):
parent_pk_col = col_name
elif t == T_PV and isinstance(element, PermissibleValue):
pk_col = col_name
elif t == T_PREFIX and isinstance(element, Prefix):
pk_col = col_name
elif t == T_PV:
if isinstance(element, PermissibleValue):
pk_col = col_name
else:
continue
elif t == T_PREFIX:
if isinstance(element, Prefix):
pk_col = col_name
else:
continue
else:
logging.warning(f"Not implemented: {t}")
raise AssertionError(f"Unexpected type: {t}")
if not pk_col:
logging.info(f"Skipping element: {element}, no PK")
return
Expand Down Expand Up @@ -182,6 +198,7 @@ def repl(v: Any) -> Optional[str]:
if isinstance(v, bool):
return str(v).lower()
return v

# map the value (which may be a collection or an object) to a flat string
# representation
if isinstance(v, list):
Expand Down Expand Up @@ -311,5 +328,3 @@ def export_schema(tsv_files, output_directory, output: TextIO, overwrite: bool,

if __name__ == '__main__':
export_schema()


0 comments on commit f3323b9

Please sign in to comment.