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

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

Merged
merged 5 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions doc/source/serve/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,6 @@ as shown below.

.. literalinclude:: ../../../python/ray/serve/examples/doc/conda_env.py

.. warning::
The script must be run in an activated conda environment (not required to be
``ray-tf1`` or ``ray-tf2``). We hope to remove this restriction in the
future.

.. note::
If the argument ``env`` is omitted, backends will be started in the same
conda environment as the caller of
Expand Down
1 change: 1 addition & 0 deletions python/ray/serve/examples/doc/imported_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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")
Expand Down
17 changes: 13 additions & 4 deletions python/ray/serve/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
from ray.serve.exceptions import RayServeException
from collections import UserDict
from pathlib import Path

import starlette.requests
import requests
Expand Down Expand Up @@ -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
Expand Down