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

[Runtime Env] Make every ${ENV_VAR} replaceable #36187

Merged

Conversation

rkooo567
Copy link
Contributor

@rkooo567 rkooo567 commented Jun 8, 2023

Why are these changes needed?

In the master, we only allow a few env vars specified via ${} translatable. This is unnecessarily too restrictive. This PR allows every env vars to be translated if they are specified via ${ENV_VAR}

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: SangBin Cho <rkooo567@gmail.com>
os.environ[key] = value.replace("${" + key + "}", os.environ.get(key, ""))
else:
os.environ[key] = value
os.environ[key] = os.path.expandvars(value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the Python implementation leaves the env var unchanged if it doesn't exist. E.g.,

unset ENV_VAR

# previous
${ENV_VAR} -> ""

# now
${ENV_VAR} -> ${ENV_VAR}

I feel like this should be fine (especially given this python implementation will work cross platform correctly). But if we have to keep this behavior, I can somehow write the custom implementation

Copy link
Contributor

Choose a reason for hiding this comment

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

nice, using python's expandvars is fine

Copy link
Contributor

@jjyao jjyao left a comment

Choose a reason for hiding this comment

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

Can you also update the doc (https://docs.ray.io/en/latest/ray-core/handling-dependencies.html) as well?

Currently it has

env_vars (Dict[str, str]): Environment variables to set. Environment variables already set on the cluster will still be visible to the Ray workers; so there is no need to include os.environ or similar in the env_vars field. By default, these environment variables override the same name environment variables on the cluster. You can also reference existing environment variables using ${ENV_VAR} to achieve the appending behavior. Only PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, and LD_PRELOAD are supported. See below for an example:

Example: {"OMP_NUM_THREADS": "32", "TF_WARNINGS": "none"}

Example: {"LD_LIBRARY_PATH": "${LD_LIBRARY_PATH}:/home/admin/my_lib"}

@stale
Copy link

stale bot commented Jul 15, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

  • If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@stale stale bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jul 15, 2023
@rkooo567 rkooo567 removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jul 18, 2023
@rkooo567 rkooo567 requested a review from a team as a code owner August 10, 2023 01:28
@rkooo567
Copy link
Contributor Author

cc @jjyao it is ready for review.

Copy link
Contributor

@jjyao jjyao left a comment

Choose a reason for hiding this comment

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

Do we have tests already?

@rkooo567
Copy link
Contributor Author

@jjyao yes!

doc/source/ray-core/handling-dependencies.rst Outdated Show resolved Hide resolved
doc/source/ray-core/handling-dependencies.rst Outdated Show resolved Hide resolved
python/ray/_private/utils.py Outdated Show resolved Hide resolved
@rkooo567 rkooo567 merged commit 97e2ba1 into ray-project:master Aug 23, 2023
22 of 94 checks passed
@rkooo567
Copy link
Contributor Author

Merged it because the previous run succeeds, and I only made doc changes.

arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
In the master, we only allow a few env vars specified via ${} translatable. This is unnecessarily too restrictive. This PR allows every env vars to be translated if they are specified via ${ENV_VAR}

Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
vymao pushed a commit to vymao/ray that referenced this pull request Oct 11, 2023
In the master, we only allow a few env vars specified via ${} translatable. This is unnecessarily too restrictive. This PR allows every env vars to be translated if they are specified via ${ENV_VAR}

Signed-off-by: Victor <vctr.y.m@example.com>
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.

None yet

3 participants