[Serve] Add dependency management support for driver not running in a conda env (#13269)

This commit is contained in:
architkulkarni
2021-01-12 09:57:15 -08:00
committed by GitHub
parent 518427627b
commit e560933f9c
3 changed files with 14 additions and 9 deletions
@@ -5,6 +5,7 @@ from ray.serve.backends import ImportedBackend
client = serve.start()
# Include your class as input to the ImportedBackend constructor.
backend_class = ImportedBackend("ray.serve.utils.MockImportedBackend")
client.create_backend("imported", backend_class, "input_arg")
client.create_endpoint("imported", backend="imported", route="/imported")
+13 -4
View File
@@ -11,6 +11,7 @@ from typing import Iterable, List, Dict, Tuple
import os
from ray.serve.exceptions import RayServeException
from collections import UserDict
from pathlib import Path
import starlette.requests
import requests
@@ -180,13 +181,21 @@ def format_actor_name(actor_name, controller_name=None, *modifiers):
def get_conda_env_dir(env_name):
"""Given a environment name like `tf1`, find and validate the
corresponding conda directory.
corresponding conda directory. Untested on Windows.
"""
conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix is None:
raise ValueError(
"Serve cannot find environment variables installed by conda. " +
"Are you sure you are in a conda env?")
# The caller is neither in a conda env or in (base). This is rare
# because by default, new terminals start in (base), but we can still
# support this case.
conda_exe = os.environ.get("CONDA_EXE")
if conda_exe is None:
raise RayServeException(
"Ray Serve cannot find environment variables set by conda. "
"Please verify conda is installed.")
# Example: CONDA_EXE=$HOME/anaconda3/bin/python
# Strip out the /bin/python by going up two parent directories.
conda_prefix = str(Path(conda_exe).parent.parent)
# There are two cases:
# 1. We are in conda base env: CONDA_DEFAULT_ENV=base and