From 45c4aba11e70d4be7f3f67204e0016fedd2b4974 Mon Sep 17 00:00:00 2001 From: Nathaniel Waisbrot Date: Sat, 8 Aug 2020 23:55:07 -0400 Subject: [PATCH] trying to get the package to produce a script; also change to markdown README --- README.md | 30 ++++++++++++++++++++++++++++++ README.rst | 34 ---------------------------------- pyproject.toml | 6 +++--- yaml2jsonnet/__main__.py | 14 ++------------ yaml2jsonnet/cli.py | 11 +++++++++++ 5 files changed, 46 insertions(+), 49 deletions(-) create mode 100644 README.md delete mode 100644 README.rst diff --git a/README.md b/README.md new file mode 100644 index 0000000..c933157 --- /dev/null +++ b/README.md @@ -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/ diff --git a/README.rst b/README.rst deleted file mode 100644 index e5bf04f..0000000 --- a/README.rst +++ /dev/null @@ -1,34 +0,0 @@ -================= -yaml2jsonnet -================= - - -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. - -The goal of this project is to make the conversion a little easier: transform the YAML into *slightly* prettier Jsonnet, preserving -comments along the way. - - ------------------- -Development Setup ------------------- - - -* 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/ diff --git a/pyproject.toml b/pyproject.toml index a45d142..52ee061 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] -readme = "README.rst" +readme = "README.md" repository = "https://github.com/waisbrot/yaml2jsonnet" classifiers = [ "Development Status :: 4 - Beta", @@ -17,7 +17,7 @@ classifiers = [ ] [tool.poetry.scripts] -yaml2jsonnet = 'yaml2jsonnet' +yaml2jsonnet = 'yaml2jsonnet.cli:main' [tool.poetry.dependencies] python = "^3.8" diff --git a/yaml2jsonnet/__main__.py b/yaml2jsonnet/__main__.py index d2b362d..ac5716f 100644 --- a/yaml2jsonnet/__main__.py +++ b/yaml2jsonnet/__main__.py @@ -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() diff --git a/yaml2jsonnet/cli.py b/yaml2jsonnet/cli.py index 58e7396..554a44b 100644 --- a/yaml2jsonnet/cli.py +++ b/yaml2jsonnet/cli.py @@ -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)