Skip to content

Commit d85a450

Browse files
committed
nested ifs, not ands for table_config scanning when exporting
1 parent 1314910 commit d85a450

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

schemasheets/schema_exporter.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SchemaExporter:
3131
"""
3232
Exports a schema to Schema Sheets TSV format
3333
"""
34-
schemamaker: SchemaMaker = field(default_factory= lambda: SchemaMaker())
34+
schemamaker: SchemaMaker = field(default_factory=lambda: SchemaMaker())
3535
delimiter = '\t'
3636
rows: List[ROW] = field(default_factory=lambda: [])
3737

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

95-
def export_element(self, element: Element, parent: Optional[Element], schemaview: SchemaView, table_config: TableConfig):
95+
def export_element(self, element: Element, parent: Optional[Element], schemaview: SchemaView,
96+
table_config: TableConfig):
9697
"""
9798
Translates an individual schema element to a row
9899
@@ -120,24 +121,39 @@ def export_element(self, element: Element, parent: Optional[Element], schemaview
120121
pk_col = col_name
121122
if isinstance(parent, ClassDefinition):
122123
parent_pk_col = col_name
123-
elif t == T_SLOT and isinstance(element, SlotDefinition):
124-
pk_col = col_name
125-
elif t == T_TYPE and isinstance(element, TypeDefinition):
126-
pk_col = col_name
127-
elif t == T_SUBSET and isinstance(element, SubsetDefinition):
128-
pk_col = col_name
124+
elif t == T_SLOT:
125+
if isinstance(element, SlotDefinition):
126+
pk_col = col_name
127+
else:
128+
continue
129+
elif t == T_TYPE:
130+
if isinstance(element, TypeDefinition):
131+
pk_col = col_name
132+
else:
133+
continue
134+
elif t == T_SUBSET:
135+
if isinstance(element, SubsetDefinition):
136+
pk_col = col_name
137+
else:
138+
continue
129139
elif t == T_ENUM:
130140
# permissible values MUST be contextualized by enums
131141
if isinstance(element, EnumDefinition):
132142
pk_col = col_name
133143
if isinstance(parent, EnumDefinition):
134144
parent_pk_col = col_name
135-
elif t == T_PV and isinstance(element, PermissibleValue):
136-
pk_col = col_name
137-
elif t == T_PREFIX and isinstance(element, Prefix):
138-
pk_col = col_name
145+
elif t == T_PV:
146+
if isinstance(element, PermissibleValue):
147+
pk_col = col_name
148+
else:
149+
continue
150+
elif t == T_PREFIX:
151+
if isinstance(element, Prefix):
152+
pk_col = col_name
153+
else:
154+
continue
139155
else:
140-
logging.warning(f"Not implemented: {t}")
156+
raise AssertionError(f"Unexpected type: {t}")
141157
if not pk_col:
142158
logging.info(f"Skipping element: {element}, no PK")
143159
return
@@ -182,6 +198,7 @@ def repl(v: Any) -> Optional[str]:
182198
if isinstance(v, bool):
183199
return str(v).lower()
184200
return v
201+
185202
# map the value (which may be a collection or an object) to a flat string
186203
# representation
187204
if isinstance(v, list):
@@ -311,5 +328,3 @@ def export_schema(tsv_files, output_directory, output: TextIO, overwrite: bool,
311328

312329
if __name__ == '__main__':
313330
export_schema()
314-
315-

0 commit comments

Comments
 (0)