netherframe.generation 0.3.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.
- netherframe_generation-0.3.0/LICENSE +21 -0
- netherframe_generation-0.3.0/PKG-INFO +66 -0
- netherframe_generation-0.3.0/README.md +43 -0
- netherframe_generation-0.3.0/netherframe/generation/__init__.py +31 -0
- netherframe_generation-0.3.0/netherframe/generation/api.py +306 -0
- netherframe_generation-0.3.0/netherframe/generation/batch.py +65 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/__init__.py +6 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/bindings.py +180 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/converter.py +365 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/emitter.py +972 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/expressions.py +701 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/hcl_ast.py +721 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/module_fetch.py +135 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/module_source.py +200 -0
- netherframe_generation-0.3.0/netherframe/generation/convert/python_code.py +152 -0
- netherframe_generation-0.3.0/netherframe/generation/discovered_code.py +777 -0
- netherframe_generation-0.3.0/netherframe/generation/functions/__init__.py +8 -0
- netherframe_generation-0.3.0/netherframe/generation/functions/generator.py +369 -0
- netherframe_generation-0.3.0/netherframe/generation/import_specs.py +179 -0
- netherframe_generation-0.3.0/netherframe/generation/imports.py +169 -0
- netherframe_generation-0.3.0/netherframe/generation/nf_alias_shims.py +104 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/__init__.py +1 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/build_backend.py +90 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/cli.py +274 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/code_generator.py +2128 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/codegen_support.py +542 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/logging.py +22 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/output_transaction.py +85 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/package_output.py +440 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/release.py +155 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/schema_generation.py +220 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/schema_loading.py +10 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/schema_native.py +97 -0
- netherframe_generation-0.3.0/netherframe/generation/providers/schema_parser.py +563 -0
- netherframe_generation-0.3.0/netherframe/generation/py.typed +0 -0
- netherframe_generation-0.3.0/nf/generation/__init__.py +4 -0
- netherframe_generation-0.3.0/nf/generation/api.py +4 -0
- netherframe_generation-0.3.0/nf/generation/batch.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/__init__.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/bindings.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/converter.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/emitter.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/expressions.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/hcl_ast.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/module_fetch.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/module_source.py +4 -0
- netherframe_generation-0.3.0/nf/generation/convert/python_code.py +4 -0
- netherframe_generation-0.3.0/nf/generation/discovered_code.py +4 -0
- netherframe_generation-0.3.0/nf/generation/functions/__init__.py +4 -0
- netherframe_generation-0.3.0/nf/generation/functions/generator.py +4 -0
- netherframe_generation-0.3.0/nf/generation/import_specs.py +4 -0
- netherframe_generation-0.3.0/nf/generation/imports.py +4 -0
- netherframe_generation-0.3.0/nf/generation/nf_alias_shims.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/__init__.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/build_backend.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/cli.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/code_generator.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/codegen_support.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/logging.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/output_transaction.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/package_output.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/release.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/schema_generation.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/schema_loading.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/schema_native.py +4 -0
- netherframe_generation-0.3.0/nf/generation/providers/schema_parser.py +4 -0
- netherframe_generation-0.3.0/nf/generation/py.typed +0 -0
- netherframe_generation-0.3.0/pyproject.toml +47 -0
- netherframe_generation-0.3.0/pyproject.toml.orig +44 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Netherframe
|
|
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,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netherframe.generation
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Code generation utilities for Netherframe
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: orjson>=3.13.0
|
|
8
|
+
Requires-Dist: rich>=15.0.0
|
|
9
|
+
Requires-Dist: python-hcl2>=8.2.0
|
|
10
|
+
Requires-Dist: lark>=1.3.1
|
|
11
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
12
|
+
Requires-Dist: packaging>=26.3
|
|
13
|
+
Requires-Dist: netherframe-core>=0.9.0
|
|
14
|
+
Requires-Dist: pytest>=9.2.0 ; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest-cov>=7.1.0 ; extra == 'dev'
|
|
16
|
+
Requires-Dist: ruff>=0.17.5 ; extra == 'dev'
|
|
17
|
+
Requires-Dist: ty>=0.0.105 ; extra == 'dev'
|
|
18
|
+
Requires-Python: >=3.14
|
|
19
|
+
Project-URL: Homepage, https://netherframe.arsenal.sh
|
|
20
|
+
Project-URL: Repository, https://github.com/arsenal-sh/netherframe
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# nf.generation
|
|
25
|
+
|
|
26
|
+
Code generation utilities for Netherframe framework.
|
|
27
|
+
|
|
28
|
+
This package contains:
|
|
29
|
+
- Function generation from Terraform/OpenTofu schemas
|
|
30
|
+
- Import statement generation
|
|
31
|
+
- Provider code generation from provider schemas
|
|
32
|
+
|
|
33
|
+
## Provider Generation Paths
|
|
34
|
+
|
|
35
|
+
Provider schema acquisition follows this order:
|
|
36
|
+
|
|
37
|
+
1. Cached schema from `~/.cache/nf/<org>/<provider>/<version>/schema.json`
|
|
38
|
+
2. Native provider protocol schema retrieval
|
|
39
|
+
3. Terraform CLI schema generation fallback
|
|
40
|
+
|
|
41
|
+
When Terraform CLI fallback is used, schema loading mode is controlled by:
|
|
42
|
+
|
|
43
|
+
- CLI: `--schema-loading disk|memory`
|
|
44
|
+
- Env: `NF_GENERATION_SCHEMA_LOADING=disk|memory`
|
|
45
|
+
|
|
46
|
+
Default mode is `disk`.
|
|
47
|
+
|
|
48
|
+
## Performance Benchmark
|
|
49
|
+
|
|
50
|
+
Use the generation benchmark script for repeatable local comparisons:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
NF_LOG_LEVEL=ERROR uv run python libs/netherframe.generation/benchmarks/generation_perf_benchmark.py
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Save a baseline:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
NF_LOG_LEVEL=ERROR uv run python libs/netherframe.generation/benchmarks/generation_perf_benchmark.py --output-json /tmp/nf_generation_baseline.json
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Compare current code to a baseline:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
NF_LOG_LEVEL=ERROR uv run python libs/netherframe.generation/benchmarks/generation_perf_benchmark.py --compare /tmp/nf_generation_baseline.json
|
|
66
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# nf.generation
|
|
2
|
+
|
|
3
|
+
Code generation utilities for Netherframe framework.
|
|
4
|
+
|
|
5
|
+
This package contains:
|
|
6
|
+
- Function generation from Terraform/OpenTofu schemas
|
|
7
|
+
- Import statement generation
|
|
8
|
+
- Provider code generation from provider schemas
|
|
9
|
+
|
|
10
|
+
## Provider Generation Paths
|
|
11
|
+
|
|
12
|
+
Provider schema acquisition follows this order:
|
|
13
|
+
|
|
14
|
+
1. Cached schema from `~/.cache/nf/<org>/<provider>/<version>/schema.json`
|
|
15
|
+
2. Native provider protocol schema retrieval
|
|
16
|
+
3. Terraform CLI schema generation fallback
|
|
17
|
+
|
|
18
|
+
When Terraform CLI fallback is used, schema loading mode is controlled by:
|
|
19
|
+
|
|
20
|
+
- CLI: `--schema-loading disk|memory`
|
|
21
|
+
- Env: `NF_GENERATION_SCHEMA_LOADING=disk|memory`
|
|
22
|
+
|
|
23
|
+
Default mode is `disk`.
|
|
24
|
+
|
|
25
|
+
## Performance Benchmark
|
|
26
|
+
|
|
27
|
+
Use the generation benchmark script for repeatable local comparisons:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
NF_LOG_LEVEL=ERROR uv run python libs/netherframe.generation/benchmarks/generation_perf_benchmark.py
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Save a baseline:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
NF_LOG_LEVEL=ERROR uv run python libs/netherframe.generation/benchmarks/generation_perf_benchmark.py --output-json /tmp/nf_generation_baseline.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Compare current code to a baseline:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
NF_LOG_LEVEL=ERROR uv run python libs/netherframe.generation/benchmarks/generation_perf_benchmark.py --compare /tmp/nf_generation_baseline.json
|
|
43
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Code generation utilities for Netherframe.
|
|
2
|
+
|
|
3
|
+
This package provides code generation utilities for Netherframe:
|
|
4
|
+
- Provider generation from Terraform schemas
|
|
5
|
+
- Function generation from Terraform/OpenTofu
|
|
6
|
+
- Import configuration generation from state files
|
|
7
|
+
|
|
8
|
+
The unified API is available through the api module.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from netherframe.generation.api import (
|
|
12
|
+
PROVIDER_SETS,
|
|
13
|
+
ImportGenerator,
|
|
14
|
+
generate_functions,
|
|
15
|
+
generate_imports,
|
|
16
|
+
generate_provider,
|
|
17
|
+
generate_providers,
|
|
18
|
+
get_provider_set,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
# Main generation functions
|
|
23
|
+
"generate_provider",
|
|
24
|
+
"generate_providers",
|
|
25
|
+
"generate_functions",
|
|
26
|
+
"generate_imports",
|
|
27
|
+
# Utilities
|
|
28
|
+
"ImportGenerator",
|
|
29
|
+
"get_provider_set",
|
|
30
|
+
"PROVIDER_SETS",
|
|
31
|
+
]
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"""Unified API for all Netherframe generation utilities.
|
|
2
|
+
|
|
3
|
+
This module provides a single, consistent interface for all code generation
|
|
4
|
+
functionality in Netherframe, improving developer experience and discoverability.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import TYPE_CHECKING, Any
|
|
11
|
+
|
|
12
|
+
import orjson
|
|
13
|
+
|
|
14
|
+
from netherframe.generation.batch import generate_provider_batch
|
|
15
|
+
from netherframe.generation.functions.generator import generate_terraform_functions
|
|
16
|
+
from netherframe.generation.import_specs import (
|
|
17
|
+
extract_import_specs_from_state_file,
|
|
18
|
+
import_specs_to_config,
|
|
19
|
+
)
|
|
20
|
+
from netherframe.generation.imports import ImportGenerator
|
|
21
|
+
from netherframe.generation.providers.cli import generate_provider as _generate_provider
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from netherframe.generation.providers.schema_loading import SchemaLoading
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"ImportGenerator",
|
|
28
|
+
"generate_functions",
|
|
29
|
+
"generate_imports",
|
|
30
|
+
"generate_provider",
|
|
31
|
+
"generate_providers",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def generate_provider(
|
|
36
|
+
provider_name: str,
|
|
37
|
+
output_dir: str = ".",
|
|
38
|
+
*,
|
|
39
|
+
provider_version: str = "latest",
|
|
40
|
+
schema_loading: SchemaLoading | str | None = None,
|
|
41
|
+
create_package: bool = True,
|
|
42
|
+
verbose: bool = False,
|
|
43
|
+
clean: bool = False,
|
|
44
|
+
skip_formatting: bool = False,
|
|
45
|
+
include_generated_at: bool = False,
|
|
46
|
+
binding_revision: int = 0,
|
|
47
|
+
# Advanced options
|
|
48
|
+
schema_path: str | None = None,
|
|
49
|
+
resources: list[str] | None = None,
|
|
50
|
+
data_sources: list[str] | None = None,
|
|
51
|
+
) -> int:
|
|
52
|
+
"""Generate a single provider package.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
provider_name: Provider name (e.g., 'hashicorp/aws', 'keycloak/keycloak')
|
|
56
|
+
output_dir: Output directory for generated provider package
|
|
57
|
+
provider_version: Specific provider version to use (defaults to latest)
|
|
58
|
+
schema_loading: Schema loading mode override ("disk" or "memory")
|
|
59
|
+
create_package: Create full package structure with pyproject.toml
|
|
60
|
+
verbose: Show detailed output
|
|
61
|
+
clean: Stage a clean replacement package and install it only on success
|
|
62
|
+
skip_formatting: Skip code formatting for faster generation
|
|
63
|
+
include_generated_at: Include generation timestamp in package metadata
|
|
64
|
+
binding_revision: Non-negative fourth-component Python binding revision
|
|
65
|
+
schema_path: Path to provider schema JSON (advanced)
|
|
66
|
+
resources: Generate only specific resources (advanced)
|
|
67
|
+
data_sources: Generate only specific data sources (advanced)
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
Exit code (0 for success, non-zero for failure)
|
|
71
|
+
|
|
72
|
+
Example:
|
|
73
|
+
>>> from netherframe.generation.api import generate_provider
|
|
74
|
+
>>> generate_provider("hashicorp/aws", output_dir="providers/hashicorp/aws")
|
|
75
|
+
>>> # Generate with Rust acceleration for better performance
|
|
76
|
+
>>> generate_provider(
|
|
77
|
+
... "hashicorp/aws",
|
|
78
|
+
... output_dir="providers/hashicorp/aws",
|
|
79
|
+
... )
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
return _generate_provider(
|
|
83
|
+
provider_name=provider_name,
|
|
84
|
+
output_dir=output_dir,
|
|
85
|
+
provider_version=provider_version,
|
|
86
|
+
schema_loading=schema_loading,
|
|
87
|
+
schema_path=schema_path,
|
|
88
|
+
resources=resources,
|
|
89
|
+
data_sources=data_sources,
|
|
90
|
+
functions=None, # Provider functions are not commonly used
|
|
91
|
+
create_package=create_package,
|
|
92
|
+
verbose=verbose,
|
|
93
|
+
clean=clean,
|
|
94
|
+
skip_formatting=skip_formatting,
|
|
95
|
+
include_generated_at=include_generated_at,
|
|
96
|
+
binding_revision=binding_revision,
|
|
97
|
+
resource_limit=None,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def generate_providers(
|
|
102
|
+
provider_names: list[str],
|
|
103
|
+
output_base_dir: str = "providers",
|
|
104
|
+
*,
|
|
105
|
+
provider_version: str = "latest",
|
|
106
|
+
schema_loading: SchemaLoading | str | None = None,
|
|
107
|
+
verbose: bool = False,
|
|
108
|
+
clean: bool = False,
|
|
109
|
+
skip_formatting: bool = False,
|
|
110
|
+
include_generated_at: bool = False,
|
|
111
|
+
binding_revision: int = 0,
|
|
112
|
+
parallel: bool = False,
|
|
113
|
+
) -> dict[str, bool]:
|
|
114
|
+
"""Generate multiple provider packages.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
provider_names: List of provider names to generate
|
|
118
|
+
output_base_dir: Base directory for provider packages
|
|
119
|
+
provider_version: Version to use for all providers
|
|
120
|
+
schema_loading: Schema loading mode override ("disk" or "memory")
|
|
121
|
+
verbose: Show detailed output
|
|
122
|
+
clean: Stage clean replacement packages and install each only on success
|
|
123
|
+
skip_formatting: Skip code formatting for faster generation
|
|
124
|
+
include_generated_at: Include generation timestamp in package metadata
|
|
125
|
+
binding_revision: Non-negative fourth-component Python binding revision
|
|
126
|
+
parallel: Generate providers in parallel (experimental)
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
Dictionary mapping provider names to success status
|
|
130
|
+
|
|
131
|
+
Example:
|
|
132
|
+
>>> from netherframe.generation.api import generate_providers
|
|
133
|
+
>>> results = generate_providers(
|
|
134
|
+
... ["hashicorp/aws", "hashicorp/google"],
|
|
135
|
+
... output_base_dir="providers"
|
|
136
|
+
... )
|
|
137
|
+
>>> print(results) # {"hashicorp/aws": True, "hashicorp/google": True}
|
|
138
|
+
|
|
139
|
+
"""
|
|
140
|
+
return generate_provider_batch(
|
|
141
|
+
provider_names,
|
|
142
|
+
output_base_dir=output_base_dir,
|
|
143
|
+
provider_version=provider_version,
|
|
144
|
+
schema_loading=schema_loading,
|
|
145
|
+
verbose=verbose,
|
|
146
|
+
clean=clean,
|
|
147
|
+
skip_formatting=skip_formatting,
|
|
148
|
+
include_generated_at=include_generated_at,
|
|
149
|
+
binding_revision=binding_revision,
|
|
150
|
+
parallel=parallel,
|
|
151
|
+
generate_provider_fn=generate_provider,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def generate_functions(
|
|
156
|
+
output_path: str | Path | None = None,
|
|
157
|
+
*,
|
|
158
|
+
legacy_binary: str = "terraform",
|
|
159
|
+
dry_run: bool = False,
|
|
160
|
+
) -> str | None:
|
|
161
|
+
"""Generate Terraform/OpenTofu functions for Netherframe.
|
|
162
|
+
|
|
163
|
+
This generates Python implementations of all Terraform/OpenTofu built-in
|
|
164
|
+
functions with type-safe wrappers that return Token[T] instances.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
output_path: Output file path (defaults to package's generated.py)
|
|
168
|
+
legacy_binary: Legacy binary to introspect (for example: terraform or tofu)
|
|
169
|
+
dry_run: Return generated code without writing to file
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
Generated code if dry_run=True, otherwise None
|
|
173
|
+
|
|
174
|
+
Example:
|
|
175
|
+
>>> from netherframe.generation.api import generate_functions
|
|
176
|
+
>>> # Generate functions to default location
|
|
177
|
+
>>> generate_functions()
|
|
178
|
+
>>> # Generate with OpenTofu
|
|
179
|
+
>>> generate_functions(legacy_binary="tofu")
|
|
180
|
+
>>> # Preview generated code
|
|
181
|
+
>>> code = generate_functions(dry_run=True)
|
|
182
|
+
|
|
183
|
+
"""
|
|
184
|
+
# Use the generator default legacy-catalog layout unless caller overrides output.
|
|
185
|
+
result = generate_terraform_functions(
|
|
186
|
+
output_path=str(Path(output_path)) if output_path is not None else None,
|
|
187
|
+
legacy_binary=legacy_binary,
|
|
188
|
+
dry_run=dry_run,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
return result if dry_run else None
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def generate_imports(
|
|
195
|
+
state_file: str | Path,
|
|
196
|
+
output_file: str | Path = "imports.json",
|
|
197
|
+
*,
|
|
198
|
+
resource_types: list[str] | None = None,
|
|
199
|
+
exclude_types: list[str] | None = None,
|
|
200
|
+
stack_name: str = "imported",
|
|
201
|
+
dry_run: bool = False,
|
|
202
|
+
) -> dict[str, Any] | None:
|
|
203
|
+
"""Generate Netherframe import configuration from Terraform state.
|
|
204
|
+
|
|
205
|
+
This analyzes a Terraform state file and generates import configurations
|
|
206
|
+
that can be used to import existing infrastructure into Netherframe.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
state_file: Path to Terraform state file
|
|
210
|
+
output_file: Output file for import configuration
|
|
211
|
+
resource_types: Only import these resource types
|
|
212
|
+
exclude_types: Exclude these resource types
|
|
213
|
+
stack_name: Name for the generated stack
|
|
214
|
+
dry_run: Return configuration without writing to file
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
Import configuration if dry_run=True, otherwise None
|
|
218
|
+
|
|
219
|
+
Example:
|
|
220
|
+
>>> from netherframe.generation.api import generate_imports
|
|
221
|
+
>>> # Generate import configuration
|
|
222
|
+
>>> generate_imports("terraform.tfstate")
|
|
223
|
+
>>> # Filter specific resource types
|
|
224
|
+
>>> generate_imports(
|
|
225
|
+
... "terraform.tfstate",
|
|
226
|
+
... resource_types=["aws_instance", "aws_s3_bucket"]
|
|
227
|
+
... )
|
|
228
|
+
|
|
229
|
+
"""
|
|
230
|
+
specs = extract_import_specs_from_state_file(
|
|
231
|
+
state_file,
|
|
232
|
+
resource_types=resource_types,
|
|
233
|
+
exclude_types=exclude_types,
|
|
234
|
+
)
|
|
235
|
+
import_config = {
|
|
236
|
+
"stack_name": stack_name,
|
|
237
|
+
"imports": import_specs_to_config(specs),
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if dry_run:
|
|
241
|
+
return import_config
|
|
242
|
+
|
|
243
|
+
output_path = Path(output_file)
|
|
244
|
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
245
|
+
output_path.write_bytes(orjson.dumps(import_config, option=orjson.OPT_INDENT_2))
|
|
246
|
+
|
|
247
|
+
return None
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
# Predefined provider sets for convenience
|
|
251
|
+
PROVIDER_SETS = {
|
|
252
|
+
"common": [
|
|
253
|
+
"hashicorp/aws",
|
|
254
|
+
"hashicorp/google",
|
|
255
|
+
"hashicorp/azurerm",
|
|
256
|
+
"hashicorp/random",
|
|
257
|
+
"hashicorp/null",
|
|
258
|
+
],
|
|
259
|
+
"cloud": [
|
|
260
|
+
"hashicorp/aws",
|
|
261
|
+
"hashicorp/google",
|
|
262
|
+
"hashicorp/azurerm",
|
|
263
|
+
"hashicorp/alicloud",
|
|
264
|
+
"hashicorp/oci",
|
|
265
|
+
],
|
|
266
|
+
"kubernetes": [
|
|
267
|
+
"hashicorp/kubernetes",
|
|
268
|
+
"hashicorp/helm",
|
|
269
|
+
"hashicorp/kubectl",
|
|
270
|
+
],
|
|
271
|
+
"utils": [
|
|
272
|
+
"hashicorp/random",
|
|
273
|
+
"hashicorp/null",
|
|
274
|
+
"hashicorp/time",
|
|
275
|
+
"hashicorp/local",
|
|
276
|
+
"hashicorp/archive",
|
|
277
|
+
"hashicorp/http",
|
|
278
|
+
"hashicorp/tls",
|
|
279
|
+
],
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def get_provider_set(set_name: str) -> list[str]:
|
|
284
|
+
"""Get a predefined set of providers.
|
|
285
|
+
|
|
286
|
+
Args:
|
|
287
|
+
set_name: Name of the provider set
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
List of provider names in the set
|
|
291
|
+
|
|
292
|
+
Raises:
|
|
293
|
+
ValueError: If set_name is not recognized
|
|
294
|
+
|
|
295
|
+
Example:
|
|
296
|
+
>>> from netherframe.generation.api import get_provider_set
|
|
297
|
+
>>> providers = get_provider_set("common")
|
|
298
|
+
>>> print(providers)
|
|
299
|
+
['hashicorp/aws', 'hashicorp/google', ...]
|
|
300
|
+
|
|
301
|
+
"""
|
|
302
|
+
if set_name not in PROVIDER_SETS:
|
|
303
|
+
raise ValueError(
|
|
304
|
+
f"Unknown provider set '{set_name}'. Available sets: {', '.join(PROVIDER_SETS.keys())}",
|
|
305
|
+
)
|
|
306
|
+
return PROVIDER_SETS[set_name].copy()
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from collections.abc import Callable
|
|
9
|
+
from netherframe.generation.providers.schema_loading import SchemaLoading
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def provider_output_dir(provider_name: str, output_base_dir: str) -> Path:
|
|
13
|
+
"""Return the package output directory for a provider."""
|
|
14
|
+
if "/" in provider_name:
|
|
15
|
+
org, short = provider_name.split("/", 1)
|
|
16
|
+
else:
|
|
17
|
+
org = "hashicorp"
|
|
18
|
+
short = provider_name
|
|
19
|
+
return Path(output_base_dir) / org / short
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def generate_provider_batch(
|
|
23
|
+
provider_names: list[str],
|
|
24
|
+
*,
|
|
25
|
+
output_base_dir: str,
|
|
26
|
+
provider_version: str,
|
|
27
|
+
schema_loading: SchemaLoading | str | None,
|
|
28
|
+
verbose: bool,
|
|
29
|
+
clean: bool,
|
|
30
|
+
skip_formatting: bool,
|
|
31
|
+
include_generated_at: bool,
|
|
32
|
+
parallel: bool,
|
|
33
|
+
generate_provider_fn: Callable[..., int],
|
|
34
|
+
binding_revision: int = 0,
|
|
35
|
+
) -> dict[str, bool]:
|
|
36
|
+
"""Generate multiple providers using a shared provider-generation callable."""
|
|
37
|
+
|
|
38
|
+
def generate_single(provider_name: str) -> tuple[str, bool]:
|
|
39
|
+
try:
|
|
40
|
+
exit_code = generate_provider_fn(
|
|
41
|
+
provider_name=provider_name,
|
|
42
|
+
output_dir=str(provider_output_dir(provider_name, output_base_dir)),
|
|
43
|
+
provider_version=provider_version,
|
|
44
|
+
schema_loading=schema_loading,
|
|
45
|
+
create_package=True,
|
|
46
|
+
verbose=verbose,
|
|
47
|
+
clean=clean,
|
|
48
|
+
skip_formatting=skip_formatting,
|
|
49
|
+
include_generated_at=include_generated_at,
|
|
50
|
+
binding_revision=binding_revision,
|
|
51
|
+
)
|
|
52
|
+
return provider_name, exit_code == 0
|
|
53
|
+
except Exception:
|
|
54
|
+
return provider_name, False
|
|
55
|
+
|
|
56
|
+
if not parallel:
|
|
57
|
+
return dict(generate_single(provider_name) for provider_name in provider_names)
|
|
58
|
+
|
|
59
|
+
results: dict[str, bool] = {}
|
|
60
|
+
with ThreadPoolExecutor(max_workers=4) as executor:
|
|
61
|
+
futures = {executor.submit(generate_single, provider_name): provider_name for provider_name in provider_names}
|
|
62
|
+
for future in as_completed(futures):
|
|
63
|
+
provider_name, success = future.result()
|
|
64
|
+
results[provider_name] = success
|
|
65
|
+
return results
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Convert Terraform modules (HCL or JSON syntax) into typed Netherframe Python (`nf convert`)."""
|
|
2
|
+
|
|
3
|
+
from .converter import ConversionError, ConversionResult, convert_module
|
|
4
|
+
from .hcl_ast import HclSyntaxError
|
|
5
|
+
|
|
6
|
+
__all__ = ["ConversionError", "ConversionResult", "HclSyntaxError", "convert_module"]
|