Skip to content

Commit

Permalink
jinja profiles folder added to search path (#17432)
Browse files Browse the repository at this point in the history
* jinja profiles folder added to search path

* unconditionally adding the folder
  • Loading branch information
memsharded authored Dec 11, 2024
1 parent cc2bff1 commit e54f491
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
5 changes: 4 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,10 @@ def _load_profile(self, profile_name, cwd):
"conan_version": conan_version,
"detect_api": detect_api}

rtemplate = Environment(loader=FileSystemLoader(base_path)).from_string(text)
# Always include the root Conan home "profiles" folder as secondary route for loading
# imports and includes from jinja2 templates.
loader_paths = [base_path, profiles_folder]
rtemplate = Environment(loader=FileSystemLoader(loader_paths)).from_string(text)

try:
text = rtemplate.render(context)
Expand Down
54 changes: 54 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,42 @@ 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_include_from_cache():
# 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/sub2/profile_vars": tpl2})
client.save({"conanfile.py": GenConanfile(),
"sub1/profile1": tpl1})
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 e54f491

Please sign in to comment.