Skip to content
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

[pipes] change env vars scheme for subprocess client #17479

Conversation

alangenfeld
Copy link
Member

@alangenfeld alangenfeld commented Oct 30, 2023

Update the subprocess pipes client to inherit the parent environment. This

  • is generally more intuitive
  • necessary for windows which requires certain env vars to start subprocesses

resolves #17364

How I Tested These Changes

added test

@alangenfeld alangenfeld requested a review from schrockn October 30, 2023 17:58
@alangenfeld
Copy link
Member Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

env={
**pipes_session.get_bootstrap_env_vars(),
**self.env,
**(self._base_env if self._base_env is not None else os.environ),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is currently "inherit or use the specific values set on the client"

the main downside here is if you want to set some env vars at the client and inherit you have to do env={ **os.environ, 'set': 'other_vals'}

looks like for the old shell op we ended up always inheriting #6513

so some alternative options are:

  • have a separate (default on) arg control whether we inherit process env vars
  • just always inherit and leave it to direct open_pipes_session usage to blank out

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re:

the main downside here is if you want to set some env vars at the client and inherit you have to do env={ **os.environ, 'set': 'other_vals'}

If this were ok why not tell people just to do env=os.environ?

Unless I am confuse someone. Seems like to me we should also inherit os.environ or not and then us the "just always inherit and leave it to direct open_pipes_session usage to blank out": approach.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this line of reasoning motivating to update the PR to just always inherit the parent env

@alangenfeld alangenfeld force-pushed the al/10-30-_pipes_change_env_vars_scheme_for_subprocess_client branch from 07a56d7 to 6eeee82 Compare October 30, 2023 18:27
@@ -29,8 +30,9 @@ class _PipesSubprocess(PipesClient):
a temp file, and structured messages are read from from a temp file.

Args:
env (Optional[Mapping[str, str]]): An optional dict of environment variables to pass to the
subprocess.
env (Optional[Mapping[str, str]]): The base environment variables to pass to the
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe should rename to base_env if we go with this approach

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to think about naming is what is the scenario where we imagine the __init__ env arg, a callsite-specific arg, and inheriting os.environ at the callsite interacting. Why use this one versus pushing everything to the callsite?

env (Optional[Mapping[str, str]]): An optional dict of environment variables to pass to the
subprocess.
env (Optional[Mapping[str, str]]): The base environment variables to pass to the
subprocess, over layed with those set in the run call. Defaults to None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overlayed

Comment on lines 99 to 100
context_injector=self._context_injector,
message_reader=self._message_reader,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big deal, but why change these to the private accessors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was renaming env to base_env and figured that these members probably are not intentionally part of the "public" api so moved them to private to be clear.

Copy link
Member

@schrockn schrockn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to you q for discussion

env={
**pipes_session.get_bootstrap_env_vars(),
**self.env,
**(self._base_env if self._base_env is not None else os.environ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re:

the main downside here is if you want to set some env vars at the client and inherit you have to do env={ **os.environ, 'set': 'other_vals'}

If this were ok why not tell people just to do env=os.environ?

Unless I am confuse someone. Seems like to me we should also inherit os.environ or not and then us the "just always inherit and leave it to direct open_pipes_session usage to blank out": approach.

@@ -29,8 +30,9 @@ class _PipesSubprocess(PipesClient):
a temp file, and structured messages are read from from a temp file.

Args:
env (Optional[Mapping[str, str]]): An optional dict of environment variables to pass to the
subprocess.
env (Optional[Mapping[str, str]]): The base environment variables to pass to the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to think about naming is what is the scenario where we imagine the __init__ env arg, a callsite-specific arg, and inheriting os.environ at the callsite interacting. Why use this one versus pushing everything to the callsite?

@alangenfeld alangenfeld force-pushed the al/10-30-_pipes_change_env_vars_scheme_for_subprocess_client branch from 6eeee82 to dcc8835 Compare November 1, 2023 16:51
@alangenfeld alangenfeld dismissed schrockn’s stale review November 1, 2023 16:54

updated to much simpler change

Copy link

github-actions bot commented Nov 1, 2023

Deploy preview for dagit-storybook ready!

✅ Preview
https://dagit-storybook-re45k7hmv-elementl.vercel.app
https://al-10-30--pipes-change-env-vars-scheme-for-subprocess-client.components-storybook.dagster-docs.io

Built with commit dcc8835.
This pull request is being automatically deployed with vercel-action

Copy link

github-actions bot commented Nov 1, 2023

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-nvzss38dd-elementl.vercel.app
https://al-10-30--pipes-change-env-vars-scheme-for-subprocess-client.core-storybook.dagster-docs.io

Built with commit dcc8835.
This pull request is being automatically deployed with vercel-action

@@ -101,9 +102,10 @@ def run(
command,
cwd=cwd or self.cwd,
env={
**pipes_session.get_bootstrap_env_vars(),
**os.environ,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we get user demand we can pretty easily add a bool argument to disable this if we want

@alangenfeld alangenfeld merged commit 4061b3e into master Nov 1, 2023
3 checks passed
@alangenfeld alangenfeld deleted the al/10-30-_pipes_change_env_vars_scheme_for_subprocess_client branch November 1, 2023 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PipesSubprocessClient broken on Windows
2 participants