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

allow global.conf jinja include #13336

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions conans/client/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import List

import yaml
from jinja2 import Template

from jinja2 import FileSystemLoader, Environment

from conan.internal.cache.cache import DataCache, RecipeLayout, PackageLayout
from conans.client.cache.editable import EditablePackages
Expand Down Expand Up @@ -152,7 +151,9 @@ def new_config(self):
distro = None
if platform.system() in ["Linux", "FreeBSD"]:
import distro
content = Template(text).render({"platform": platform, "os": os, "distro": distro})
base_path = os.path.dirname(self.new_config_path)
template = Environment(loader=FileSystemLoader(base_path)).from_string(text)
content = template.render({"platform": platform, "os": os, "distro": distro})
self._new_config.loads(content)
return self._new_config

Expand Down
17 changes: 17 additions & 0 deletions conans/test/integration/configuration/conf/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ def test_jinja_global_conf(client):
assert "user.mycompany:dist=42" in client.out


def test_jinja_global_conf_include(client):
global_conf = textwrap.dedent("""\
{% include "user_global.conf" %}
{% import "user_global.conf" as vars %}
user.mycompany:dist = {{vars.myvar*2}}
""")
user_global_conf = textwrap.dedent("""\
{% set myvar = 42 %}
user.mycompany:parallel = {{myvar}}
""")
save(client.cache.new_config_path, global_conf)
save(os.path.join(client.cache_folder, "user_global.conf"), user_global_conf)
client.run("install .")
assert "user.mycompany:parallel=42" in client.out
assert "user.mycompany:dist=84" in client.out


def test_empty_conf_valid():
tc = TestClient()
profile = textwrap.dedent(r"""
Expand Down
19 changes: 18 additions & 1 deletion conans/test/integration/configuration/test_profile_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_profile_template_variables():
assert "os=FreeBSD" in client.out


def test_profile_template_inclusion():
def test_profile_template_import():
client = TestClient()
tpl1 = textwrap.dedent("""
{% import "profile_vars" as vars %}
Expand All @@ -53,6 +53,23 @@ def test_profile_template_inclusion():
assert "os=FreeBSD" in client.out


def test_profile_template_include():
client = TestClient()
tpl1 = textwrap.dedent("""
{% include "profile_vars" %}
""")
tpl2 = textwrap.dedent("""
{% set a = "FreeBSD" %}
[settings]
os = {{ a }}
""")
client.save({"conanfile.py": GenConanfile(),
"profile1": tpl1,
"profile_vars": tpl2})
client.run("install . -pr=profile1")
assert "os=FreeBSD" in client.out


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