Skip to content

Commit e69c9dd

Browse files
authored
root profile name jinja (#19393)
1 parent a35ce49 commit e69c9dd

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

conan/internal/api/profile/profile_loader.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ def from_cli_args(self, profiles, settings, options, conf, cwd, context=None):
9999
def load_profile(self, profile_name, cwd=None, context=None):
100100
# TODO: This can be made private, only used in testing now
101101
cwd = cwd or os.getcwd()
102-
profile = self._load_profile(profile_name, cwd, context)
102+
profile = self._load_profile(profile_name, cwd, context, root_profile_name=profile_name)
103103
return profile
104104

105-
def _load_profile(self, profile_name, cwd, context):
105+
def _load_profile(self, profile_name, cwd, context, root_profile_name):
106106
""" Will look for "profile_name" in disk if profile_name is absolute path,
107107
in current folder if path is relative or in the default folder otherwise.
108108
return: a Profile object
@@ -122,6 +122,7 @@ def _load_profile(self, profile_name, cwd, context):
122122
"subprocess": subprocess,
123123
"profile_dir": base_path,
124124
"profile_name": file_path,
125+
"root_profile_name": root_profile_name,
125126
"conan_version": conan_version,
126127
"detect_api": detect_api,
127128
"context": context}
@@ -138,11 +139,11 @@ def _load_profile(self, profile_name, cwd, context):
138139
f"Check your Jinja2 syntax: {str(e)}")
139140

140141
try:
141-
return self._recurse_load_profile(text, profile_path, context)
142+
return self._recurse_load_profile(text, profile_path, context, profile_name)
142143
except ConanException as exc:
143144
raise ConanException("Error reading '%s' profile: %s" % (profile_name, exc))
144145

145-
def _recurse_load_profile(self, text, profile_path, context):
146+
def _recurse_load_profile(self, text, profile_path, context, root_profile_name):
146147
""" Parse and return a Profile object from a text config like representation.
147148
cwd is needed to be able to load the includes
148149
"""
@@ -154,7 +155,7 @@ def _recurse_load_profile(self, text, profile_path, context):
154155
# from parent profiles
155156
for include in profile_parser.includes:
156157
# Recursion !!
157-
profile = self._load_profile(include, cwd, context)
158+
profile = self._load_profile(include, cwd, context, root_profile_name)
158159
inherited_profile.compose_profile(profile)
159160

160161
# Current profile before update with parents (but parent variables already applied)

test/integration/configuration/test_profile_jinja.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,24 @@ def configure(self):
232232
assert "conanfile.py: PROFILE NAME: include_default" in client.out
233233

234234

235+
def test_profile_root_name():
236+
c = TestClient()
237+
root = textwrap.dedent("""
238+
[conf]
239+
user.profile:name = {{ profile_name }}
240+
user.profile:root_name = {{ root_profile_name }}
241+
""")
242+
tpl = textwrap.dedent("""
243+
include(myprofile)
244+
""")
245+
246+
c.save({"myprofile": root,
247+
"other": tpl})
248+
c.run("profile show -pr=other")
249+
assert "user.profile:name=myprofile" in c.out
250+
assert "user.profile:root_name=other" in c.out
251+
252+
235253
class TestProfileDetectAPI:
236254
def test_profile_detect_os_arch(self):
237255
""" testing OS & ARCH just to test the UX and interface

0 commit comments

Comments
 (0)