Skip to content

Commit

Permalink
adding base_schema_path to the converter (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
djarecka authored Mar 25, 2024
1 parent 40feaec commit 649af7e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions schemasheets/schemamaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SchemaMaker:
unique_slots: bool = None
gsheet_id: str = None
table_config_path: str = None
base_schema_path: str = None

def create_schema(self, csv_files: Union[str, List[str]], **kwargs) -> SchemaDefinition:
"""
Expand All @@ -55,8 +56,13 @@ def create_schema(self, csv_files: Union[str, List[str]], **kwargs) -> SchemaDef
:param kwargs:
:return: generated schema
"""
n = self.default_name
if n is None:
self.base_view = SchemaView(self.base_schema_path) if self.base_schema_path else None

if self.default_name:
n = self.default_name
elif self.base_view and self.base_view.schema.name:
n = self.base_view.schema.name
else:
n = 'TEMP'
self.schema = SchemaDefinition(id=n, name=n, default_prefix=n, default_range='string')
if not isinstance(csv_files, list):
Expand All @@ -70,6 +76,9 @@ def create_schema(self, csv_files: Union[str, List[str]], **kwargs) -> SchemaDef
if prefix not in self.schema.prefixes:
logging.error(f'Prefix {prefix} not declared: using default')
self.schema.prefixes[prefix] = Prefix(prefix, f'https://example.org/{prefix}/')

if self.base_view:
SchemaView(self.schema).merge_schema(self.base_view.schema)
return self.schema

def _tidy_slot_usage(self):
Expand Down Expand Up @@ -660,10 +669,12 @@ def ensure_csvreader(self, file_name: str, delimiter=None) -> str:
help="Auto-repair schema")
@click.option("--gsheet-id",
help="Google sheets ID. If this is specified then the arguments MUST be sheet names")
@click.option("--base-schema-path",
help="Base schema yaml file, the base-schema will be merged with the generated schema")
@click.option("-v", "--verbose", count=True)
@click.argument('tsv_files', nargs=-1)
def convert(tsv_files, gsheet_id, output: TextIO, name, repair, table_config_path: str, use_attributes: bool,
unique_slots: bool, verbose: int, sort_keys: bool):
unique_slots: bool, verbose: int, sort_keys: bool, base_schema_path: str):
"""
Convert schemasheets to a LinkML schema
Expand All @@ -688,7 +699,8 @@ def convert(tsv_files, gsheet_id, output: TextIO, name, repair, table_config_pat
unique_slots=unique_slots,
gsheet_id=gsheet_id,
default_name=name,
table_config_path=table_config_path)
table_config_path=table_config_path,
base_schema_path=base_schema_path)
schema = sm.create_schema(list(tsv_files))
if repair:
schema = sm.repair_schema(schema)
Expand Down

0 comments on commit 649af7e

Please sign in to comment.