Skip to content

Commit

Permalink
fix(runner): environment vars are evaluated to late
Browse files Browse the repository at this point in the history
  • Loading branch information
d-biehl committed Jan 24, 2024
1 parent c0495e6 commit f74ea4a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def server_initialized(self, sender: Any) -> None:
config: RobotConfig = self.workspace.get_configuration(RobotConfig, folder.uri)

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

for p in self.robot_profile.python_path or []:
pa = Path(str(p))
Expand Down
4 changes: 2 additions & 2 deletions packages/robot/src/robotcode/robot/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ class RobotBaseProfile(CommonOptions, CommonExtendOptions, RobotOptions, RobotEx
Corresponds to the `paths` argument of __robot__.
"""
)
env: Optional[Dict[str, str]] = field(
env: Optional[Dict[str, Union[str, StringExpression]]] = field(
description="""\
Define environment variables to be set before running tests.
Expand Down Expand Up @@ -2202,7 +2202,7 @@ class RobotExtraBaseProfile(RobotBaseProfile):
"""
)

extend_env: Optional[Dict[str, str]] = field(
extend_env: Optional[Dict[str, Union[str, StringExpression]]] = field(
description="""\
Append extra environment variables to be set before tests.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def create_imports_manager(self, root_uri: Uri) -> ImportsManager:
robot_config = self.workspace.get_configuration(RobotConfig, root_uri)

cache_config = self.workspace.get_configuration(CacheConfig, root_uri)
environment = self.robot_profile.env or {}
environment = {k: str(v) for k, v in (self.robot_profile.env or {}).items()}
if robot_config.env:
environment.update(robot_config.env)

Expand Down
17 changes: 8 additions & 9 deletions packages/runner/src/robotcode/runner/cli/libdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ def libdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
robot_arguments, app.config.config_files, verbose_callback=app.verbose
)
try:
profile = (
load_robot_config_from_path(*config_files)
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
.evaluated()
profile = load_robot_config_from_path(*config_files).combine_profiles(
*(app.config.profiles or []), verbose_callback=app.verbose
)

if profile.env:
for k, v in profile.env.items():
os.environ[k] = str(v)
app.verbose(lambda: f"Set environment variable {k} to {v}")
profile = profile.evaluated()
except (TypeError, ValueError) as e:
raise click.ClickException(str(e)) from e

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

options = libdoc_options.build_command_line()

if profile.env:
for k, v in profile.env.items():
os.environ[k] = v
app.verbose(lambda: f"Set environment variable {k} to {v}")

app.verbose(
lambda: "Executing libdoc robot with the following options:\n "
+ " ".join(f'"{o}"' for o in (options + list(robot_options_and_args)))
Expand Down
17 changes: 8 additions & 9 deletions packages/runner/src/robotcode/runner/cli/rebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ def rebot(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
)

try:
profile = (
load_robot_config_from_path(*config_files)
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
.evaluated()
profile = load_robot_config_from_path(*config_files).combine_profiles(
*(app.config.profiles or []), verbose_callback=app.verbose
)
if profile.env:
for k, v in profile.env.items():
os.environ[k] = str(v)
app.verbose(lambda: f"Set environment variable {k} to {v}")
profile = profile.evaluated()

except (TypeError, ValueError) as e:
raise click.ClickException(str(e)) from e

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

if profile.env:
for k, v in profile.env.items():
os.environ[k] = v
app.verbose(lambda: f"Set environment variable {k} to {v}")

app.verbose(
lambda: "Executing rebot with the following options:\n "
+ " ".join(f'"{o}"' for o in (options + list(robot_options_and_args)))
Expand Down
19 changes: 10 additions & 9 deletions packages/runner/src/robotcode/runner/cli/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,17 @@ def handle_robot_options(
robot_arguments, app.config.config_files, verbose_callback=app.verbose
)
try:
profile = (
load_robot_config_from_path(*config_files)
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
.evaluated()
profile = load_robot_config_from_path(*config_files).combine_profiles(
*(app.config.profiles or []), verbose_callback=app.verbose
)

if profile.env:
for k, v in profile.env.items():
os.environ[k] = str(v)
app.verbose(lambda: f"Set environment variable {k} to {v}")

profile = profile.evaluated()

except (TypeError, ValueError) as e:
raise click.ClickException(str(e)) from e

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

if profile.env:
for k, v in profile.env.items():
os.environ[k] = v
app.verbose(lambda: f"Set environment variable {k} to {v}")

app.verbose(
lambda: "Executing robot with following options:\n "
+ " ".join(f'"{o}"' for o in (cmd_options + list(robot_options_and_args)))
Expand Down
16 changes: 7 additions & 9 deletions packages/runner/src/robotcode/runner/cli/testdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ def testdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
)

try:
profile = (
load_robot_config_from_path(*config_files)
.combine_profiles(*(app.config.profiles or []), verbose_callback=app.verbose)
.evaluated()
profile = load_robot_config_from_path(*config_files).combine_profiles(
*(app.config.profiles or []), verbose_callback=app.verbose
)
if profile.env:
for k, v in profile.env.items():
os.environ[k] = str(v)
app.verbose(lambda: f"Set environment variable {k} to {v}")
profile = profile.evaluated()
except (TypeError, ValueError) as e:
raise click.ClickException(str(e)) from e

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

options = testdoc_options.build_command_line()

if profile.env:
for k, v in profile.env.items():
os.environ[k] = v
app.verbose(lambda: f"Set environment variable {k} to {v}")

app.verbose(
lambda: "Executing testdoc with the following options:\n "
+ " ".join(f'"{o}"' for o in (options + list(robot_options_and_args)))
Expand Down

0 comments on commit f74ea4a

Please sign in to comment.