Skip to content

Commit 8dee326

Browse files
authored
added inputs generation on [cfn init] (#522)
1 parent 0032c60 commit 8dee326

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ repos:
3333
- flake8-pep3101>=1.2.1
3434
# language_version: python3.6
3535
- id: pretty-format-json
36+
exclude: inputs.json
3637
args:
3738
- --autofix
3839
- --indent=4

src/rpdk/core/project.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,26 @@ def _write(f):
189189

190190
self.safewrite(self.schema_path, _write)
191191

192+
def _write_example_inputs(self):
193+
194+
shutil.rmtree(self.inputs_path, ignore_errors=True)
195+
self.inputs_path.mkdir(exist_ok=True)
196+
197+
template = self.env.get_template("inputs.json")
198+
properties = list(self.schema["properties"].keys())
199+
200+
for inputs_file in (
201+
"inputs_1_create.json",
202+
"inputs_1_update.json",
203+
"inputs_1_invalid.json",
204+
):
205+
self.safewrite(
206+
self.inputs_path / inputs_file,
207+
template.render(
208+
properties=properties[:-1], last_property=properties[-1]
209+
),
210+
)
211+
192212
def write_settings(self):
193213
if self.runtime not in LAMBDA_RUNTIMES:
194214
LOG.critical(
@@ -220,6 +240,7 @@ def init(self, type_name, language, settings=None):
220240
self.settings = settings or {}
221241

222242
self._write_example_schema()
243+
self._write_example_inputs()
223244
self._plugin.init(self)
224245
self.write_settings()
225246

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
{% for property in properties %}
3+
"{{ property }}": "...",
4+
{% endfor %}
5+
"{{ last_property }}": "..."
6+
}

tests/test_project.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,15 @@ def test_init(project):
473473
with project.schema_path.open("r", encoding="utf-8") as f:
474474
assert json.load(f)
475475

476+
for file_inputs in (
477+
"inputs_1_create.json",
478+
"inputs_1_update.json",
479+
"inputs_1_invalid.json",
480+
):
481+
path_file = project.inputs_path / file_inputs
482+
with path_file.open("r", encoding="utf-8") as f:
483+
assert json.load(f)
484+
476485
# ends with newline
477486
with project.schema_path.open("rb") as f:
478487
f.seek(-1, os.SEEK_END)

0 commit comments

Comments
 (0)