metainfoyaml2py


Namemetainfoyaml2py JSON
Version 0.0.9 PyPI version JSON
download
home_page
SummaryA program for converting NOMAD metainfo YAML schemas into Python class definitions
upload_time2023-11-14 17:39:59
maintainer
docs_urlNone
author
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 structlog.stdlib import (
    BoundLogger,
)
from nomad.metainfo import (
    Package,
    Quantity,
    Datetime,
    Section,
)
from nomad.datamodel.data import (
    ArchiveSection,
)

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, 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, 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": "",
    "name": "metainfoyaml2py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Hampus N\u00e4sstr\u00f6m <hampus.naesstroem@physik.hu-berlin.de>",
    "keywords": "nomad",
    "author": "",
    "author_email": "Hampus N\u00e4sstr\u00f6m <hampus.naesstroem@physik.hu-berlin.de>",
    "download_url": "https://files.pythonhosted.org/packages/7d/76/9cb61a7644e23843774c5855db0af9f4dabe49955c59635eff50a5913f82/metainfoyaml2py-0.0.9.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 structlog.stdlib import (\n    BoundLogger,\n)\nfrom nomad.metainfo import (\n    Package,\n    Quantity,\n    Datetime,\n    Section,\n)\nfrom nomad.datamodel.data import (\n    ArchiveSection,\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, 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, 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.9",
    "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": "52c68434c0681bfddde13d4fe80e03d6c5da9c9f9b0019f0ac6950d55696ddca",
                "md5": "a1a725d42b6dd70d5da34523ef48d8cd",
                "sha256": "1a427824eec601427bbd9e77ae5daac5480d437edf8f207b9739510dd3b756b0"
            },
            "downloads": -1,
            "filename": "metainfoyaml2py-0.0.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a1a725d42b6dd70d5da34523ef48d8cd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 20901,
            "upload_time": "2023-11-14T17:39:58",
            "upload_time_iso_8601": "2023-11-14T17:39:58.009091Z",
            "url": "https://files.pythonhosted.org/packages/52/c6/8434c0681bfddde13d4fe80e03d6c5da9c9f9b0019f0ac6950d55696ddca/metainfoyaml2py-0.0.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d769cb61a7644e23843774c5855db0af9f4dabe49955c59635eff50a5913f82",
                "md5": "118a5b74010dc683237b466a84359240",
                "sha256": "a1f1abd621d30ebe8326a45e82339d3f0ca1778ac61ef1122066dd6f7fb9522a"
            },
            "downloads": -1,
            "filename": "metainfoyaml2py-0.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "118a5b74010dc683237b466a84359240",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 31909,
            "upload_time": "2023-11-14T17:39:59",
            "upload_time_iso_8601": "2023-11-14T17:39:59.667323Z",
            "url": "https://files.pythonhosted.org/packages/7d/76/9cb61a7644e23843774c5855db0af9f4dabe49955c59635eff50a5913f82/metainfoyaml2py-0.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-14 17:39:59",
    "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: 0.13804s