diff --git a/nwb_linkml/src/nwb_linkml/adapters/namespaces.py b/nwb_linkml/src/nwb_linkml/adapters/namespaces.py index f607c5d..71fba06 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/namespaces.py +++ b/nwb_linkml/src/nwb_linkml/adapters/namespaces.py @@ -73,14 +73,14 @@ class NamespacesAdapter(Adapter): if progress is not None: try: progress.update(sch.namespace, action=sch.name) - except KeyError: - # happens when we skip builds due to cachine + except KeyError: # pragma: no cover + # happens when we skip builds due to caching pass sch_result += sch.build() if progress is not None: try: progress.update(sch.namespace, advance=1) - except KeyError: + except KeyError: # pragma: no cover # happens when we skip builds due to caching pass @@ -113,7 +113,7 @@ class NamespacesAdapter(Adapter): description = ns.doc, version = ns.version, imports=ns_schemas, - annotations=[{'tag': 'namespace', 'value': True}] + annotations=[{'tag': 'is_namespace', 'value': True}, {'tag': 'namespace', 'value': ns.name}] ) sch_result.schemas.append(ns_schema) diff --git a/nwb_linkml/src/nwb_linkml/adapters/schema.py b/nwb_linkml/src/nwb_linkml/adapters/schema.py index 3f350d9..bbffe05 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/schema.py +++ b/nwb_linkml/src/nwb_linkml/adapters/schema.py @@ -72,7 +72,7 @@ class SchemaAdapter(Adapter): for group in self.groups: res += GroupAdapter(cls=group).build() - if len(res.slots) > 0: + if len(res.slots) > 0: # pragma: no cover - hard to induce this error because the child classes don't fuck up like this raise RuntimeError('Generated schema in this translation can only have classes, all slots should be attributes within a class') sch = SchemaDefinition( @@ -82,7 +82,8 @@ class SchemaAdapter(Adapter): classes=res.classes, slots=res.slots, types=res.types, - version=self.version + version=self.version, + annotations=[{'tag': 'is_namespace', 'value': False}, {'tag': 'namespace', 'value': self.namespace}] ) # every schema needs the language elements sch.imports.append('.'.join([self.namespace, 'nwb.language'])) diff --git a/nwb_linkml/src/nwb_linkml/generators/pydantic.py b/nwb_linkml/src/nwb_linkml/generators/pydantic.py index f1aa9f4..1675f1e 100644 --- a/nwb_linkml/src/nwb_linkml/generators/pydantic.py +++ b/nwb_linkml/src/nwb_linkml/generators/pydantic.py @@ -328,7 +328,7 @@ class NWBPydanticGenerator(PydanticGenerator): if not self.split: # we are compiling this whole thing in one big file so we don't import anything return {} - if 'namespace' in sv.schema.annotations.keys() and sv.schema.annotations['namespace']['value'] == 'True': + if 'is_namespace' in sv.schema.annotations.keys() and sv.schema.annotations['is_namespace']['value'] == 'True': return self._get_namespace_imports(sv) all_classes = sv.all_classes(imports=True) diff --git a/nwb_linkml/src/nwb_linkml/providers/git.py b/nwb_linkml/src/nwb_linkml/providers/git.py index a542ddb..3422db7 100644 --- a/nwb_linkml/src/nwb_linkml/providers/git.py +++ b/nwb_linkml/src/nwb_linkml/providers/git.py @@ -135,18 +135,16 @@ class GitRepo: @commit.setter def commit(self, commit:str|None): - # first get out of a potential detached head state - # that would cause a call to "HEAD" to fail in unexpected ways - if self.detached_head: - self._git_call('checkout', self.default_branch) + # setting commit as None should do nothing if we have already cloned, + # and if we are just cloning we will always be at the most recent commit anyway + if commit is not None: + # first get out of a potential detached head state + # that would cause a call to "HEAD" to fail in unexpected ways + if self.detached_head: + self._git_call('checkout', self.default_branch) - if commit is None: - if len(self.namespace.versions) > 0: - self._git_call('checkout', self.namespace.versions[-1]) - else: - self._git_call('checkout', "HEAD") - else: self._git_call('checkout', commit) + self._git_call('submodule', 'update', '--init', '--recursive') self._commit = commit @@ -277,7 +275,6 @@ class GitRepo: self.cleanup() else: # already have it, just ensure commit and return - self.commit = self.commit return elif self.temp_directory.exists(): diff --git a/nwb_linkml/src/nwb_linkml/providers/schema.py b/nwb_linkml/src/nwb_linkml/providers/schema.py index 04472f6..dcfad4d 100644 --- a/nwb_linkml/src/nwb_linkml/providers/schema.py +++ b/nwb_linkml/src/nwb_linkml/providers/schema.py @@ -384,7 +384,7 @@ class LinkMLProvider(Provider): # write schemas to yaml files build_result = {} - namespace_sch = [sch for sch in built.schemas if 'namespace' in sch.annotations.keys()] + namespace_sch = [sch for sch in built.schemas if sch.annotations.get('is_namespace', False) and sch.annotations['is_namespace'].value == 'True'] for ns_linkml in namespace_sch: version = ns_adapter.versions[ns_linkml.name] version_path = self.namespace_path(ns_linkml.name, version, allow_repo=False) diff --git a/nwb_linkml/tests/fixtures.py b/nwb_linkml/tests/fixtures.py index 55d6dc9..4a02f29 100644 --- a/nwb_linkml/tests/fixtures.py +++ b/nwb_linkml/tests/fixtures.py @@ -220,7 +220,7 @@ def linkml_schema_bare() -> TestSchemas: id="namespace", version="1.1.1", default_prefix="namespace", - annotations={'namespace': {'tag': 'namespace', 'value': 'True'}}, + annotations=[{'tag': 'is_namespace', 'value': 'True'}, {'tag': 'namespace', 'value': 'core'}], description="A namespace package that should import all other classes", imports=['core', 'imported'] ) diff --git a/nwb_linkml/tests/test_adapters/test_adapter_namespaces.py b/nwb_linkml/tests/test_adapters/test_adapter_namespaces.py index 21f4230..c0d010a 100644 --- a/nwb_linkml/tests/test_adapters/test_adapter_namespaces.py +++ b/nwb_linkml/tests/test_adapters/test_adapter_namespaces.py @@ -1,3 +1,5 @@ +import pdb + import pytest from ..fixtures import nwb_core_fixture from nwb_schema_language import Dataset, Group @@ -32,4 +34,14 @@ def test_populate_imports(nwb_core_fixture): def test_build(nwb_core_fixture): - pass \ No newline at end of file + pass + +def test_skip_imports(nwb_core_fixture): + """ + We can build just the namespace in question without also building the other namespaces that it imports + """ + res = nwb_core_fixture.build(skip_imports=True) + + # we shouldn't have any of the hdmf-common schema in with us + namespaces = [sch.annotations['namespace'].value for sch in res.schemas] + assert all([ns == 'core' for ns in namespaces]) \ No newline at end of file diff --git a/nwb_linkml/tests/test_adapters/test_adapter_schema.py b/nwb_linkml/tests/test_adapters/test_adapter_schema.py index dd8b47e..2edbcd0 100644 --- a/nwb_linkml/tests/test_adapters/test_adapter_schema.py +++ b/nwb_linkml/tests/test_adapters/test_adapter_schema.py @@ -11,4 +11,15 @@ from nwb_schema_language import Dataset, Group, Schema ) def test_schema_build(nwb_core_fixture, schema_name): schema = [sch for sch in nwb_core_fixture.schemas if sch.name == schema_name][0] - res = schema.build() \ No newline at end of file + res = schema.build() + + + +def test_schema_repr(nwb_core_fixture): + """ + Doesn't really make sense to test the string repr matches any particular value because it's + strictly cosmetic, but we do test that it can be done + """ + sch = nwb_core_fixture.schemas[0] + repr_str = sch.__repr__() + assert isinstance(repr_str, str)