yamkix
Why?
Because I like my yaml file to be nicely formatted
Because https://marketplace.visualstudio.com/items?itemName=adamvoss.yaml creates (valid) yaml not compatible for kubernetes (and I mainly edit yaml files for kubernetes)
Because https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml does not add explicit start of documents and I don’t like it this way
Because I’m not a js/typescript dev so I don’t want to go into a VSCode extension with client and server language
What?
> ./yamkix -h
usage: yamkix [-h] -i INPUT [-t TYP] [-o OUTPUT] [-n] [-e] [-q] [-f] [-d]
Format yaml input file. By default, explicit_start is `On`, explicit_end is
`Off` and array elements are pushed inwards the start of the matching
sequence. Comments are preserved thanks to default parsing mode `rt`.
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
the file to parse
-t TYP, --typ TYP the yaml parser mode. Can be `safe` or `rt`
-o OUTPUT, --output OUTPUT
the name of the file to generate (same as input file
if not specied)
-n, --no-explicit-start
by default, explicit start of the yaml doc is `On`,
you can disable it with this option
-e, --explicit-end by default, explicit end of the yaml doc is `Off`, you
can enable it with this option
-q, --no-quotes-preserved
by default, quotes are preserverd you can disable this
with this option
-f, --default-flow-style
enable the default flow style `Off` by default. In
default flow style (with typ=`rt`), maps and lists are
written like json
-d, --no-dash-inwards
by default, dash are pushed inwards use `--no-dash-inwards` to have the dash start at the sequence level
Config
Explicit start of yaml docs by default (you can disable it with --no-explicit-start)
Quotes preserved by default (you can disable it with --no-quotes-preserved)
Arrays elements pushed inwards by default (you can disable it with --no-dash-inwards)
Output file is input file by default
Comments preserved by default thanks to ruamel.yaml round_trip mode (you can disable it with --typ safe)
To preserve or not to preserve quotes?
Quotes preserved means : if there were quotes in the input, they will also be present in the output, and it will be the same type (single/double) of quotes
Quotes not preserved means :
if quotes are not necessary (around pure strings), they will be removed
if quotes are present around booleans and numbers, they will be converted to default (single quotes)
if quotes are not present around booleans and numbers, there will be no quotes in the output too
Note: there is no option for the moment to force the usage of double quotes when -q/–no-quotes-preserved is used.
Quotes preserved (default behavior)
With input :
---
apiVersion: extensions/v1beta1 # with comment
kind: ReplicaSet
metadata:
name: tname
namespace: tns
annotations:
string_no_quotes: frontend
string_single_quotes: 'frontend'
string_double_quotes: "frontend"
boolean_no_quotes: true
boolean_single_quotes: 'true'
boolean_double_quotes: "true"
number_no_quotes: 1
number_single_quotes: '1'
number_double_quotes: "1"
the output will be the same as the input :
---
apiVersion: extensions/v1beta1 # with comment
kind: ReplicaSet
metadata:
name: tname
namespace: tns
annotations:
string_no_quotes: frontend
string_single_quotes: 'frontend'
string_double_quotes: "frontend"
boolean_no_quotes: true
boolean_single_quotes: 'true'
boolean_double_quotes: "true"
number_no_quotes: 1
number_single_quotes: '1'
number_double_quotes: "1"
Quotes not preserved (using -q/–no-quotes-preserved)
With input :
---
apiVersion: extensions/v1beta1 # with comment
kind: ReplicaSet
metadata:
name: tname
namespace: tns
annotations:
string_no_quotes: frontend
string_single_quotes: 'frontend'
string_double_quotes: "frontend"
boolean_no_quotes: true
boolean_single_quotes: 'true'
boolean_double_quotes: "true"
number_no_quotes: 1
number_single_quotes: '1'
number_double_quotes: "1"
the output will be :
---
apiVersion: extensions/v1beta1 # with comment
kind: ReplicaSet
metadata:
name: tname
namespace: tns
annotations:
string_no_quotes: frontend
string_single_quotes: frontend
string_double_quotes: frontend
boolean_no_quotes: true
boolean_single_quotes: 'true'
boolean_double_quotes: 'true'
number_no_quotes: 1
number_single_quotes: '1'
number_double_quotes: '1'
Note : kubesplit is not fully _Kubernetes_ aware for the moment, so it does not try to enforce this behaviour only on string sensible _kubernetes_ resource fields (.metadata.annotations and .spec.containers.environment values)
Where does the name ‘yamkix’ come from?
Thanks to http://online-generator.com/name-generator/product-name-generator.php that suggested me zamkix. Just switched the starting z for the y of yaml
Usage
Install the package with pip install --user yamkix
Sample vscode task :
{
"taskName": "format yaml with yamkix",
"type": "shell",
"command": "yamkix --input ${file}",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
}
Hack
python3 -m virtualenv .venv
source .venv/bin/activate
pip install -r requirements_dev.txt
make all
Acknowledgements
Dependencies scanned by PyUp.io
Metadata
Release files for yamkix 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yamkix-0.7.0.tar.gz | 10.4 kB | Without provenance | Details for yamkix-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yamkix-0.7.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for yamkix-0.7.0-py2.py3-none-any.whl |
Total release size: 24.1 kB
Release files / yamkix-0.7.0.tar.gz
| Download URL | yamkix-0.7.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ca5f3b3b51193202219ee6e20bfc949bc7017d849d4379d8f6a2debc87a97e1
|
|
BLAKE2b-256 checksum How to use checksums |
02fe10f9675f76caf88d50d0009509b24212ffb4054455e43bfd392e224fc907
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.8.2
|
Release files / yamkix-0.7.0-py2.py3-none-any.whl
| Download URL | yamkix-0.7.0-py2.py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e1b7ce8927686afed685e83b73dceadaa4922780281c21755c713ec901d59ed1
|
|
BLAKE2b-256 checksum How to use checksums |
f1d5783709ab9dd867b45fe48f001cde19eddbc3c12dd12a9e2cdac2014a5fc9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.8.2
|
Security for yamkix 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.