Skip to content

Commit 45c4aba

Browse files
committed
trying to get the package to produce a script; also change to markdown README
1 parent e2aba3d commit 45c4aba

File tree

5 files changed

+46
-49
lines changed

5 files changed

+46
-49
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# YAML2Jsonnet: Switch configuration languages
2+
3+
Converts YAML into Jsonnet (specifically targetting YAML for Kubernetes)
4+
5+
Suppose that you have some [YAML][] that you use for [Kubernetes][] (either hand-written or output by [Helm][]. Now you'd like to use
6+
[Jsonnet][] instead, for its fancier templating capabilities. This is a pain, because while YAML->JSON converters are easy to find,
7+
they produce ugly-looking (but valid!) Jsonnet.
8+
9+
YAML2Jsonnet makes the conversion a little easier: it transforms the YAML into *slightly* prettier Jsonnet, preserving
10+
comments along the way.
11+
12+
## Examples
13+
14+
TODO
15+
16+
## Development
17+
18+
* Install [Poetry]
19+
* Install [Pre-commit]
20+
* Run `poetry install` to install dependencies
21+
* Run `poetry run python -m yaml2jsonnet /path/to/yaml` to convert a file
22+
* Probably, run `jsonnetfmt` on the output, since the only whitespace I provide is newlines
23+
24+
25+
[YAML]: https://yaml.org/
26+
[Helm]: https://helm.sh/
27+
[Jsonnet]: https://jsonnet.org/
28+
[Kubernetes]: https://kubernetes.io/
29+
[Poetry]: https://python-poetry.org/
30+
[Pre-commit]: https://pre-commit.com/

README.rst

Lines changed: 0 additions & 34 deletions
This file was deleted.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[tool.poetry]
22
name = "yaml2jsonnet"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
description = "Convert from YAML to Jsonnet format, retaining comments"
55
license = "AGPL-3.0-or-later"
66
authors = ["Nathaniel Waisbrot <code@waisbrot.net>"]
7-
readme = "README.rst"
7+
readme = "README.md"
88
repository = "https://github.com/waisbrot/yaml2jsonnet"
99
classifiers = [
1010
"Development Status :: 4 - Beta",
@@ -17,7 +17,7 @@ classifiers = [
1717
]
1818

1919
[tool.poetry.scripts]
20-
yaml2jsonnet = 'yaml2jsonnet'
20+
yaml2jsonnet = 'yaml2jsonnet.cli:main'
2121

2222
[tool.poetry.dependencies]
2323
python = "^3.8"

yaml2jsonnet/__main__.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
import logging
1+
from yaml2jsonnet.cli import main
22

3-
from yaml2jsonnet.cli import parse_args, run
4-
5-
if __name__ == "__main__":
6-
args = parse_args()
7-
loglevel = logging.WARNING
8-
if args.v > 0:
9-
loglevel = logging.INFO
10-
if args.v > 1:
11-
loglevel = logging.DEBUG
12-
logging.basicConfig(level=loglevel)
13-
run(args)
3+
main()

yaml2jsonnet/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@ def run(args: argparse.Namespace) -> None:
2626
log.debug("Read yaml into memory")
2727
yaml_data = args.yaml.read()
2828
convert_yaml(yaml_data, args.out)
29+
30+
31+
def main() -> None:
32+
args = parse_args()
33+
loglevel = logging.WARNING
34+
if args.v > 0:
35+
loglevel = logging.INFO
36+
if args.v > 1:
37+
loglevel = logging.DEBUG
38+
logging.basicConfig(level=loglevel)
39+
run(args)

0 commit comments

Comments
 (0)