Handle files in skeleton template dirs correctly (PR#82624)

* If file and file.j2 exists in skeletons template dir, copy both
* Add tests
pull/82624/head
Markus Falb 4 months ago
parent 0428490e3c
commit 4622a6a538

@ -1217,10 +1217,10 @@ class GalaxyCLI(CLI):
b_rendered = to_bytes(templar.template(template_data), errors='surrogate_or_strict')
with open(dest_file, 'wb') as df:
df.write(b_rendered)
elif f + '.j2' in files and not in_templates_dir:
# We have two possible sources for the same file, we prefer the jinja template
continue
else:
if f + '.j2' in files:
# We have two possible sources for the same file, we prefer the jinja template
continue
f_rel_path = os.path.relpath(os.path.join(root, f), obj_skeleton)
shutil.copyfile(os.path.join(root, f), os.path.join(obj_path, f_rel_path), follow_symlinks=False)

@ -0,0 +1,2 @@
[defaults]
test_key = not_a_jinja_file_at_all

@ -445,6 +445,14 @@ class TestGalaxyInitSkeleton(unittest.TestCase, ValidRoleTests):
expected_contents = '[defaults]\ntest_key = {{ test_variable }}'
self.assertEqual(expected_contents, contents.strip(), msg="test.conf.j2 doesn't contain what it should, is it being rendered?")
def test_file_not_masked_by_template(self):
test_conf = os.path.join(self.role_dir, 'templates', 'test.conf')
self.assertTrue(os.path.exists(test_conf), msg="The test.conf file doesn't seem to exist, was it not copied because test.conf.j2 does exist too?")
with open(test_conf, 'r') as f:
contents = f.read()
expected_contents = '[defaults]\ntest_key = not_a_jinja_file_at_all'
self.assertEqual(expected_contents, contents.strip(), msg="test.conf doesn't contain what it should, is it being rendered?")
def test_template_ignore_jinja_subfolder(self):
test_conf_j2 = os.path.join(self.role_dir, 'templates', 'subfolder', 'test.conf.j2')
self.assertTrue(os.path.exists(test_conf_j2), msg="The test.conf.j2 template doesn't seem to exist, is it being rendered as test.conf?")

@ -443,6 +443,9 @@ def test_init_collection(collection_input):
file_hash = secure_hash_s(open(os.path.join(input_dir, 'README.md')).read())
assert file_hash == '08f24200b9fbe18903e7a50930c9d0df0b8d7da3' # shasum test/units/cli/test_data/collection_skeleton/README.md.j2
assert os.path.isfile(os.path.join(input_dir, 'roles/common/templates/file-a.j2'))
assert os.path.isfile(os.path.join(input_dir, 'roles/common/templates/file-a'))
def test_build_collection_no_galaxy_yaml():
fake_path = u'/fake/ÅÑŚÌβŁÈ/path'

Loading…
Cancel
Save