Skip to content

Commit 3893175

Browse files
committed
Support environment variable substitution without regenerating Conan
1 parent cdc2265 commit 3893175

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/py_build_cmake/commands/conan.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,13 @@ def _substitute_environment_options( # noqa: PLR0912
339339

340340
def _template_expand(k, a, vars):
341341
try:
342-
try:
343-
return Template(a).substitute(vars)
344-
except KeyError:
342+
if vars is None:
345343
return Template(a).substitute(os.environ)
344+
else:
345+
try:
346+
return Template(a).substitute(vars)
347+
except KeyError:
348+
return Template(a).substitute(os.environ)
346349
except KeyError as e:
347350
msg = f"Invalid substitution in environment variable '{k}': {e.args[0]}"
348351
raise ConfigError(msg) from e
@@ -352,7 +355,8 @@ def _template_expand(k, a, vars):
352355
continue
353356
assert isinstance(v, StringOption)
354357
# Perform template substitution on the different components
355-
vars = env.vars(self.conanfile) # TODO: could be slow?
358+
# TODO: could be slow?
359+
vars = None if self.conanfile is None else env.vars(self.conanfile)
356360
for attr in "value", "append", "append_path", "prepend", "prepend_path":
357361
a = getattr(v, attr)
358362
if a is not None:

0 commit comments

Comments
 (0)