|
3 | 3 | import shutil
|
4 | 4 | import subprocess
|
5 | 5 | import tempfile
|
6 |
| -from typing import Any, Dict, List, Optional, Tuple |
7 | 6 |
|
8 | 7 | import yaml
|
9 | 8 |
|
@@ -39,35 +38,28 @@ def compile_file(self, config: KapitanInputTypeCuelangConfig, input_path: str, c
|
39 | 38 | temp_input_dir = os.path.join(temp_dir, input_dir_name)
|
40 | 39 | shutil.copytree(abs_input_path, temp_input_dir)
|
41 | 40 |
|
42 |
| - cwd = os.getcwd() |
43 |
| - |
44 |
| - # os.chdir(temp_input_dir) |
45 |
| - |
| 41 | + # Write the input data to file |
46 | 42 | input_file_path = os.path.join(temp_input_dir, "input.yaml")
|
47 | 43 | with open(input_file_path, "w") as f:
|
48 | 44 | yaml.dump(config.input, f)
|
49 | 45 |
|
| 46 | + # Prepare the command to run CUE export |
50 | 47 | cmd = [
|
51 | 48 | self.cue_path,
|
52 | 49 | "export",
|
53 |
| - ".", # can't get it to work compiling from an absolute path |
54 |
| - # temp_input_dir, |
55 |
| - "-l", |
56 |
| - "input:", |
57 |
| - "input.yaml", |
58 |
| - "--out", |
59 |
| - "yaml", |
| 50 | + ".", |
60 | 51 | ]
|
61 |
| - |
62 |
| - with open("output.yaml", "w") as f: |
| 52 | + # if specified where to inject the input, add it to the command |
| 53 | + if config.input_fill_path: |
| 54 | + cmd += ["-l", config.input_fill_path] |
| 55 | + cmd += ["input.yaml", "--out", "yaml"] |
| 56 | + # if specified where the output is yielded, add it to the command |
| 57 | + if config.output_yield_path: |
| 58 | + cmd += ["--expression", config.output_yield_path] |
| 59 | + |
| 60 | + output_file = os.path.join(compile_path, "output.yaml") # TODO: make this configurable |
| 61 | + with open(output_file, "w") as f: |
63 | 62 | result = subprocess.run(cmd, stdout=f, stderr=subprocess.PIPE, text=True, cwd=temp_input_dir)
|
64 | 63 | if result.returncode != 0:
|
65 | 64 | err = f"Failed to run CUE export: {result.stderr}"
|
66 | 65 | raise KustomizeTemplateError(err)
|
67 |
| - |
68 |
| - # os.chdir(cwd) |
69 |
| - output_file = os.path.join(compile_path, "output.yaml") |
70 |
| - |
71 |
| - with open(output_file, "w") as out_f: |
72 |
| - with open("output.yaml", "r") as in_f: |
73 |
| - out_f.write(in_f.read()) |
0 commit comments