Skip to content

Commit 296c13b

Browse files
authored
Improve collection root detection (#220)
* Improve collection root detection * Template only j2 files * Rename
1 parent 704a7a2 commit 296c13b

File tree

6 files changed

+7
-6
lines changed

6 files changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{% raw %}collection_root: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}"
1+
collection_root: "{{ lookup ( 'env', 'MOLECULE_PROJECT_DIRECTORY' ) }}/.."
22
integration_tests_path: "{{ collection_root }}/tests/integration/targets/"
33
molecule_scenario_name: "{{ molecule_scenario_directory | basename }}"
4-
{%- endraw %}

src/ansible_creator/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,19 @@ def _recursive_copy( # noqa: C901, PLR0912
131131
if obj.name == "__meta__.yml":
132132
continue
133133
# remove .j2 suffix at destination
134+
needs_templating = False
134135
if dest_path.suffix == ".j2":
135136
dest_path = dest_path.with_suffix("")
137+
needs_templating = True
136138
dest_file = Path(self.dest) / dest_path
137139
self.output.debug(msg=f"dest file is {dest_file}")
138140

139141
# write at destination only if missing or belongs to overwrite list
140142
if not dest_file.exists() or overwrite:
141143
content = obj.read_text(encoding="utf-8")
142-
# only render as templates if both of these are provided
143-
# templating is not mandatory
144-
if self.templar and template_data:
144+
# only render as templates if both of these are provided,
145+
# and original file suffix was j2
146+
if self.templar and template_data and needs_templating:
145147
content = self.templar.render_from_content(
146148
template=content,
147149
data=template_data,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
collection_root: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}"
1+
collection_root: "{{ lookup ( 'env', 'MOLECULE_PROJECT_DIRECTORY' ) }}/.."
22
integration_tests_path: "{{ collection_root }}/tests/integration/targets/"
33
molecule_scenario_name: "{{ molecule_scenario_directory | basename }}"

0 commit comments

Comments
 (0)