Skip to main content

ninja-bear keeps your language specific constants in sync

Project description

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

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, 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: 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

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

Output (readme-config.ts)

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

Output (readme_config.py)

from dataclasses import dataclass

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

Output (readme_config.h)

#ifndef README_CONFIG_H
#define README_CONFIG_H

const struct {
    char Greeting[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 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 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.

Languages

Distributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ninja_bear-0.1.3.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

ninja_bear-0.1.3-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file ninja_bear-0.1.3.tar.gz.

File metadata

  • Download URL: ninja_bear-0.1.3.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ninja_bear-0.1.3.tar.gz
Algorithm Hash digest
SHA256 62a0d8a56daee1f8abd371802e572a810567b7ba08cb35366ee9ff51f1ce909f
MD5 a5a3e16b86a923cf284f71762b9294f4
BLAKE2b-256 249c2eb7b0ac73586629287c3c30e6fdad1c262b2d001247ca6c41be906475a4

See more details on using hashes here.

File details

Details for the file ninja_bear-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ninja_bear-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 31.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ninja_bear-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 89cd3d585ab8d6a20422a348bcfd782b0ca56332b88e4e7c2b9830e4455f0d16
MD5 7954a1f6f8ea79b699a6aa8a0c08b1d8
BLAKE2b-256 88b5251a4294e279b565ed7888d302808b3e81cba7e49718ce738f99e2c3ec64

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page