Skip to content

pylover/snam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

snam

Still Not A Markup!

PyPI Build Coverage Status Documentation Downloads Downloads Downloads

Another YAML parser and builder featured by:

  • Include other files.
  • Expand environment varibales.
  • Execute and use the shell commands standard output.
  • Merge/Melt mappings.

Install

pip install snam

quickstart

from snam import loads

yamldoc = '''
foo:
  enabled: true
  title: BAR
  rate: .73
  user: !env USER
  greeting: !shell echo Hello

fruites:
  - cherry
  - melon
  - banana
  - pineapple
'''

obj = loads(ymldoc)
assert obj.foo.enabled
assert obj.title == 'BAR'
assert obj.rate == 0.73
assert obj.fruites == ['cherry', 'melon', 'banana', 'pineapple']

Tutorial

Parsing

You may user loads(str) function to parse YAML string, and load(file) to parse file-like object or filename. these functions return a snam.Meld object. The Meld object is subclass of the Python's dictionary but in addtion you can access the members by getattr, setattr and delattr operations.

meld = loads('foo: bar')
assert meld.foo == 'bar'
meld = load('foo.yml')
with open('foo.yml') as file:
  meld = load(file)

Merging/Melting

Using the |= operator you may merge any other dictionary or YAML-string into a Meld.

meld |= '''
  foo: bar
  baz: 23
'''

And also using the <<= you may load a file-like object or a filename into a Meld object.

meld <<= 'foo.yml'
with open('foo.yml') as file:
  meld <<= file

Dump

Use snam.dumps(obj) -> str, snam.dump(obj, file) and also meld >>= filename.

dumps(meld, indent=6, indentsize=2)
dump(meld, 'foo.yml', indent=6, indentsize=2)

with open('foo.yml', 'w') as file:
  dump(meld, file, indent=6, indentsize=2)
meld >>= 'foo.yml'
with open('foo.yml', 'w') as file:
  meld >>= file

Contribution

Dependencies

Install python-makelib.

Virtualenv

Create virtual environment:

make venv

Delete virtual environment:

make venv-delete

Activate the virtual environment:

source ./activate.sh

Install (editable mode)

Install this project as editable mode and all other development dependencies:

make env

Tests

Execute all tests:

make test

Execute specific test(s) using wildcard:

make test F=tests/test_db*
make test F=tests/test_form.py::test_querystringform

refer to pytest documentation for more info about invoking tests.

Execute tests and report coverage result:

make cover
make cover F=tests/test_static.py
make cover-html

Lint

make lint

Distribution

Execute these commands to create Python's standard distribution packages at dist directory:

make sdist
make wheel

Clean build directory

Execute:

make clean

to clean-up previous dist/* and build/* directories.

PyPI

WARNING: Do not do this if you'r not responsible as author and or maintainer of this project.

Execute

make clean
make pypi

to upload sdists and wheel packages on PyPI.

Documentation

source activate.sh
make doc
make doclive
make doctest

Or

source activate.sh
cd sphinx
make doctest
make html
make livehtml

About

Still Not A Markup! Simple yaml-like parser and builder with include, shell and environment var support.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors