Skip to content

Commit f74ea4a

Browse files
committed
fix(runner): environment vars are evaluated to late
1 parent c0495e6 commit f74ea4a

File tree

7 files changed

+37
-40
lines changed

7 files changed

+37
-40
lines changed

packages/language_server/src/robotcode/language_server/robotframework/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def server_initialized(self, sender: Any) -> None:
215215
config: RobotConfig = self.workspace.get_configuration(RobotConfig, folder.uri)
216216

217217
for k, v in (self.robot_profile.env or {}).items():
218-
os.environ[k] = v
218+
os.environ[k] = str(v)
219219

220220
for p in self.robot_profile.python_path or []:
221221
pa = Path(str(p))

packages/robot/src/robotcode/robot/config/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@ class RobotBaseProfile(CommonOptions, CommonExtendOptions, RobotOptions, RobotEx
21552155
Corresponds to the `paths` argument of __robot__.
21562156
"""
21572157
)
2158-
env: Optional[Dict[str, str]] = field(
2158+
env: Optional[Dict[str, Union[str, StringExpression]]] = field(
21592159
description="""\
21602160
Define environment variables to be set before running tests.
21612161
@@ -2202,7 +2202,7 @@ class RobotExtraBaseProfile(RobotBaseProfile):
22022202
"""
22032203
)
22042204

2205-
extend_env: Optional[Dict[str, str]] = field(
2205+
extend_env: Optional[Dict[str, Union[str, StringExpression]]] = field(
22062206
description="""\
22072207
Append extra environment variables to be set before tests.
22082208
"""

packages/robot/src/robotcode/robot/diagnostics/document_cache_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def create_imports_manager(self, root_uri: Uri) -> ImportsManager:
462462
robot_config = self.workspace.get_configuration(RobotConfig, root_uri)
463463

464464
cache_config = self.workspace.get_configuration(CacheConfig, root_uri)
465-
environment = self.robot_profile.env or {}
465+
environment = {k: str(v) for k, v in (self.robot_profile.env or {}).items()}
466466
if robot_config.env:
467467
environment.update(robot_config.env)
468468

packages/runner/src/robotcode/runner/cli/libdoc.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ def libdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
7070
robot_arguments, app.config.config_files, verbose_callback=app.verbose
7171
)
7272
try:
73-
profile = (
74-
load_robot_config_from_path(*config_files)
75-
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
76-
.evaluated()
73+
profile = load_robot_config_from_path(*config_files).combine_profiles(
74+
*(app.config.profiles or []), verbose_callback=app.verbose
7775
)
76+
77+
if profile.env:
78+
for k, v in profile.env.items():
79+
os.environ[k] = str(v)
80+
app.verbose(lambda: f"Set environment variable {k} to {v}")
81+
profile = profile.evaluated()
7882
except (TypeError, ValueError) as e:
7983
raise click.ClickException(str(e)) from e
8084

@@ -86,11 +90,6 @@ def libdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
8690

8791
options = libdoc_options.build_command_line()
8892

89-
if profile.env:
90-
for k, v in profile.env.items():
91-
os.environ[k] = v
92-
app.verbose(lambda: f"Set environment variable {k} to {v}")
93-
9493
app.verbose(
9594
lambda: "Executing libdoc robot with the following options:\n "
9695
+ " ".join(f'"{o}"' for o in (options + list(robot_options_and_args)))

packages/runner/src/robotcode/runner/cli/rebot.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ def rebot(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
7171
)
7272

7373
try:
74-
profile = (
75-
load_robot_config_from_path(*config_files)
76-
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
77-
.evaluated()
74+
profile = load_robot_config_from_path(*config_files).combine_profiles(
75+
*(app.config.profiles or []), verbose_callback=app.verbose
7876
)
77+
if profile.env:
78+
for k, v in profile.env.items():
79+
os.environ[k] = str(v)
80+
app.verbose(lambda: f"Set environment variable {k} to {v}")
81+
profile = profile.evaluated()
82+
7983
except (TypeError, ValueError) as e:
8084
raise click.ClickException(str(e)) from e
8185

@@ -90,11 +94,6 @@ def rebot(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
9094
except (TypeError, ValueError) as e:
9195
raise click.ClickException(str(e)) from e
9296

93-
if profile.env:
94-
for k, v in profile.env.items():
95-
os.environ[k] = v
96-
app.verbose(lambda: f"Set environment variable {k} to {v}")
97-
9897
app.verbose(
9998
lambda: "Executing rebot with the following options:\n "
10099
+ " ".join(f'"{o}"' for o in (options + list(robot_options_and_args)))

packages/runner/src/robotcode/runner/cli/robot.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,17 @@ def handle_robot_options(
108108
robot_arguments, app.config.config_files, verbose_callback=app.verbose
109109
)
110110
try:
111-
profile = (
112-
load_robot_config_from_path(*config_files)
113-
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
114-
.evaluated()
111+
profile = load_robot_config_from_path(*config_files).combine_profiles(
112+
*(app.config.profiles or []), verbose_callback=app.verbose
115113
)
114+
115+
if profile.env:
116+
for k, v in profile.env.items():
117+
os.environ[k] = str(v)
118+
app.verbose(lambda: f"Set environment variable {k} to {v}")
119+
120+
profile = profile.evaluated()
121+
116122
except (TypeError, ValueError) as e:
117123
raise click.ClickException(str(e)) from e
118124

@@ -132,11 +138,6 @@ def handle_robot_options(
132138
f"robotcode.modifiers.ExcludedByLongName{sep}{sep.join(exclude_by_longname)}",
133139
)
134140

135-
if profile.env:
136-
for k, v in profile.env.items():
137-
os.environ[k] = v
138-
app.verbose(lambda: f"Set environment variable {k} to {v}")
139-
140141
app.verbose(
141142
lambda: "Executing robot with following options:\n "
142143
+ " ".join(f'"{o}"' for o in (cmd_options + list(robot_options_and_args)))

packages/runner/src/robotcode/runner/cli/testdoc.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ def testdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
7171
)
7272

7373
try:
74-
profile = (
75-
load_robot_config_from_path(*config_files)
76-
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
77-
.evaluated()
74+
profile = load_robot_config_from_path(*config_files).combine_profiles(
75+
*(app.config.profiles or []), verbose_callback=app.verbose
7876
)
77+
if profile.env:
78+
for k, v in profile.env.items():
79+
os.environ[k] = str(v)
80+
app.verbose(lambda: f"Set environment variable {k} to {v}")
81+
profile = profile.evaluated()
7982
except (TypeError, ValueError) as e:
8083
raise click.ClickException(str(e)) from e
8184

@@ -87,11 +90,6 @@ def testdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
8790

8891
options = testdoc_options.build_command_line()
8992

90-
if profile.env:
91-
for k, v in profile.env.items():
92-
os.environ[k] = v
93-
app.verbose(lambda: f"Set environment variable {k} to {v}")
94-
9593
app.verbose(
9694
lambda: "Executing testdoc with the following options:\n "
9795
+ " ".join(f'"{o}"' for o in (options + list(robot_options_and_args)))

0 commit comments

Comments
 (0)