neoconfigen


Nameneoconfigen JSON
Version 2.4.2 PyPI version JSON
download
home_pagehttps://github.com/predictive-analytics-lab/neoconfigen
SummaryA fork of hydra-core's configen with extended type-compatibility.
upload_time2023-10-10 18:40:05
maintainer
docs_urlNone
authorOmry Yadan
requires_python>=3.9,<3.13
licenseMIT
keywords hydra python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # configen

Automatically generates Structured Configs that can be used with hydra.utils.instantiate()

This is optional at two levels:
1. Structured Configs are optional, one can use Hydra without them.
2. One can manually code these dataclasses. The advantage of this tool is that it does the work automatically.

# Setup
Configen requires config file per project. The config indicates what classes to generate code for, where to put
the generated code etc.
Configen will suggest creating a config on the first run:
```
$ configen 
[2020-08-14 12:06:11,359][configen.configen][ERROR] - Use --config-dir DIR.
If you have no config dir yet use the following command to create an initial config in the `conf` dir:
        configen init_config_dir=conf
$ configen init_config_dir=conf
[2020-08-14 12:07:07,752][configen.configen][INFO] - Initializing config in 'conf'
```

This will generate a basic config similar to:
```yaml
$ cat conf/configen.yaml 
configen:
  # output directory
  output_dir: ${hydra:runtime.cwd}/gen

  header: |
    # Generated by configen, do not edit.
    # See https://github.com/facebookresearch/hydra/tree/master/tools/configen

  # The directory of each module under output_dir
  module_dir: '{{module_path}}/conf'

  # list of modules to generate configs for
  modules:
    - name: configen.samples.user
      # for each module, a list of classes
      classes:
        - User
```

Configen comes with a few samples [classes](configen/samples) that are being processed by the default config.
For example:
```python title="configen/samples/user.py"
class User:
    def __init__(self, age: int, name: str):
        self.age = age
        self.name = name
```

Running configen with this config directory:
```
$ configen --config-dir conf
[2020-08-14 12:44:54,990][configen.configen][INFO] - configen.samples.user.User -> /home/omry/tmp/configen/gen/configen/samples/user/conf/User.py
```

Will result in a file `gen/configen/samples/user/conf/User.py` like:
```python
# Generated by configen, do not edit.
# See https://github.com/facebookresearch/hydra/tree/master/tools/configen
# fmt: off
# isort:skip_file
# flake8: noqa

from dataclasses import dataclass
from typing import *

from omegaconf import MISSING


@dataclass
class UserConf:
    _target_: str = "configen.samples.user.User"
    age: int = MISSING
    name: str = MISSING
```

The generated code can be used by a Hydra application to instantiate the user object.
See the [example aplication](example/my_app.py).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/predictive-analytics-lab/neoconfigen",
    "name": "neoconfigen",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<3.13",
    "maintainer_email": "",
    "keywords": "hydra,python",
    "author": "Omry Yadan",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/4a/ae/756f7dc083952ef94c89828c1f6c8ccdb77b97fbe671d7cd7ffebda0e1a5/neoconfigen-2.4.2.tar.gz",
    "platform": null,
    "description": "# configen\n\nAutomatically generates Structured Configs that can be used with hydra.utils.instantiate()\n\nThis is optional at two levels:\n1. Structured Configs are optional, one can use Hydra without them.\n2. One can manually code these dataclasses. The advantage of this tool is that it does the work automatically.\n\n# Setup\nConfigen requires config file per project. The config indicates what classes to generate code for, where to put\nthe generated code etc.\nConfigen will suggest creating a config on the first run:\n```\n$ configen \n[2020-08-14 12:06:11,359][configen.configen][ERROR] - Use --config-dir DIR.\nIf you have no config dir yet use the following command to create an initial config in the `conf` dir:\n        configen init_config_dir=conf\n$ configen init_config_dir=conf\n[2020-08-14 12:07:07,752][configen.configen][INFO] - Initializing config in 'conf'\n```\n\nThis will generate a basic config similar to:\n```yaml\n$ cat conf/configen.yaml \nconfigen:\n  # output directory\n  output_dir: ${hydra:runtime.cwd}/gen\n\n  header: |\n    # Generated by configen, do not edit.\n    # See https://github.com/facebookresearch/hydra/tree/master/tools/configen\n\n  # The directory of each module under output_dir\n  module_dir: '{{module_path}}/conf'\n\n  # list of modules to generate configs for\n  modules:\n    - name: configen.samples.user\n      # for each module, a list of classes\n      classes:\n        - User\n```\n\nConfigen comes with a few samples [classes](configen/samples) that are being processed by the default config.\nFor example:\n```python title=\"configen/samples/user.py\"\nclass User:\n    def __init__(self, age: int, name: str):\n        self.age = age\n        self.name = name\n```\n\nRunning configen with this config directory:\n```\n$ configen --config-dir conf\n[2020-08-14 12:44:54,990][configen.configen][INFO] - configen.samples.user.User -> /home/omry/tmp/configen/gen/configen/samples/user/conf/User.py\n```\n\nWill result in a file `gen/configen/samples/user/conf/User.py` like:\n```python\n# Generated by configen, do not edit.\n# See https://github.com/facebookresearch/hydra/tree/master/tools/configen\n# fmt: off\n# isort:skip_file\n# flake8: noqa\n\nfrom dataclasses import dataclass\nfrom typing import *\n\nfrom omegaconf import MISSING\n\n\n@dataclass\nclass UserConf:\n    _target_: str = \"configen.samples.user.User\"\n    age: int = MISSING\n    name: str = MISSING\n```\n\nThe generated code can be used by a Hydra application to instantiate the user object.\nSee the [example aplication](example/my_app.py).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A fork of hydra-core's configen with extended type-compatibility.",
    "version": "2.4.2",
    "project_urls": {
        "Homepage": "https://github.com/predictive-analytics-lab/neoconfigen",
        "Repository": "https://github.com/predictive-analytics-lab/neoconfigen"
    },
    "split_keywords": [
        "hydra",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c0fa52f1f58d68f043f93e86e0e27bf8f323be1303b801b206936ebc530d283f",
                "md5": "5c3c591a90a2e7eab1d6391c7e490bf0",
                "sha256": "0059024f1558a2193d0b790514b17ffa727ea1eac90fd580b52ebccf5cc88ce9"
            },
            "downloads": -1,
            "filename": "neoconfigen-2.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5c3c591a90a2e7eab1d6391c7e490bf0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<3.13",
            "size": 9410,
            "upload_time": "2023-10-10T18:40:01",
            "upload_time_iso_8601": "2023-10-10T18:40:01.980273Z",
            "url": "https://files.pythonhosted.org/packages/c0/fa/52f1f58d68f043f93e86e0e27bf8f323be1303b801b206936ebc530d283f/neoconfigen-2.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4aae756f7dc083952ef94c89828c1f6c8ccdb77b97fbe671d7cd7ffebda0e1a5",
                "md5": "e5e3f39f5e10b06de9e1a416fb3a3b58",
                "sha256": "b5644ecbb4b2961c1defab53ad0eaa201744e6303ed9aec32660bca52ffd0ba4"
            },
            "downloads": -1,
            "filename": "neoconfigen-2.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e5e3f39f5e10b06de9e1a416fb3a3b58",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<3.13",
            "size": 8078,
            "upload_time": "2023-10-10T18:40:05",
            "upload_time_iso_8601": "2023-10-10T18:40:05.095983Z",
            "url": "https://files.pythonhosted.org/packages/4a/ae/756f7dc083952ef94c89828c1f6c8ccdb77b97fbe671d7cd7ffebda0e1a5/neoconfigen-2.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-10 18:40:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "predictive-analytics-lab",
    "github_project": "neoconfigen",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "neoconfigen"
}
        
Elapsed time: 0.12358s