Skip to content

Commit

Permalink
[Serve] Good error message when Serve not installed and ensure Serve …
Browse files Browse the repository at this point in the history
…installs ray[default] (ray-project#19570)
  • Loading branch information
simon-mo authored Oct 21, 2021
1 parent 32e648e commit 03805d4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@
python/ray/tests/test_basic_3
- bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 $(./scripts/bazel_export_options)
python/ray/tests/test_runtime_env_ray_minimal
# TODO(archit)
- bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 $(./scripts/bazel_export_options)
python/ray/tests/test_serve_ray_minimal
- label: ":python: (Flaky tests)"
conditions: ["RAY_CI_PYTHON_AFFECTED", "RAY_CI_SERVE_AFFECTED", "RAY_CI_RLLIB_AFFECTED", "RAY_CI_TUNE_AFFECTED"]
commands:
Expand Down
14 changes: 10 additions & 4 deletions python/ray/serve/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from ray.serve.api import (start, get_replica_context, shutdown, ingress,
deployment, get_deployment, list_deployments)
from ray.serve.batching import batch
from ray.serve.config import HTTPOptions
try:
from ray.serve.api import (start, get_replica_context, shutdown, ingress,
deployment, get_deployment, list_deployments)
from ray.serve.batching import batch
from ray.serve.config import HTTPOptions
except ModuleNotFoundError as e:
e.msg += (
". You can run `pip install 'ray[serve]'` to install all Ray Serve"
" dependencies.")
raise e

# Mute the warning because Serve sometimes intentionally calls
# ray.get inside async actors.
Expand Down
8 changes: 8 additions & 0 deletions python/ray/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ py_test(
deps = ["//:ray_lib"],
)

py_test(
name = "test_serve_ray_minimal",
size = "small",
srcs = SRCS + ["test_serve_ray_minimal.py"],
tags = ["exclusive", "team:serve"],
deps = ["//:ray_lib"],
)

# TODO(ekl) we can't currently support tagging these as flaky since there's
# no way to filter by both flaky and client mode tests in bazel.
py_test_module_list(
Expand Down
22 changes: 22 additions & 0 deletions python/ray/tests/test_serve_ray_minimal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Test that Serve gives good error message when no deps are installed.
This tests exist in the ray/tests/ directory instead of ray/serve/tests because
it needs not to have dependencies on serve's conftest.py.
"""

import os

import pytest


@pytest.mark.skipif(
os.environ.get("RAY_MINIMAL") != "1",
reason="This test is only run in CI with a minimal Ray installation.")
def test_error_msg():
with pytest.raises(ModuleNotFoundError, match="install 'ray\[serve\]'"):
from ray import serve
serve.start()


if __name__ == "__main__":
pytest.main(["-v", "-s", __file__])
4 changes: 4 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def get_packages(self):
],
}

# Ray Serve depends on the Ray dashboard components.
setup_spec.extras["serve"] = list(
set(setup_spec.extras["serve"] + setup_spec.extras["default"]))

if RAY_EXTRA_CPP:
setup_spec.extras["cpp"] = ["ray-cpp==" + setup_spec.version]

Expand Down

0 comments on commit 03805d4

Please sign in to comment.