ninja-bear


Nameninja-bear JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/monstermichl/ninja-bear.git
Summaryninja-bear keeps your language specific constants in sync
upload_time2024-11-04 15:16:52
maintainerNone
docs_urlNone
authormonstermichl
requires_python>=3.10
licenseNone
keywords ninja-bear constants language generator distributor
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ninja-bear 🥷🐻
In times of distributed systems and en vogue micro-architecture it can get quite cumbersome to keep constants that are required by several components up-to-date and in sync. It can get especially hard when these components or services are written in different languages. ninja-bear targets this issue by using a language neutral YAML configuration that lets you generate language specific constant-files.

## Concept
ninja-bear uses a plugin-based approach in which each language and distributor is an independend Python module. This gives developers a high amount of flexibility by letting them define and publish their own languages and distributors without the need to modify ninja-bear directly.

## Installation
```bash
pip install ninja-bear
```

## Example
Lets have a look at a simple example to see what *ninja-bear* can do for you.

The example YAML file contains a property named *greeting* with the value "Hello World". Constant-files shall be generated for [TypeScript](https://pypi.org/project/ninja-bear-language-typescript/), [Python](https://pypi.org/project/ninja-bear-language-python/) and [C](https://pypi.org/project/ninja-bear-language-c/) (using the corresponding plugins). In case of *C*, the value shall be changed to *"Hello Mars"* and the file shall be distributed to Git using the [ninja-bear-distributor-git](https://pypi.org/project/ninja-bear-distributor-git/) plugin.

For detailed configuration information, please check [test-config.yaml](https://github.com/monstermichl/ninja-bear/blob/main/example/test-config.yaml). All possible values are described there.

### Input (readme-config.yaml)
```yaml
# -----------------------------------------------------------------------------
# This section defines languages and properties which are usually the settings
# that you'll use the most.
# -----------------------------------------------------------------------------
languages:
  - language: typescript
    property_naming: screaming-snake
    export: esm

  - language: python
    file_naming: snake
    property_naming: screaming-snake

  - language: c
    file_naming: snake
    property_naming: pascal

    transformers:
      - mars-transformer

    distributors:
      - git-distributor

properties:
  - type: string
    name: greeting
    value: Hello World

# -----------------------------------------------------------------------------
# This sections defines the available transformers and distributors. They are
# are used if property values need to be transformed before they get written
# or if specific language constants shall be distributed. To use a transformer
# and/or a distributor, its alias needs to be used in the language section
# (refer to c-example).
# -----------------------------------------------------------------------------
transformers:
  - transformer: |
      value = 'Hello Mars'
    as: mars-transformer

distributors:
  - distributor: git
    as: git-distributor
```

### Execute ninja-bear
```bash
# -d is used to distribute the C-file to Git.
ninja-bear -c readme-config.yaml -d
```

### Output (readme-config.ts)
```typescript
export const ReadmeConfig = {
    GREETING: 'Hello World',
} as const;
```

### Output (readme_config.py)
```python
from dataclasses import dataclass

@dataclass(frozen=True)
class ReadmeConfig:
    GREETING = 'Hello World'
```

### Output (readme_config.h)
```c
#ifndef README_CONFIG_H
#define README_CONFIG_H

const struct {
    char Greeting[11];
} ReadmeConfig = {
    "Hello Mars",
};

#endif /* README_CONFIG_H */
```

## Usage
### Commandline
```bash
ninja-bear -c test-config.yaml -o generated
```

### Script
```python
from ninja_bear import Orchestrator

# Create Orchestrator instance from file.
orchestrator = Orchestrator.read_config('test-config.yaml')

# Write constants to 'generated' directory.
orchestrator.write('generated')

# Distribute constants (if required).
orchestrator.distribute()
```

## Create a plugin
To create a new plugin, clone the repository, run the [create_plugin.py](https://github.com/monstermichl/ninja-bear/blob/main/misc/plugins/create_plugin.py) script and select the corresponding plugin type. The script guides you through the required steps and creates a new folder (e.g. ninja-bear-language-examplescript), which contains all necessary files to get started. All files that require some implementation contain the comment **"TODO: Implement"**. The method comments contain information about what to implement. To install and test the plugin, scripts can be found in the *helpers* directory.

## Example list of available plugins
A short list of available plugins for ninja-bear. There are probably more. For a better overview please refer to [pypi.org](https://pypi.org/search/?q=%22ninja-bear-*%22).

### Languages
- [ninja-bear-language-c](https://pypi.org/project/ninja-bear-language-c/)
- [ninja-bear-language-go](https://pypi.org/project/ninja-bear-language-go/)
- [ninja-bear-language-java](https://pypi.org/project/ninja-bear-language-java/)
- [ninja-bear-language-javascript](https://pypi.org/project/ninja-bear-language-javascript/)
- [ninja-bear-language-python](https://pypi.org/project/ninja-bear-language-python/)
- [ninja-bear-language-shell](https://pypi.org/project/ninja-bear-language-shell/)
- [ninja-bear-language-typescript](https://pypi.org/project/ninja-bear-language-typescript/)

### Distributors
- [ninja-bear-language-fs](https://pypi.org/project/ninja-bear-distributor-fs/)
- [ninja-bear-language-git](https://pypi.org/project/ninja-bear-distributor-git/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/monstermichl/ninja-bear.git",
    "name": "ninja-bear",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "ninja-bear, constants, language, generator, distributor",
    "author": "monstermichl",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/9d/7e/2cda82939216b7cfe246bd04fcefd0a1a016a321e6f831ef348853615d1a/ninja_bear-0.1.4.tar.gz",
    "platform": null,
    "description": "# ninja-bear \ud83e\udd77\ud83d\udc3b\nIn times of distributed systems and en vogue micro-architecture it can get quite cumbersome to keep constants that are required by several components up-to-date and in sync. It can get especially hard when these components or services are written in different languages. ninja-bear targets this issue by using a language neutral YAML configuration that lets you generate language specific constant-files.\n\n## Concept\nninja-bear uses a plugin-based approach in which each language and distributor is an independend Python module. This gives developers a high amount of flexibility by letting them define and publish their own languages and distributors without the need to modify ninja-bear directly.\n\n## Installation\n```bash\npip install ninja-bear\n```\n\n## Example\nLets have a look at a simple example to see what *ninja-bear* can do for you.\n\nThe example YAML file contains a property named *greeting* with the value \"Hello World\". Constant-files shall be generated for [TypeScript](https://pypi.org/project/ninja-bear-language-typescript/), [Python](https://pypi.org/project/ninja-bear-language-python/) and [C](https://pypi.org/project/ninja-bear-language-c/) (using the corresponding plugins). In case of *C*, the value shall be changed to *\"Hello Mars\"* and the file shall be distributed to Git using the [ninja-bear-distributor-git](https://pypi.org/project/ninja-bear-distributor-git/) plugin.\n\nFor detailed configuration information, please check [test-config.yaml](https://github.com/monstermichl/ninja-bear/blob/main/example/test-config.yaml). All possible values are described there.\n\n### Input (readme-config.yaml)\n```yaml\n# -----------------------------------------------------------------------------\n# This section defines languages and properties which are usually the settings\n# that you'll use the most.\n# -----------------------------------------------------------------------------\nlanguages:\n  - language: typescript\n    property_naming: screaming-snake\n    export: esm\n\n  - language: python\n    file_naming: snake\n    property_naming: screaming-snake\n\n  - language: c\n    file_naming: snake\n    property_naming: pascal\n\n    transformers:\n      - mars-transformer\n\n    distributors:\n      - git-distributor\n\nproperties:\n  - type: string\n    name: greeting\n    value: Hello World\n\n# -----------------------------------------------------------------------------\n# This sections defines the available transformers and distributors. They are\n# are used if property values need to be transformed before they get written\n# or if specific language constants shall be distributed. To use a transformer\n# and/or a distributor, its alias needs to be used in the language section\n# (refer to c-example).\n# -----------------------------------------------------------------------------\ntransformers:\n  - transformer: |\n      value = 'Hello Mars'\n    as: mars-transformer\n\ndistributors:\n  - distributor: git\n    as: git-distributor\n```\n\n### Execute ninja-bear\n```bash\n# -d is used to distribute the C-file to Git.\nninja-bear -c readme-config.yaml -d\n```\n\n### Output (readme-config.ts)\n```typescript\nexport const ReadmeConfig = {\n    GREETING: 'Hello World',\n} as const;\n```\n\n### Output (readme_config.py)\n```python\nfrom dataclasses import dataclass\n\n@dataclass(frozen=True)\nclass ReadmeConfig:\n    GREETING = 'Hello World'\n```\n\n### Output (readme_config.h)\n```c\n#ifndef README_CONFIG_H\n#define README_CONFIG_H\n\nconst struct {\n    char Greeting[11];\n} ReadmeConfig = {\n    \"Hello Mars\",\n};\n\n#endif /* README_CONFIG_H */\n```\n\n## Usage\n### Commandline\n```bash\nninja-bear -c test-config.yaml -o generated\n```\n\n### Script\n```python\nfrom ninja_bear import Orchestrator\n\n# Create Orchestrator instance from file.\norchestrator = Orchestrator.read_config('test-config.yaml')\n\n# Write constants to 'generated' directory.\norchestrator.write('generated')\n\n# Distribute constants (if required).\norchestrator.distribute()\n```\n\n## Create a plugin\nTo create a new plugin, clone the repository, run the [create_plugin.py](https://github.com/monstermichl/ninja-bear/blob/main/misc/plugins/create_plugin.py) script and select the corresponding plugin type. The script guides you through the required steps and creates a new folder (e.g. ninja-bear-language-examplescript), which contains all necessary files to get started. All files that require some implementation contain the comment **\"TODO: Implement\"**. The method comments contain information about what to implement. To install and test the plugin, scripts can be found in the *helpers* directory.\n\n## Example list of available plugins\nA short list of available plugins for ninja-bear. There are probably more. For a better overview please refer to [pypi.org](https://pypi.org/search/?q=%22ninja-bear-*%22).\n\n### Languages\n- [ninja-bear-language-c](https://pypi.org/project/ninja-bear-language-c/)\n- [ninja-bear-language-go](https://pypi.org/project/ninja-bear-language-go/)\n- [ninja-bear-language-java](https://pypi.org/project/ninja-bear-language-java/)\n- [ninja-bear-language-javascript](https://pypi.org/project/ninja-bear-language-javascript/)\n- [ninja-bear-language-python](https://pypi.org/project/ninja-bear-language-python/)\n- [ninja-bear-language-shell](https://pypi.org/project/ninja-bear-language-shell/)\n- [ninja-bear-language-typescript](https://pypi.org/project/ninja-bear-language-typescript/)\n\n### Distributors\n- [ninja-bear-language-fs](https://pypi.org/project/ninja-bear-distributor-fs/)\n- [ninja-bear-language-git](https://pypi.org/project/ninja-bear-distributor-git/)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "ninja-bear keeps your language specific constants in sync",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/monstermichl/ninja-bear.git"
    },
    "split_keywords": [
        "ninja-bear",
        " constants",
        " language",
        " generator",
        " distributor"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db833ed83dec5c29af467c2108220dae8ecda12e4ac503835fddbf2e2983661b",
                "md5": "c7801764ff1f01aac8465568600a885f",
                "sha256": "ebadb6439c4aedb29ccd314d375068cb8e5e2e4021160c22dc83dab023119793"
            },
            "downloads": -1,
            "filename": "ninja_bear-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c7801764ff1f01aac8465568600a885f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 31125,
            "upload_time": "2024-11-04T15:16:50",
            "upload_time_iso_8601": "2024-11-04T15:16:50.890373Z",
            "url": "https://files.pythonhosted.org/packages/db/83/3ed83dec5c29af467c2108220dae8ecda12e4ac503835fddbf2e2983661b/ninja_bear-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d7e2cda82939216b7cfe246bd04fcefd0a1a016a321e6f831ef348853615d1a",
                "md5": "967f54075b4b410929f19fc8f4a1bee1",
                "sha256": "2ae1561729140d755409e7e54a3ef5bf2d42bb5511ee10b7c4d15a67329ab122"
            },
            "downloads": -1,
            "filename": "ninja_bear-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "967f54075b4b410929f19fc8f4a1bee1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 26937,
            "upload_time": "2024-11-04T15:16:52",
            "upload_time_iso_8601": "2024-11-04T15:16:52.489548Z",
            "url": "https://files.pythonhosted.org/packages/9d/7e/2cda82939216b7cfe246bd04fcefd0a1a016a321e6f831ef348853615d1a/ninja_bear-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-04 15:16:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "monstermichl",
    "github_project": "ninja-bear",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "ninja-bear"
}
        
Elapsed time: 0.85450s