Kyushi / yconpy

YConPy - Yaml Config to Python: Generate a Python config file from a yaml config file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YConPy - Yaml config to Python

Requirements

Python 3.6

About

Pronunciation: [why-con-pie]

When working with a yaml config file, I was annoyed that I could not use auto completion in my favourite Pyton IDE, so I decided to read the config into a Python file with a class for each set of keys. Since having to add the keys in both the yaml file and in the python file is tiresome and error-prone, I came up with YConPy. This reads all keys and values from the yaml file and writes a python file with classes that reflect the yaml faithfully.

Example:

A file myconfig.yaml :

Data:
  data_dir: 'data'

  Files:
    filename: 'file.csv'

returns `myconfig.py`:

class Data:
    data_dir = 'data'
    class Files:
        filename = 'file.csv'

so that you can use this as

import myconfig
myconfig.Data.Files.filename

in your code.

The script does this by reading the yaml file using the standard yaml module, generating a string from it and writing that to a .py file.

Usage

Download

git clone https:github.com/Kyushi/yconpy.git

Install

pip install .

Run

python -m yconpy [yaml] [root]

Use the following command line arguments (if applicable):

Arg Help Notes
yaml Path to yaml file Yaml dir and filename will be used as output file name and dir
root Path to root directory of your project (For future use of adding absolute paths)(optional)
name Name of Base class Base class, of which all config elements are a subclass (optional)

About

YConPy - Yaml Config to Python: Generate a Python config file from a yaml config file

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 100.0%