jinjasubst 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nadav Tasher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: jinjasubst
3
+ Version: 0.1.0
4
+ Summary: Render stdin as Jinja2 template using environment variables
5
+ Maintainer-email: Nadav Tasher <hey@nadav.app>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/NadavTasher/jinjasubst
8
+ Keywords: jinja2,envsubst,templates
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: jinja2
15
+ Dynamic: license-file
16
+
17
+ # jinjasubst
18
+
19
+ ## What does it do?
20
+
21
+ Renders the stdin as a Jinja2 template, with the current environment variables as arguments.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install jinjasubst
27
+ ```
28
+
29
+ or:
30
+
31
+ ```bash
32
+ pipx install jinjasubst
33
+ ```
34
+
35
+ ## Usage examples
36
+
37
+ ```bash
38
+ # Format a template file
39
+ jinjasubst < kubernetes.yml | kubectl apply -f -
40
+
41
+ # Format from file path
42
+ jinjasubst -i kubernetes.yml -o rendered.yml
43
+
44
+ # Using shortened versions
45
+ jsubst -i kubernetes.yml > rendered.yml
46
+ jenvsubst -i kubernetes.yml > rendered.yml
47
+ j2subst -i kubernetes.yml > rendered.yml
48
+ j2envsubst -i kubernetes.yml > rendered.yml
49
+
50
+ # Using the shell global
51
+ jinjasubst -s <<'EOF'
52
+ Hello {{ USER }}, the date is {{ shell("date") }}
53
+ EOF
54
+
55
+ # Using the shell filter
56
+ jinjasubst -s <<'EOF'
57
+ Hello {{ USER }}, your reversed name is {{ USER | shell("rev") }}
58
+ EOF
59
+ ```
60
+
61
+ ### Usage in development
62
+
63
+ ```bash
64
+ python3 -m src.jinjasubst.cli -s <<'EOF'
65
+ Hello {{ USER }}, it is {{ shell("date") }}
66
+ EOF
67
+ ```
@@ -0,0 +1,51 @@
1
+ # jinjasubst
2
+
3
+ ## What does it do?
4
+
5
+ Renders the stdin as a Jinja2 template, with the current environment variables as arguments.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install jinjasubst
11
+ ```
12
+
13
+ or:
14
+
15
+ ```bash
16
+ pipx install jinjasubst
17
+ ```
18
+
19
+ ## Usage examples
20
+
21
+ ```bash
22
+ # Format a template file
23
+ jinjasubst < kubernetes.yml | kubectl apply -f -
24
+
25
+ # Format from file path
26
+ jinjasubst -i kubernetes.yml -o rendered.yml
27
+
28
+ # Using shortened versions
29
+ jsubst -i kubernetes.yml > rendered.yml
30
+ jenvsubst -i kubernetes.yml > rendered.yml
31
+ j2subst -i kubernetes.yml > rendered.yml
32
+ j2envsubst -i kubernetes.yml > rendered.yml
33
+
34
+ # Using the shell global
35
+ jinjasubst -s <<'EOF'
36
+ Hello {{ USER }}, the date is {{ shell("date") }}
37
+ EOF
38
+
39
+ # Using the shell filter
40
+ jinjasubst -s <<'EOF'
41
+ Hello {{ USER }}, your reversed name is {{ USER | shell("rev") }}
42
+ EOF
43
+ ```
44
+
45
+ ### Usage in development
46
+
47
+ ```bash
48
+ python3 -m src.jinjasubst.cli -s <<'EOF'
49
+ Hello {{ USER }}, it is {{ shell("date") }}
50
+ EOF
51
+ ```
@@ -0,0 +1,39 @@
1
+ [project]
2
+ name = "jinjasubst"
3
+ version = "0.1.0"
4
+ requires-python = ">= 3.8"
5
+ description = "Render stdin as Jinja2 template using environment variables"
6
+ readme = "README.md"
7
+ license = "MIT"
8
+ maintainers = [{name = "Nadav Tasher", email = "hey@nadav.app"}]
9
+ classifiers = [
10
+ "Programming Language :: Python",
11
+ "Programming Language :: Python :: 3",
12
+ ]
13
+ dependencies = [
14
+ "jinja2",
15
+ ]
16
+ keywords = ["jinja2", "envsubst", "templates"]
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/NadavTasher/jinjasubst"
20
+
21
+ [project.scripts]
22
+ jsubst = "jinjasubst.cli:main"
23
+ jenvsubst = "jinjasubst.cli:main"
24
+ jinjasubst = "jinjasubst.cli:main"
25
+ j2subst = "jinjasubst.cli:main"
26
+ j2envsubst = "jinjasubst.cli:main"
27
+ jinja2subst = "jinjasubst.cli:main"
28
+
29
+ [build-system]
30
+ requires = ["setuptools>=61.0"]
31
+ build-backend = "setuptools.build_meta"
32
+
33
+ [tool.distutils.bdist_wheel]
34
+ universal = false
35
+
36
+ [tool.yapf]
37
+ based_on_style = "google"
38
+ column_limit = 400
39
+ indent_width = 4
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,109 @@
1
+ import os
2
+ import sys
3
+ import json
4
+ import shlex
5
+ import argparse
6
+ import traceback
7
+ import subprocess
8
+
9
+ # For template rendering
10
+ import jinja2
11
+
12
+
13
+ def exec(value: str, check: bool = False):
14
+ # Run value as a shell command and capture the output
15
+ process = subprocess.run(value, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, check=check)
16
+
17
+ # Return the process output
18
+ return process.stdout
19
+
20
+
21
+ def exec_check(value: str):
22
+ return exec(value, check=True)
23
+
24
+
25
+ def shell(value: str, command: str, check: bool = False):
26
+ # Run command with value as input and capture the output
27
+ process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, input=value, check=check)
28
+
29
+ # Return the process output
30
+ return process.stdout
31
+
32
+
33
+ def shell_check(value: str, command: str):
34
+ return shell(value, command, check=True)
35
+
36
+
37
+ def parse_arguments():
38
+ # Create argument parser
39
+ parser = argparse.ArgumentParser()
40
+
41
+ # Enable shell filter
42
+ parser.add_argument("-s", "--shell", action="store_true", help="Enable shell() filter")
43
+
44
+ # Input filename
45
+ parser.add_argument("-i", "--input", action="store", default="-", help="Input file path")
46
+
47
+ # Output filename
48
+ parser.add_argument("-o", "--output", action="store", default="-", help="Output file path")
49
+
50
+ # Parse the arguments
51
+ return parser.parse_args()
52
+
53
+
54
+ def main():
55
+ # Parse the arguments
56
+ arguments = parse_arguments()
57
+
58
+ # Create jinja2 environment
59
+ environment = jinja2.Environment(
60
+ autoescape=False,
61
+ keep_trailing_newline=True,
62
+ )
63
+
64
+ # Add the json dumps filter
65
+ environment.filters.update(json=json.dumps)
66
+
67
+ # Add the shlex quote filter
68
+ environment.filters.update(shlex=shlex.quote)
69
+
70
+ # If shell filter is enabled, add it
71
+ if arguments.shell:
72
+ # When executing a shell without a filter, shell -> exec
73
+ environment.globals.update(shell=exec, shell_check=exec_check)
74
+
75
+ # When executing a shell with a filter, shell -> shell, and takes input
76
+ environment.filters.update(shell=shell, shell_check=shell_check)
77
+
78
+ try:
79
+ # Load the input template
80
+ if arguments.input == "-":
81
+ # Load template from stdin
82
+ template = environment.from_string(sys.stdin.read())
83
+ else:
84
+ # Load template from file
85
+ with open(arguments.input, "r", encoding="utf-8") as file:
86
+ template = environment.from_string(file.read())
87
+
88
+ # Render the template
89
+ template = template.render(os.environ)
90
+
91
+ # Write the rendered template to the output
92
+ if arguments.output == "-":
93
+ # Write to stdout
94
+ sys.stdout.write(template)
95
+ else:
96
+ # Write to file
97
+ with open(arguments.output, "w", encoding="utf-8") as file:
98
+ file.write(template)
99
+ except:
100
+ # Write error to stderr
101
+ sys.stderr.write(traceback.format_exc())
102
+
103
+ # Exit with error code
104
+ sys.exit(1)
105
+
106
+
107
+ if __name__ == "__main__":
108
+ # Just call the main function
109
+ main()
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: jinjasubst
3
+ Version: 0.1.0
4
+ Summary: Render stdin as Jinja2 template using environment variables
5
+ Maintainer-email: Nadav Tasher <hey@nadav.app>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/NadavTasher/jinjasubst
8
+ Keywords: jinja2,envsubst,templates
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: jinja2
15
+ Dynamic: license-file
16
+
17
+ # jinjasubst
18
+
19
+ ## What does it do?
20
+
21
+ Renders the stdin as a Jinja2 template, with the current environment variables as arguments.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install jinjasubst
27
+ ```
28
+
29
+ or:
30
+
31
+ ```bash
32
+ pipx install jinjasubst
33
+ ```
34
+
35
+ ## Usage examples
36
+
37
+ ```bash
38
+ # Format a template file
39
+ jinjasubst < kubernetes.yml | kubectl apply -f -
40
+
41
+ # Format from file path
42
+ jinjasubst -i kubernetes.yml -o rendered.yml
43
+
44
+ # Using shortened versions
45
+ jsubst -i kubernetes.yml > rendered.yml
46
+ jenvsubst -i kubernetes.yml > rendered.yml
47
+ j2subst -i kubernetes.yml > rendered.yml
48
+ j2envsubst -i kubernetes.yml > rendered.yml
49
+
50
+ # Using the shell global
51
+ jinjasubst -s <<'EOF'
52
+ Hello {{ USER }}, the date is {{ shell("date") }}
53
+ EOF
54
+
55
+ # Using the shell filter
56
+ jinjasubst -s <<'EOF'
57
+ Hello {{ USER }}, your reversed name is {{ USER | shell("rev") }}
58
+ EOF
59
+ ```
60
+
61
+ ### Usage in development
62
+
63
+ ```bash
64
+ python3 -m src.jinjasubst.cli -s <<'EOF'
65
+ Hello {{ USER }}, it is {{ shell("date") }}
66
+ EOF
67
+ ```
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/jinjasubst/cli.py
5
+ src/jinjasubst.egg-info/PKG-INFO
6
+ src/jinjasubst.egg-info/SOURCES.txt
7
+ src/jinjasubst.egg-info/dependency_links.txt
8
+ src/jinjasubst.egg-info/entry_points.txt
9
+ src/jinjasubst.egg-info/requires.txt
10
+ src/jinjasubst.egg-info/top_level.txt
@@ -0,0 +1,7 @@
1
+ [console_scripts]
2
+ j2envsubst = jinjasubst.cli:main
3
+ j2subst = jinjasubst.cli:main
4
+ jenvsubst = jinjasubst.cli:main
5
+ jinja2subst = jinjasubst.cli:main
6
+ jinjasubst = jinjasubst.cli:main
7
+ jsubst = jinjasubst.cli:main
@@ -0,0 +1 @@
1
+ jinjasubst