Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jaanli/nomen

:goat: Lightweight configuration trees with command line flags :goat:
https://github.com/jaanli/nomen

config configuration dictionary nested nomen python tree yaml

Last synced: 14 days ago
JSON representation

:goat: Lightweight configuration trees with command line flags :goat:

Awesome Lists containing this project

README

        

# nomen
[![Build Status](https://travis-ci.org/altosaar/nomen.svg?branch=master)](https://travis-ci.org/altosaar/nomen)

[Nomen](https://en.wikipedia.org/wiki/Nomen_nudum) or _nomen nudum_ means _naked name_ in taxonomy. The goal of this package is to provide python programs with highly-readable, minimalist configuration and command line flags based on YAML syntax. The main difference compared to the standard argparse library is that a nomen configuration file and and command line flag definition are the same thing. This means defining command line flags is less verbose.

Define a configuration with YAML syntax and any environment variables:

File `main.py`
```
import yaml
import nomen
"""
model:
learning_rate: 0.1
turbo: false
variational:
learning_rate: 0.3

data:
shape: &shape [28, 28, 1]
eval_data:
shape: *shape

log: $LOG ## will be replaced by the $LOG environment variable
"""
cfg = nomen.Config(yaml.safe_load('config.yml'))
cfg.parse_args()
print('Model options', cfg['model'])
print('Model learning rate', cfg.model.learning_rate)
print('Eval options', cfg['eval_data'])
```

Configurations define command line arguments:
```
python main.py \
--model/learning_rate 0.001 \
--log /tmp \
--model/turbo
```

Configurations are portable - save and load using yaml:
```
with open('config.yml', 'w') as f:
f.write(str(cfg))
```

### Install
```
pip install nomen
```

### Reasons for not using
It is easy to write subtle bugs with YAML parsing a boolean incorrectly. c.f. [problems with YAML](https://arp242.net/weblog/yaml_probably_not_so_great_after_all.html). TODO: switch `load` to `safe_load`. Consider switching to StrictYAML.

### Testing
```
# create a symbolic link to the package for testing
pip install -e .
# run all the tests
pytest
```

### Pushing to pypi
```
# build the package, possibly with a new version.py
python setup.py sdist bdist_wheel
# test the built package
pip install -i https://testpypi.python.org/pypi nomen
# upload to pypi
twine upload dist/*
# test again
pip install nomen --no-cache-dir
```

### Acknowledgments
Many thanks to Rajesh - this is based around his advice and ideas, which I've found it very useful. Many props to Bharat for helping subclass addict.Dict in the proper way and providing proper support.

### Contributing
Pull requests and issues welcome. Please help

### Wishlist / todo
* How to design global options? In yaml?
*