diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index cb2f3c565e64..58a0b8495aa2 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -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: diff --git a/python/ray/serve/__init__.py b/python/ray/serve/__init__.py index 341d80f4f38c..3865b1d25e37 100644 --- a/python/ray/serve/__init__.py +++ b/python/ray/serve/__init__.py @@ -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. diff --git a/python/ray/tests/BUILD b/python/ray/tests/BUILD index e7a62d4b4db5..46ad35927871 100644 --- a/python/ray/tests/BUILD +++ b/python/ray/tests/BUILD @@ -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( diff --git a/python/ray/tests/test_serve_ray_minimal.py b/python/ray/tests/test_serve_ray_minimal.py new file mode 100644 index 000000000000..03acd63c0793 --- /dev/null +++ b/python/ray/tests/test_serve_ray_minimal.py @@ -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__]) diff --git a/python/setup.py b/python/setup.py index 24a7ac8d2fca..0d8bad1a2670 100644 --- a/python/setup.py +++ b/python/setup.py @@ -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]