Skip to content

Commit

Permalink
trying to get the package to produce a script; also change to markdow…
Browse files Browse the repository at this point in the history
…n README
  • Loading branch information
waisbrot committed Aug 9, 2020
1 parent e2aba3d commit 45c4aba
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 49 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# YAML2Jsonnet: Switch configuration languages

Converts YAML into Jsonnet (specifically targetting YAML for Kubernetes)

Suppose that you have some [YAML][] that you use for [Kubernetes][] (either hand-written or output by [Helm][]. Now you'd like to use
[Jsonnet][] instead, for its fancier templating capabilities. This is a pain, because while YAML->JSON converters are easy to find,
they produce ugly-looking (but valid!) Jsonnet.

YAML2Jsonnet makes the conversion a little easier: it transforms the YAML into *slightly* prettier Jsonnet, preserving
comments along the way.

## Examples

TODO

## Development

* Install [Poetry]
* Install [Pre-commit]
* Run `poetry install` to install dependencies
* Run `poetry run python -m yaml2jsonnet /path/to/yaml` to convert a file
* Probably, run `jsonnetfmt` on the output, since the only whitespace I provide is newlines


[YAML]: https://yaml.org/
[Helm]: https://helm.sh/
[Jsonnet]: https://jsonnet.org/
[Kubernetes]: https://kubernetes.io/
[Poetry]: https://python-poetry.org/
[Pre-commit]: https://pre-commit.com/
34 changes: 0 additions & 34 deletions README.rst

This file was deleted.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tool.poetry]
name = "yaml2jsonnet"
version = "0.6.0"
version = "0.7.0"
description = "Convert from YAML to Jsonnet format, retaining comments"
license = "AGPL-3.0-or-later"
authors = ["Nathaniel Waisbrot <[email protected]>"]
readme = "README.rst"
readme = "README.md"
repository = "https://github.com/waisbrot/yaml2jsonnet"
classifiers = [
"Development Status :: 4 - Beta",
Expand All @@ -17,7 +17,7 @@ classifiers = [
]

[tool.poetry.scripts]
yaml2jsonnet = 'yaml2jsonnet'
yaml2jsonnet = 'yaml2jsonnet.cli:main'

[tool.poetry.dependencies]
python = "^3.8"
Expand Down
14 changes: 2 additions & 12 deletions yaml2jsonnet/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import logging
from yaml2jsonnet.cli import main

from yaml2jsonnet.cli import parse_args, run

if __name__ == "__main__":
args = parse_args()
loglevel = logging.WARNING
if args.v > 0:
loglevel = logging.INFO
if args.v > 1:
loglevel = logging.DEBUG
logging.basicConfig(level=loglevel)
run(args)
main()
11 changes: 11 additions & 0 deletions yaml2jsonnet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ def run(args: argparse.Namespace) -> None:
log.debug("Read yaml into memory")
yaml_data = args.yaml.read()
convert_yaml(yaml_data, args.out)


def main() -> None:
args = parse_args()
loglevel = logging.WARNING
if args.v > 0:
loglevel = logging.INFO
if args.v > 1:
loglevel = logging.DEBUG
logging.basicConfig(level=loglevel)
run(args)

0 comments on commit 45c4aba

Please sign in to comment.