-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[core] [5/N] Check uv existence before installation #48632
Changes from 1 commit
fd7c067
7219120
0c25579
f1b5f69
794fd61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ def __init__( | |
|
||
logger.debug("Setting up uv for runtime_env: %s", runtime_env) | ||
self._target_dir = target_dir | ||
# An empty directory is created to execute cmd. | ||
self._exec_cwd = os.path.join(self._target_dir, "exec_cwd") | ||
self._runtime_env = runtime_env | ||
self._logger = logger | ||
|
||
|
@@ -62,6 +64,28 @@ async def _install_uv( | |
logger.info("Installing package uv to %s", virtualenv_path) | ||
await check_output_cmd(uv_install_cmd, logger=logger, cwd=cwd, env=pip_env) | ||
|
||
# TODO(hjiang): Add an integration test for existence check after | ||
# PR (https://github.com/ray-project/ray/pull/48619) gets merged. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 48619 is merged now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realize it's not a good way to test:
|
||
async def _check_uv_existence( | ||
self, path: str, cwd: str, env: dict, logger: logging.Logger | ||
) -> bool: | ||
"""Check and return the existence of `uv` in system executable path.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is checking the existence of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes
dentiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
python = virtualenv_utils.get_virtualenv_python(path) | ||
|
||
check_existence_cmd = [ | ||
python, | ||
"-m", | ||
"uv", | ||
"version", | ||
] | ||
|
||
try: | ||
# If `uv` doesn't exist, exception will be thrown. | ||
await check_output_cmd(check_existence_cmd, logger=logger, cwd=cwd, env=env) | ||
return True | ||
except Exception: | ||
return False | ||
|
||
async def _install_uv_packages( | ||
self, | ||
path: str, | ||
|
@@ -70,13 +94,18 @@ async def _install_uv_packages( | |
pip_env: Dict, | ||
logger: logging.Logger, | ||
): | ||
"""Install required python packages via `uv`.""" | ||
virtualenv_path = virtualenv_utils.get_virtualenv_path(path) | ||
python = virtualenv_utils.get_virtualenv_python(path) | ||
# TODO(fyrestone): Support -i, --no-deps, --no-cache-dir, ... | ||
requirements_file = dependency_utils.get_requirements_file(path, uv_packages) | ||
|
||
# Check existence for `uv` and see if we could skip `uv` installation. | ||
uv_exists = await self._check_uv_existence(python, cwd, pip_env, logger) | ||
|
||
# Install uv, which acts as the default package manager. | ||
await self._install_uv(path, cwd, pip_env, logger) | ||
if not uv_exists: | ||
await self._install_uv(path, cwd, pip_env, logger) | ||
|
||
# Avoid blocking the event loop. | ||
loop = get_running_loop() | ||
|
@@ -109,17 +138,18 @@ async def _run(self): | |
# We create an empty directory for exec cmd so that the cmd will | ||
# run more stable. e.g. if cwd has ray, then checking ray will | ||
# look up ray in cwd instead of site packages. | ||
exec_cwd = os.path.join(path, "exec_cwd") | ||
os.makedirs(exec_cwd, exist_ok=True) | ||
os.makedirs(self._exec_cwd, exist_ok=True) | ||
try: | ||
await virtualenv_utils.create_or_get_virtualenv(path, exec_cwd, logger) | ||
await virtualenv_utils.create_or_get_virtualenv( | ||
path, self._exec_cwd, logger | ||
) | ||
python = virtualenv_utils.get_virtualenv_python(path) | ||
async with dependency_utils.check_ray(python, exec_cwd, logger): | ||
async with dependency_utils.check_ray(python, self._exec_cwd, logger): | ||
# Install packages with uv. | ||
await self._install_uv_packages( | ||
path, | ||
uv_packages, | ||
exec_cwd, | ||
self._exec_cwd, | ||
self._uv_env, | ||
logger, | ||
) | ||
|
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.
My planned way to test:
ray.remote
havinguv
specified, making sure all packages correctly installed;_check_uv_existence
to make sureuv
does exist in virtual env.