Skip to main content

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 config 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

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". Config files shall be generated for TypeScript, Python and 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 plugin.

For detailed configuration information, please check test-config.yaml. All possible values are described there.

Input (readme-config.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: opener
    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 configs 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

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

Output (readme-config.ts)

export const ReadmeConfig = {
    OPENER: 'Hello World',
} as const;

Output (readme_config.py)

from dataclasses import dataclass

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

Output (readme_config.h)

#ifndef README_CONFIG_H
#define README_CONFIG_H

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

#endif /* README_CONFIG_H */

Usage

Commandline

ninja-bear -c test-config.yaml -o generated

Script

from ninja_bear import Orchestrator

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

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

# Distribute configs (if required).
orchestrator.distribute()

Create a plugin

To create a new plugin, clone the repository, run the 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.

Metadata

Release files for ninja-bear 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ninja-bear 0.1.0
File Size Uploaded Provenance Actions
ninja_bear-0.1.0.tar.gz 26.5 kB Without provenance Details for ninja_bear-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ninja-bear 0.1.0
File Interpreter ABI Platform Actions
ninja_bear-0.1.0-py3-none-any.whl Python 3 none any Details for ninja_bear-0.1.0-py3-none-any.whl

Total release size: 57.2 kB

Release files / ninja_bear-0.1.0.tar.gz

Download URL ninja_bear-0.1.0.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2320431d77405578cb2d5485801cbb8c8e20b3ed3bb3dd7afcd101a66adb5776
BLAKE2b-256 checksum
How to use checksums
0d8d8a75f68b8e93a46bdf4f51351315be67df079d84081b53a93a14dd71f825
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / ninja_bear-0.1.0-py3-none-any.whl

Download URL ninja_bear-0.1.0-py3-none-any.whl
Size 30.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f337773a4431460b36b731aa74601c65fa3906a39520442fba57d37e744d5868
BLAKE2b-256 checksum
How to use checksums
547d803f518eff68cafee4fc8f8c02d5232330b517201532ed1c1f24d050cc42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Security for ninja-bear 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page