Nomen 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))
pip install nomen
It is easy to write subtle bugs with YAML parsing a boolean incorrectly. c.f. problems with YAML. TODO: switch load
to safe_load
. Consider switching to StrictYAML.
# create a symbolic link to the package for testing
pip install -e .
# run all the tests
pytest
# 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
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.
Pull requests and issues welcome. Please help
- How to design global options? In yaml?