Skip to main content

A small resource manager for config files

Project description

This repository contains a grammar for config files, as well as a parser, a registration system and a manager of resources, and is mainly designed for the deep_pipe library.

Grammar overview

Resources definition

Think of resources as constants in a programming language. They are declared using the = symbol.

file_path = "/some/path"
num_folds = 5
kernel_sizes = [3 3 5]
some_dict = {
  "a": "my string"
  "b": ["some" "list" 3]
}

All python literals (strings, numbers) as well as dicts and lists are supported, however the coma (,) symbol is optional.

Comments

Just like in Python, comments begin with # and end with a newline character (with one small exception, see below):

# a comment
x = 1 # a very important constant

Importing stuff

The Python-like import statements are also supported:

from numpy import prod as product
from numpy import sum, random
import pandas as pd
import tqdm
import math.radians

Lazy initialization

Some resources must not be called when you specify their params.

To avoid the resource from being called you ca use the # lazy specifier:

from numpy.random import random

random_triplet = random(
    # lazy
    size=3
)

Now random_triplet is a function with the parameter size set to 3. In Python this is equivalent to the code below:

from numpy.random import random
from functools import partial

random_triplet = partial(random, size=3)

Mixins

The grammar also supports multiple inheritance, realized as mixins. Importing other configs is similar to other import statements: you can use a “starred import” or specify the path to the config. Both relative and absolute paths are allowed.

from .parent import * # importing from the file "parent.config"
import "../relative/path/config_one" "/or/absolute/path/config_two"
from "prefix/folder" import 'more' 'configs'

another_resource = "Important data"

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

resource-manager-0.6.3.tar.gz (14.4 kB view details)

Uploaded Source

File details

Details for the file resource-manager-0.6.3.tar.gz.

File metadata

File hashes

Hashes for resource-manager-0.6.3.tar.gz
Algorithm Hash digest
SHA256 d1bd3494c8629d6090236ff6aaab57c9d0f1beab99875114eb09889ee2db1417
MD5 5243a4afe4ad1db9c68e216f726ef73a
BLAKE2b-256 31845af400c48985873506a79bcb616451c95987ee7873807df6d931c51ebbde

See more details on using hashes here.

Supported by

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