Skip to content

Commit

Permalink
import schemas when they are looked for
Browse files Browse the repository at this point in the history
the schemas modules names must match the schema name, tus.
  • Loading branch information
denisri committed Jul 27, 2023
1 parent 5285699 commit e70f5b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion capsul/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path
import re
import sys
import importlib

from capsul.pipeline.pipeline import Process, Pipeline
from capsul.pipeline.process_iteration import ProcessIteration
Expand Down Expand Up @@ -63,7 +64,15 @@ def __init__(self, path=None, metadata_schema=None):

@classmethod
def find_schema(cls, metadata_schema):
return cls.schemas.get(metadata_schema)
schema = cls.schemas.get(metadata_schema)
if schema is None:
try:
# try to import the schema from capsul.schemas
importlib.import_module(f'capsul.schemas.{metadata_schema}')
except ImportError:
pass # oh well...
schema = cls.schemas.get(metadata_schema)
return schema

@classmethod
def find_schema_mapping(cls, source_schema, target_schema):
Expand Down
6 changes: 6 additions & 0 deletions capsul/schemas/brainvisa_shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-

# this module just aims to register the brainvisa_share schema when imported
# by Dataset.find_schema()

from . import brainvisa

0 comments on commit e70f5b7

Please sign in to comment.