infrablocks.terraform_pkl_type_gen 0.0.1__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) 2025 InfraBlocks
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,21 @@
1
+ MIT License
2
+
3
+ Copyright © 2025 InfraBlocks Maintainers
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,32 @@
1
+ Metadata-Version: 2.1
2
+ Name: infrablocks.terraform_pkl_type_gen
3
+ Version: 0.0.1
4
+ Summary: Provides invoke tasks to interact with terraform
5
+ License: MIT
6
+ Author: Toby Clemson
7
+ Author-email: tobyclemson@gmail.com
8
+ Requires-Python: >=3.13,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Dist: infrablocks-invoke-factory (>=0.0.3a6,<0.0.4)
12
+ Requires-Dist: invoke (>=2.2.0,<3.0.0)
13
+ Requires-Dist: tfparse (>=0.6.16,<0.7.0)
14
+ Description-Content-Type: text/markdown
15
+
16
+ # Terraform Pkl Type Gen
17
+
18
+ A library for creating Pkl types from Terraform variables definitions.
19
+
20
+ ## Development
21
+
22
+ For the best developer experience make sure you have `direnv` and `asdf` installed.
23
+
24
+ Contributing
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/infrablocks/terraform_pkl_type_gen.
26
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
27
+ Contributor Covenant code of conduct.
28
+
29
+ License
30
+ Copyright © 2025 InfraBlocks Maintainers
31
+
32
+ Distributed under the terms of the MIT License.
@@ -0,0 +1,17 @@
1
+ # Terraform Pkl Type Gen
2
+
3
+ A library for creating Pkl types from Terraform variables definitions.
4
+
5
+ ## Development
6
+
7
+ For the best developer experience make sure you have `direnv` and `asdf` installed.
8
+
9
+ Contributing
10
+ Bug reports and pull requests are welcome on GitHub at https://github.com/infrablocks/terraform_pkl_type_gen.
11
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
12
+ Contributor Covenant code of conduct.
13
+
14
+ License
15
+ Copyright © 2025 InfraBlocks Maintainers
16
+
17
+ Distributed under the terms of the MIT License.
@@ -0,0 +1,131 @@
1
+ [project]
2
+ requires-python = ">=3.13,<4.0"
3
+
4
+ [tool.poetry]
5
+ name = "infrablocks.terraform_pkl_type_gen"
6
+ version = "0.0.1"
7
+ description = "Provides invoke tasks to interact with terraform"
8
+ authors = [
9
+ "Toby Clemson <tobyclemson@gmail.com>",
10
+ "Tom Duckering <tom.duckering@gmail.com>",
11
+ ]
12
+ license = "MIT"
13
+ readme = "README.md"
14
+ packages = [
15
+ { include = "infrablocks", from = "src" },
16
+ ]
17
+
18
+ [tool.poetry.dependencies]
19
+ python = ">=3.13,<4.0"
20
+ invoke = "^2.2.0"
21
+ infrablocks-invoke-factory = {version = "^0.0.3a6", allow-prereleases = true}
22
+ tfparse = "^0.6.16"
23
+
24
+ [tool.poetry.group.dev.dependencies]
25
+ coverage = "^7.6.10"
26
+ junitparser = "^3.2.0"
27
+ poethepoet = "^0.33.1"
28
+ pyright = { extras = ["nodejs"], version = "^1.1.391" }
29
+ pytest = "^8.3.4"
30
+ pytest-asyncio = "^0.25.1"
31
+ pytest-cov = "^6.0.0"
32
+ pytest-diff = "^0.1.14"
33
+ pytest-pretty = "^1.2.0"
34
+ pytest-repeat = "^0.9.3"
35
+ pytest-unordered = "^0.6.1"
36
+ ruff = "^0.11.0"
37
+
38
+ [tool.poetry.group.changelog.dependencies]
39
+ scriv = "^1.5.1"
40
+
41
+ [tool.poetry.group.docs.dependencies]
42
+ mkdocs-material = "^9.5.47"
43
+ mkdocstrings = { extras = ["python"], version = "^0.29.0" }
44
+ black = "^25.1.0"
45
+
46
+ [tool.poe.tasks]
47
+ lint-check = "ruff check src tests"
48
+ lint-fix = "ruff check --fix src tests"
49
+ format-check = "ruff format --diff src tests"
50
+ format-fix = "ruff format src tests"
51
+ type-check = "pyright src tests"
52
+ docs-serve = "mkdocs serve"
53
+ docs-build = "mkdocs build"
54
+ changelog-fragment-create = "scriv create"
55
+ changelog-assemble = "scriv collect"
56
+
57
+ [tool.poe.tasks.test-unit]
58
+ args = [{ name = "filter", options = ["--filter"], default = "" }]
59
+ shell = """
60
+ mkdir -p reports/coverage/unit
61
+ pytest -vv tests/unit \
62
+ --junitxml=./reports/unit.junit.xml \
63
+ --cov-report=xml:./reports/coverage/unit/coverage.xml \
64
+ --cov-report=html:./reports/coverage/unit \
65
+ ${filter:+-k ${filter}}
66
+ """
67
+
68
+ [tool.poe.tasks.test-unit.env]
69
+ COVERAGE_FILE = "./reports/coverage/unit/.coverage"
70
+ PYTHONDEVMODE = "1"
71
+
72
+ [tool.poe.tasks.test-report]
73
+ shell = """
74
+ junitparser merge \
75
+ reports/*.junit.xml \
76
+ reports/all.junit.xml
77
+ coverage combine \
78
+ --keep \
79
+ --data-file=./reports/coverage/.coverage \
80
+ reports/coverage/unit/.coverage
81
+ coverage html \
82
+ --data-file=./reports/coverage/.coverage \
83
+ --directory=./reports/coverage/all
84
+ coverage xml \
85
+ --data-file=./reports/coverage/.coverage \
86
+ -o ./reports/coverage/all/coverage.xml
87
+ coverage report \
88
+ --data-file=./reports/coverage/.coverage
89
+ """
90
+
91
+ [tool.pytest.ini_options]
92
+ pythonpath = ["src"]
93
+ asyncio_mode = "auto"
94
+ asyncio_default_fixture_loop_scope = "function"
95
+ addopts = [
96
+ "--import-mode=importlib",
97
+ "--strict-markers",
98
+ "--capture=no",
99
+ "--cov=./src"
100
+ ]
101
+
102
+ [tool.coverage.run]
103
+ branch = true
104
+
105
+ [tool.coverage.report]
106
+ show_missing = true
107
+ exclude_also = ["@abstract"]
108
+
109
+ [tool.ruff]
110
+ line-length = 79
111
+
112
+ [tool.ruff.lint]
113
+ select = ["E4", "E7", "E9", "F", "I"]
114
+
115
+ [tool.ruff.lint.pylint]
116
+ max-args = 7
117
+ allow-magic-value-types = ["str", "bytes", "int"]
118
+
119
+ [tool.pyright]
120
+ include = ["src", "tests/unit"]
121
+ extraPaths = ["src"]
122
+ strict = ["src"]
123
+ reportMissingTypeStubs = "error"
124
+
125
+ [tool.scriv]
126
+ version = "literal: pyproject.toml: tool.poetry.version"
127
+ format = "md"
128
+
129
+ [build-system]
130
+ requires = ["poetry-core"]
131
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,3 @@
1
+ from .pkl_generator import generate_pkl_type as generate_pkl_type
2
+ from .pkl_generator import map_type as map_type
3
+ from .pkl_generator import write_pkl_type as write_pkl_type
@@ -0,0 +1,56 @@
1
+ from typing import Dict, List
2
+
3
+ from tfparse import load_from_path
4
+
5
+ type_mapping: Dict[str, str] = {
6
+ "string": "String",
7
+ "number": "Number",
8
+ "bool": "Boolean",
9
+ "list of dynamic": "Listing",
10
+ "list(any)": "Listing",
11
+ "list of string": "Listing<String>",
12
+ "list of number": "Listing<Number>",
13
+ "list of bool": "Listing<Boolean>",
14
+ "map of dynamic": "Mapping<String, Any>",
15
+ "map of string": "Mapping<String, String>",
16
+ "map of number": "Mapping<String, Number>",
17
+ "map of bool": "Mapping<String, Boolean>",
18
+ }
19
+
20
+ indent = " "
21
+
22
+
23
+ def map_type(terraform_type: str) -> str:
24
+ """Map Terraform type to Python type."""
25
+ return type_mapping[terraform_type]
26
+
27
+
28
+ def generate_pkl_type(chdir: str, type_name: str) -> str:
29
+ parsed = load_from_path(chdir)
30
+ root_variables = [
31
+ variable
32
+ for variable in parsed["variable"]
33
+ if variable["__tfmeta"]["filename"] == "variables.tf"
34
+ ]
35
+ output: List[str] = []
36
+
37
+ output.append(
38
+ f"// This file is automatically generated based on the input variables in {chdir}/variables.tf"
39
+ )
40
+ output.append(f"class {type_name} {{")
41
+
42
+ for variable in root_variables:
43
+ output.append(
44
+ f"{indent}{variable['__tfmeta']['label']}: {map_type(variable['type'])}"
45
+ )
46
+
47
+ output.append("}")
48
+ return "\n".join(output)
49
+
50
+
51
+ def write_pkl_type(chdir: str, target_file_path: str, type_name: str) -> None:
52
+ """Generate and write the PKL type to a file."""
53
+ result = generate_pkl_type(chdir, type_name)
54
+
55
+ with open(target_file_path, "w") as file:
56
+ file.write(result)