Skip to content

Commit

Permalink
jinja profiles folder added to search path
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Dec 9, 2024
1 parent d366425 commit 7b9ce4b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion conan/internal/api/profile/profile_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ def _load_profile(self, profile_name, cwd):
"conan_version": conan_version,
"detect_api": detect_api}

rtemplate = Environment(loader=FileSystemLoader(base_path)).from_string(text)
# If the profile is in the home profiles folder, use the profiles folder as search
# path too, to allow loading "common" profiles in common folders, not only children
loader_paths = base_path
if os.path.commonpath([profiles_folder]) == os.path.commonpath([profiles_folder,
profile_path]):
loader_paths = [base_path, profiles_folder]
rtemplate = Environment(loader=FileSystemLoader(loader_paths)).from_string(text)

try:
text = rtemplate.render(context)
Expand Down
36 changes: 36 additions & 0 deletions test/integration/configuration/test_profile_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ def test_profile_template_import():
assert "os=FreeBSD" in client.out


def test_profile_template_import_sibling():
# https://github.com/conan-io/conan/issues/17431
client = TestClient()
tpl1 = textwrap.dedent(r"""
{% import "sub2/profile_vars" as vars %}
[settings]
os = {{ vars.a }}
""")
tpl2 = textwrap.dedent("""
{% set a = "FreeBSD" %}
""")
client.save_home({"profiles/sub1/profile1": tpl1,
"profiles/sub2/profile_vars": tpl2})
client.save({"conanfile.py": GenConanfile()})
client.run("install . -pr=sub1/profile1")
assert "os=FreeBSD" in client.out


def test_profile_template_include():
client = TestClient()
tpl1 = textwrap.dedent("""
Expand All @@ -72,6 +90,24 @@ def test_profile_template_include():
assert "os=FreeBSD" in client.out


def test_profile_template_include_sibling():
# https://github.com/conan-io/conan/issues/17431
client = TestClient()
tpl1 = textwrap.dedent(r"""
{% include "sub2/profile_vars" %}
""")
tpl2 = textwrap.dedent("""
{% set a = "FreeBSD" %}
[settings]
os = {{ a }}
""")
client.save_home({"profiles/sub1/profile1": tpl1,
"profiles/sub2/profile_vars": tpl2})
client.save({"conanfile.py": GenConanfile()})
client.run("install . -pr=sub1/profile1")
assert "os=FreeBSD" in client.out


def test_profile_template_profile_dir():
client = TestClient()
tpl1 = textwrap.dedent("""
Expand Down

0 comments on commit 7b9ce4b

Please sign in to comment.