-
Notifications
You must be signed in to change notification settings - Fork 20
chore: add private _run_task_without_session_env function to the Session class #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/openjd/sessions/_session.py
Outdated
| if apply_existing_env: | ||
| for identifier in self._environments_entered: | ||
| if identifier in self._created_env_vars: | ||
| self._created_env_vars[identifier].apply_to_environment(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, which is hack-y, but can potentially unblock.
| if apply_existing_env: | |
| for identifier in self._environments_entered: | |
| if identifier in self._created_env_vars: | |
| self._created_env_vars[identifier].apply_to_environment(result) | |
| if extra_env_vars.get("APPLY_EXISTING_ENV", "true").lower() != "false": | |
| for identifier in self._environments_entered: | |
| if identifier in self._created_env_vars: | |
| self._created_env_vars[identifier].apply_to_environment(result) |
Signed-off-by: Godot Bian <13778003+godobyte@users.noreply.github.com>
Signed-off-by: Godot Bian <13778003+godobyte@users.noreply.github.com>
src/openjd/sessions/_session.py
Outdated
| step_script: StepScriptModel, | ||
| task_parameter_values: TaskParameterSet, | ||
| os_env_vars: Optional[dict[str, str]] = None, | ||
| use_session_env_vars: Optional[bool] = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we not have this variable and always have the code be true?
We don't want anyone else to consume this for any other reason. We want to directly jump to the better API and migrate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, updated in a new commit.
src/openjd/sessions/_session.py
Outdated
| use_session_env_vars: Optional[bool] = True, | ||
| log_task_banner: bool = True, | ||
| ) -> None: | ||
| """Run a Task within the Session. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - maybe just say private API since it is private and very short lived.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
src/openjd/sessions/_session.py
Outdated
| if use_session_env_vars: | ||
| action_env_vars = self._evaluate_current_session_env_vars(os_env_vars) | ||
| else: | ||
| action_env_vars = dict[str, Optional[str]](self._process_env) # Make a copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take away the if-else and always use line 898?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You meant only after L899?
src/openjd/sessions/_session.py
Outdated
| # than after -- run() itself may end up setting the action state to FAILED. | ||
| self._runner.run() | ||
|
|
||
| def _run_task_with_optional_session_env( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked that this is a copy-paste of https://github.com/OpenJobDescription/openjd-sessions-for-python/blob/mainline/src/openjd/sessions/_session.py#L779, with the new if-else.
Signed-off-by: Godot Bian <13778003+godobyte@users.noreply.github.com>
|
…the Session class (OpenJobDescription#281)" This reverts commit bc7ac1a.


What was the problem/requirement? (What/Why)
The Session class needed a new method to run tasks with more granular control over environment variable handling. The existing
run_taskmethod always applies all entered environment variables, but there was a requirement to optionally exclude session environment variables while still allowing custom OS environment variables to be passed in.What was the solution? (How)
Added a new
_run_task_without_session_envmethod to the Session class that provides:run_taskbut with different environment variable controlThe implementation follows the same pattern as the existing
run_taskmethod but not applying env var from env enter.What is the impact of this change?
This change provides support for tasks need custom environment variables without session-level environment.
How was this change tested?
See DEVELOPMENT.md for information on running tests.
Was this change documented?
Is this a breaking change?
No
Does this change impact security?
No
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.