metainfoyaml2py


Namemetainfoyaml2py JSON
Version 0.0.11 PyPI version JSON
download
home_pageNone
SummaryA program for converting NOMAD metainfo YAML schemas into Python class definitions
upload_time2024-05-14 07:52:26
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseApache-2.0
keywords nomad
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![](https://github.com/hampusnasstrom/metainfo-yaml2py/actions/workflows/publish.yml/badge.svg)
![](https://img.shields.io/pypi/pyversions/metainfoyaml2py)
![](https://img.shields.io/pypi/l/metainfoyaml2py)
![](https://img.shields.io/pypi/v/metainfoyaml2py)

# metainfo-yaml2py
A program for converting NOMAD metainfo YAML schemas into Python class definitions.

## Installation
`metainfo-yaml2py` can be installed from PyPI using pip:
```sh
pip install metainfoyaml2py
```
You can then run the program with:

```
metainfo-yaml2py <target file>
```

### For development
`metainfo-yaml2py` is currently under development and for installing and contributing you should clone the repository and install the package in editable mode (`-e`) using:
```
pip install -e .
```

## Example
Running `metainfo-yaml2py` on the following YAML file (with the `-n` flag):
```yaml
definitions:
  name: Example Schema
  sections:
    Activity:
      description: |
        A base class for any activity in relation to an entity.
        This docstring can span multiple lines.
      quantities:
        start_time:
          description: |
            The starting date and time of the activity.
          type: Datetime
          m_annotations:
            eln:
              component: DateTimeEditQuantity
        end_time:
          description: |
            The ending date and time of the activity.
          type: Datetime
          m_annotations:
            eln:
              component: DateTimeEditQuantity
    Entity:
      description: |
        A base class for any entity which can be related to an activity.
```

Will create the following python file:
```python
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from nomad.datamodel.data import ArchiveSection
from typing import (
    TYPE_CHECKING,
)
from nomad.metainfo import (
    Package,
    Quantity,
    Datetime,
    Section,
)
from nomad.datamodel.data import (
    ArchiveSection,
)
if TYPE_CHECKING:
    from nomad.datamodel.datamodel import (
        EntryArchive,
    )
    from structlog.stdlib import (
        BoundLogger,
    )

m_package = Package(name='Example Schema')


class Activity(ArchiveSection):
    '''
    A base class for any activity in relation to an entity.
    This docstring can span multiple lines.
    '''
    m_def = Section()
    start_time = Quantity(
        type=Datetime,
        description='''
        The starting date and time of the activity.
        ''',
        a_eln={
            "component": "DateTimeEditQuantity"
        },
    )
    end_time = Quantity(
        type=Datetime,
        description='''
        The ending date and time of the activity.
        ''',
        a_eln={
            "component": "DateTimeEditQuantity"
        },
    )

    def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
        '''
        The normalizer for the `Activity` class.

        Args:
            archive (EntryArchive): The archive containing the section that is being
            normalized.
            logger (BoundLogger): A structlog logger.
        '''
        super(Activity, self).normalize(archive, logger)


class Entity(ArchiveSection):
    '''
    A base class for any entity which can be related to an activity.
    '''
    m_def = Section()

    def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
        '''
        The normalizer for the `Entity` class.

        Args:
            archive (EntryArchive): The archive containing the section that is being
            normalized.
            logger (BoundLogger): A structlog logger.
        '''
        super(Entity, self).normalize(archive, logger)


m_package.__init_metainfo__()

```

## Command Line Interface
```sh
metainfo-yaml2py --help
usage: metainfo-yaml2py [-h] [-o OUTPUT_DIR] [-n] [-p] yaml_path

positional arguments:
  yaml_path             The path to the YAML schema that should be converted to Python
                        classes.

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT_DIR, --output_dir OUTPUT_DIR
                        The path to the output directory of the conversion. Defaults to
                        the current directory.
  -n, --normalizers     Add empty normalizers to all class definitions.
  -p, --plugin          Create all the necessary files for a nomad plugin.
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "metainfoyaml2py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Hampus N\u00e4sstr\u00f6m <hampus.naesstroem@physik.hu-berlin.de>",
    "keywords": "nomad",
    "author": null,
    "author_email": "Hampus N\u00e4sstr\u00f6m <hampus.naesstroem@physik.hu-berlin.de>",
    "download_url": "https://files.pythonhosted.org/packages/9d/30/c2505f9b9dbaa59e2c87ddb8fcd276a5520043bfbcbaf04ef6c85372feb4/metainfoyaml2py-0.0.11.tar.gz",
    "platform": null,
    "description": "![](https://github.com/hampusnasstrom/metainfo-yaml2py/actions/workflows/publish.yml/badge.svg)\n![](https://img.shields.io/pypi/pyversions/metainfoyaml2py)\n![](https://img.shields.io/pypi/l/metainfoyaml2py)\n![](https://img.shields.io/pypi/v/metainfoyaml2py)\n\n# metainfo-yaml2py\nA program for converting NOMAD metainfo YAML schemas into Python class definitions.\n\n## Installation\n`metainfo-yaml2py` can be installed from PyPI using pip:\n```sh\npip install metainfoyaml2py\n```\nYou can then run the program with:\n\n```\nmetainfo-yaml2py <target file>\n```\n\n### For development\n`metainfo-yaml2py` is currently under development and for installing and contributing you should clone the repository and install the package in editable mode (`-e`) using:\n```\npip install -e .\n```\n\n## Example\nRunning `metainfo-yaml2py` on the following YAML file (with the `-n` flag):\n```yaml\ndefinitions:\n  name: Example Schema\n  sections:\n    Activity:\n      description: |\n        A base class for any activity in relation to an entity.\n        This docstring can span multiple lines.\n      quantities:\n        start_time:\n          description: |\n            The starting date and time of the activity.\n          type: Datetime\n          m_annotations:\n            eln:\n              component: DateTimeEditQuantity\n        end_time:\n          description: |\n            The ending date and time of the activity.\n          type: Datetime\n          m_annotations:\n            eln:\n              component: DateTimeEditQuantity\n    Entity:\n      description: |\n        A base class for any entity which can be related to an activity.\n```\n\nWill create the following python file:\n```python\n#\n# Copyright The NOMAD Authors.\n#\n# This file is part of NOMAD. See https://nomad-lab.eu for further info.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\nfrom nomad.datamodel.data import ArchiveSection\nfrom typing import (\n    TYPE_CHECKING,\n)\nfrom nomad.metainfo import (\n    Package,\n    Quantity,\n    Datetime,\n    Section,\n)\nfrom nomad.datamodel.data import (\n    ArchiveSection,\n)\nif TYPE_CHECKING:\n    from nomad.datamodel.datamodel import (\n        EntryArchive,\n    )\n    from structlog.stdlib import (\n        BoundLogger,\n    )\n\nm_package = Package(name='Example Schema')\n\n\nclass Activity(ArchiveSection):\n    '''\n    A base class for any activity in relation to an entity.\n    This docstring can span multiple lines.\n    '''\n    m_def = Section()\n    start_time = Quantity(\n        type=Datetime,\n        description='''\n        The starting date and time of the activity.\n        ''',\n        a_eln={\n            \"component\": \"DateTimeEditQuantity\"\n        },\n    )\n    end_time = Quantity(\n        type=Datetime,\n        description='''\n        The ending date and time of the activity.\n        ''',\n        a_eln={\n            \"component\": \"DateTimeEditQuantity\"\n        },\n    )\n\n    def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:\n        '''\n        The normalizer for the `Activity` class.\n\n        Args:\n            archive (EntryArchive): The archive containing the section that is being\n            normalized.\n            logger (BoundLogger): A structlog logger.\n        '''\n        super(Activity, self).normalize(archive, logger)\n\n\nclass Entity(ArchiveSection):\n    '''\n    A base class for any entity which can be related to an activity.\n    '''\n    m_def = Section()\n\n    def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:\n        '''\n        The normalizer for the `Entity` class.\n\n        Args:\n            archive (EntryArchive): The archive containing the section that is being\n            normalized.\n            logger (BoundLogger): A structlog logger.\n        '''\n        super(Entity, self).normalize(archive, logger)\n\n\nm_package.__init_metainfo__()\n\n```\n\n## Command Line Interface\n```sh\nmetainfo-yaml2py --help\nusage: metainfo-yaml2py [-h] [-o OUTPUT_DIR] [-n] [-p] yaml_path\n\npositional arguments:\n  yaml_path             The path to the YAML schema that should be converted to Python\n                        classes.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -o OUTPUT_DIR, --output_dir OUTPUT_DIR\n                        The path to the output directory of the conversion. Defaults to\n                        the current directory.\n  -n, --normalizers     Add empty normalizers to all class definitions.\n  -p, --plugin          Create all the necessary files for a nomad plugin.\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A program for converting NOMAD metainfo YAML schemas into Python class definitions",
    "version": "0.0.11",
    "project_urls": {
        "Bug Tracker": "https://github.com/hampusnasstrom/metainfo-yaml2py/issues",
        "Homepage": "https://github.com/hampusnasstrom/metainfo-yaml2py"
    },
    "split_keywords": [
        "nomad"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "20c5c3799fa23949ba2233f0d78762c44616ff7908b886ca32a476ed0de0db05",
                "md5": "b9432e20ad0b02cf509ae31a2da82893",
                "sha256": "8244438a85742c09e84a9aa7b5ea1fac921af427ca96445a18c87bd7224615b9"
            },
            "downloads": -1,
            "filename": "metainfoyaml2py-0.0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b9432e20ad0b02cf509ae31a2da82893",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 21041,
            "upload_time": "2024-05-14T07:52:25",
            "upload_time_iso_8601": "2024-05-14T07:52:25.766228Z",
            "url": "https://files.pythonhosted.org/packages/20/c5/c3799fa23949ba2233f0d78762c44616ff7908b886ca32a476ed0de0db05/metainfoyaml2py-0.0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d30c2505f9b9dbaa59e2c87ddb8fcd276a5520043bfbcbaf04ef6c85372feb4",
                "md5": "bb8febb9f75035f7fa3b431b716850ab",
                "sha256": "902d6ef55f2b420fbce1fc4555ef6ca78975c178370795a307f3d17836a5f3e5"
            },
            "downloads": -1,
            "filename": "metainfoyaml2py-0.0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "bb8febb9f75035f7fa3b431b716850ab",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 32121,
            "upload_time": "2024-05-14T07:52:26",
            "upload_time_iso_8601": "2024-05-14T07:52:26.777533Z",
            "url": "https://files.pythonhosted.org/packages/9d/30/c2505f9b9dbaa59e2c87ddb8fcd276a5520043bfbcbaf04ef6c85372feb4/metainfoyaml2py-0.0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-14 07:52:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hampusnasstrom",
    "github_project": "metainfo-yaml2py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "metainfoyaml2py"
}
        
Elapsed time: 5.03531s