References across schema packages

I am writing a plugin for my nomad-oasis in which I want to reference a section from one shema package in another schema. My repository looks similar this:

nomad-example
   ├── src
   │   ├── nomad_example
   │   │   ├── schema_packages
   │   │   │   ├── __init__.py
   │   │   │   ├── mypackage1.py
   │   │   │   ├── mypackage2.py
   ├── LICENSE.txt
   ├── README.md
   └── pyproject.toml

mypackage1 has a section section1:

class section1(Schema):
    m_def = Section(
        label='section1',
        categories=[ToolsCategory],
        a_eln=ELNAnnotation(),
    )

which I try to reference in schemapackage2 like this:

section1_ref = Quantity(
        type=SectionProxy('schemapackage1.section1'),
        a_eln=ELNAnnotation(
            component=ELNComponentEnum.ReferenceEditQuantity,
        ),
    )

I have tried all variations of ‘section1.m_def’, ‘schema_packages.schemapackage1.section1’, ‘nomad_example.schema_packages.schemapackage1.section1’, … as well as using Reference(…) or Reference(SectionProxy(…)).
When running run my oasis without the refernece, all works well. With the reference-quantity however, I get an Error.

In the tutorial it says “The strings given to SectionProxy are paths within the available definitions. [This] works, if [section1] is eventually defined in the same package.”

Is mypackge2 not in the same package or am I doing something else wrong?

Hi @kaikoebnick!

It should be possible to use definitions across packages. You can import the section definition as a Python class, and then define a reference with that type. Something like:

from nomad_example.schema_packages.mypackage1 import Section1

section1_ref = Quantity(
    type=Section1,
    a_eln=ELNAnnotation(
        component=ELNComponentEnum.ReferenceEditQuantity,
    )
)

SectionProxy is not usable in your case, since it can only resolve references that are within the same package, whereas you have here two packages.

Hope this helps, let me know if you have any further questions or issues.