Separate ingestion of environment from fmf keys and CLI options#4968
Separate ingestion of environment from fmf keys and CLI options#4968happz wants to merge 2 commits into
Conversation
* they will have different position in the list of sources ordered by precedence, * the CLI input is used twice, both from run and from plan, while it will be owned by the run only.
There was a problem hiding this comment.
Code Review
This pull request refactors environment variable extraction by replacing the unified Environment.from_inputs method with dedicated from_fmf_keys and from_cli_options methods, alongside updating type annotations in tmt/utils/__init__.py. In tmt/base/plan.py, casting environment-file directly to list[str] can cause runtime bugs if a single string is provided. Normalize environment-file using tmt.utils.normalize_string_list and validate that environment is a dictionary before passing them to from_fmf_keys.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| return Environment.from_fmf_keys( | ||
| raw_fmf_environment_files=cast(Optional[list[str]], self.node.get("environment-file")) | ||
| or [], | ||
| raw_fmf_environment=cast(Optional[dict[str, Any]], self.node.get('environment')) or {}, | ||
| file_root=Path(self.node.root) if self.node.root else None, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType] | ||
| key_address=self.node.name, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType] | ||
| logger=self._logger, | ||
| ) | ||
|
|
||
| @property | ||
| def _environment_from_cli(self) -> Environment: | ||
| """ | ||
| Environment variables from ``--environment`` and ``--environment-file`` options. | ||
| """ | ||
|
|
||
| return Environment.from_inputs( | ||
| raw_cli_environment_files=self.opt('environment-file') or [], | ||
| raw_cli_environment=self.opt('environment'), | ||
| file_root=Path(self.node.root) if self.node.root else None, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType] | ||
| key_address=self.node.name, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType] | ||
| logger=self._logger, | ||
| ) |
There was a problem hiding this comment.
Normalize environment-file using tmt.utils.normalize_string_list and validate environment is a dictionary. Casting a string to list[str] causes runtime bugs as from_files will iterate over characters of the filename string.
raw_fmf_environment_files = tmt.utils.normalize_string_list(
f'{self.node.name}:environment-file',
self.node.get("environment-file"),
self._logger,
)
raw_fmf_environment = self.node.get('environment')
if raw_fmf_environment is None:
raw_fmf_environment = {}
elif not isinstance(raw_fmf_environment, dict):
raise tmt.utils.NormalizationError(
f'{self.node.name}:environment',
raw_fmf_environment,
'unset or a dictionary',
)
return Environment.from_fmf_keys(
raw_fmf_environment_files=raw_fmf_environment_files,
raw_fmf_environment=raw_fmf_environment,
file_root=Path(self.node.root) if self.node.root else None, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType]
logger=self._logger,
)
Pull Request Checklist