-
Notifications
You must be signed in to change notification settings - Fork 6k
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 environment hooks to load runtime_env from uv run environment #50462
Conversation
# Extract the arguments of 'uv run' that are not arguments of the script | ||
uv_run_args = cmdline[: len(cmdline) - len(sys.argv)] | ||
runtime_env["py_executable"] = " ".join(uv_run_args) |
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.
how are you differntiating between uv run args vs. script args? Is this something uv is handling under the hood by not modifying sys.argv?
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.
the sys.argv are only the script args (they get passed to the script, which is a subprocess of uv run, by uv run), and cmdline are the full args with both the uv run args and the script args. So uv run
args are computed in the line cmdline[: len(cmdline) - len(sys.argv)]
above by removing the script args (in sys.argv) from all the args (cmdline)
return runtime_env | ||
|
||
|
||
def uv_run_runtime_env_hook(runtime_env: Dict[str, Any]) -> Dict[str, Any]: |
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.
now where do we inject this hook? in snapshot_util?
tangent question: How do we deal with uv run on jobs?
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.
For the jobs: It is actually very simple, you just submit the job with uv run <script>
as the entry point :)
On the hook: Right now you need to define it manually but I think going forward we should just remove the hook and do this by default once it is ironed out a little more and works well :)
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.
so we still need to define the env variable RUNTIME_ENV_HOOK
(I forget its name)?
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.
Yes, that's right (for now) :)
# Parse known arguments of uv run that impact the runtime environment | ||
uv_run_parser = argparse.ArgumentParser() | ||
uv_run_parser.add_argument("--directory", nargs="?") | ||
uv_run_parser.add_argument("--with-requirements", nargs="?") | ||
uv_run_parser.add_argument("--project", nargs="?") | ||
uv_run_parser.add_argument("--no-project", action="store_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.
how'd we come up with this list? does it need to be updated over time?
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.
These are the features I'm aware of so far that need special handling (with one exception), since they interact with the file system. The exception is https://docs.astral.sh/uv/configuration/files/#env but it seems more advanced and we can add it if / when the need arises.
Most features just work out of the box since they can just passed through.
Co-authored-by: Edward Oakes <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
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.
Just some style nits. Our style guide avoids using "please" just for conciseness.
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: angelinalg <[email protected]> Signed-off-by: Philipp Moritz <[email protected]>
…y into runtime-env-override-hook
Why are these changes needed?
Next step after #50160 to make it more convenient to use UV with Ray.
This is a useful runtime environment hook for mirroring the environment of
uv run
to the workers (currently the args to uv run and the working_dir). This is useful because it will allow people to intuitively useuv run
in a distributed application with the same behavior as for a single python process.This only modifies the environment if the driver was run with
uv run
and could conceivably become the default for drivers run with uv run.This is currently a developer API as implied by the fact that it is in the
_private
namespace. It is currently for experimentation and can needs to be opted in viaexport RAY_RUNTIME_ENV_HOOK=ray._private.runtime_env.uv_runtime_env_hook.hook
If it works well, we might make it the default in the
uv run
case.Related issue number
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.