Skip to main content

YAML parser that environment variable is expanded

Project description

TravisCI Status CircleCI Status Requirements Status

Install

$ pip install syaml

How to use it

A syaml is YAML parser that environment variable is expanded. It can use the path, name, here and environment variable in YAML file. It described in syntax of mako template. See http://www.makotemplates.org/ .

A path is absolute path to YAML file, and name is file name of YAML file, and here is absolute directory path the YAML file stored.

For example.

/path/to/test.yaml:

- ${here}
- ${name}
- ${path}

The above file is equivalent to the following a file.

- /path/to/
- test.yaml
- /path/to/test.yaml

And, it can use environment variable in YAML file too.

/path/to/test.yaml:

- email: ${EMAIL}

If test@example.com the environment variable EMAIL is set, the above file is equivalent to the following a file.

- email: test@example.com

Load file and Load string

Example file /path/to/syaml/example.yml:

general:
  - ${here}
  - ${name}
  - ${path}

Load file object:

>>> import syaml
>>> with open('example.yml', 'rb') as fp:
...     syaml.load(fp)
...
{'general': ['/path/to/syaml', 'example.yml', '/path/to/syaml/example.yml']}

Load byte string object:

>>> syaml.loads(b'general:\n  - ${here}\n  - ${name}\n  - ${path}\n')
{'general': ['', '', '']}

Load string object:

>>> syaml.loads('general:\n  - ${here}\n  - ${name}\n  - ${path}\n')
{'general': ['', '', '']}
>>>

name and path and here will replace to empty string If you passed a string to syaml.loads function. They are for a file object. A string like object don’t have file path.

Use command line tool

syaml render

It render the SAYML file.

example.yml:

general:
  - ${here}
  - ${name}
  - ${path}

Execute syaml render command:

$ syaml render example.yml
general:
- /path/to/syaml
- example.yml
- /path/to/syaml/example.yml

Execute syaml render command json style:

$ syaml render example.yml --json
{"general": ["/path/to/syaml", "example.yml", "/path/to/syaml/example.yml"]}

Execute syaml render command pre process only:

$ syaml render example.yml --pre
general:
  - /path/to/syaml
  - example.yml
  - /path/to/syaml/example.yml

Unittest

This section describes the tools and tips used when unittest. Run these tests with the following command:

$ python -m unittest discover src

If all tests pass, you will see the following output:

....
----------------------------------------------------------------------
Ran 4 tests in 0.018s

OK

The number of tests performed may be higher than described in this document.

Release flow

1. Bump version. Edit src/syaml/__init__.py file. 1. Generate distribution files. python setup.py bdist_wheel sdist. 1. Check distribution files. twine check dist/*.

  • You need to make sure there are no “errors” displayed on the console.
  1. Upload distribution files. twine upload dist/*.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for syaml, version 1.3
Filename, size File type Python version Upload date Hashes
Filename, size syaml-1.3-py3-none-any.whl (11.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size syaml-1.3.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page