Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jinja profiles folder added to search path #17432

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading