Code Monkey home page Code Monkey logo

redpanda-property-extractor's Introduction

Redpanda Property Extractor

CLI tool to extract all properties from the Redpanda's source code and generate a JSON output with their definitions.

Dependencies

  • Python 3
  • A C++ compiler (tested with gcc)

Installation

  1. After cloning the project, initialize and update the C++ tree-sitter submodule:
git submodule init
git submodule update
  1. Install the tree_sitter dependency for Python:
pip install -r requirements.txt

Optionally, you can use venv to avoid installing this dependency globally:

python -m venv /path/to/your/venv
source /path/to/your/vm/bin/activate
pip install -r requirements.txt
  1. You will also need to download Redpanda's source code:
git clone https://github.com/redpanda-data/redpanda.git <dir>

Alternatively, you can run make to generate the file. It will be stored at ./gen/properties-output.json.

Usage

./property_extractor.py [-h] --path PATH [--recursive] [--output OUTPUT] --definitions DEFINITIONS [-v]

options:
  -h, --help            show this help message and exit
  --path PATH           Path to the Redpanda's source dir to extract the properties
  --recursive           Scan the path recursively
  --output OUTPUT       File to store the JSON output. If no file is provided, the JSON will be printed to the standard output
  --definitions DEFINITIONS
                        JSON file with extra type definitions to be used during the output generation
  -v, --verbose

Example usage:

./property_extractor.py --recursive --path /path/to/redpanda --definitions definitions.json --output my-output.json

Transformers

A transformer is an object used to add, remove, or modify the fields of a property. To create a new transformer, you need to create a class with the following methods:

  • accepts(self, info, file_pair) -> bool where:
    • info: Information about the property extracted from the source code. This dictionary contains the following fields:
      • name_in_file: name of the property as declared in the header file
      • declaration: the whole line of the property declaration in the header file. This is useful because it contains the C++ type of the property
      • params: list of the params used in the constructor's initializer list to create the property in the implementation file (in that order):
        • The name of the property
        • The description of the property
        • The metadata object
        • The default value
    • file_pair: object with two properties header and implementation containing the path (as string) of the files that the property being processed belongs to
  • parse(self, property, info, file_pair) -> void where:
    • info and file_pair are the same as in the accepts method
    • property is a dictionary where you can operate to modify the fields in the JSON output

To use your new transformer, add it to the list of enabled transformers. To see the existing transformers, check the transformers.py file.

Definitions

The definitions.json file is merged in the output under the definitions field. Those definitions are used to change the types of the properties in the last stage of the generation. To change the types used in the generation, modify the file or provide another one using the --definitions option.

redpanda-property-extractor's People

Contributors

deflaimun avatar waldson avatar

Watchers

 avatar

Forkers

deflaimun

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.