Skip to content
/ nomen Public

🐐 Lightweight configuration trees with command line flags 🐐

License

Notifications You must be signed in to change notification settings

jaanli/nomen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nomen

Build Status

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))

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. 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?