def test_get_import_path_nested_actor(self): d = serve.deployment(name="actor")(DecoratedActor) # CI may change the parent path, so check only that the suffix matches. assert get_deployment_import_path(d).endswith( "ray.serve.tests.test_util.DecoratedActor" )
def deployment_to_schema(d: Deployment) -> DeploymentSchema: """Converts a live deployment object to a corresponding structured schema. If the deployment has a class or function, it will be attemptetd to be converted to a valid corresponding import path. init_args and init_kwargs must also be JSON-serializable or this call will fail. """ if d.ray_actor_options is not None: ray_actor_options_schema = RayActorOptionsSchema.parse_obj( d.ray_actor_options) else: ray_actor_options_schema = None return DeploymentSchema( name=d.name, import_path=get_deployment_import_path(d, enforce_importable=True, replace_main=True), init_args=(), init_kwargs={}, num_replicas=d.num_replicas, route_prefix=d.route_prefix, max_concurrent_queries=d.max_concurrent_queries, user_config=d.user_config, autoscaling_config=d._config.autoscaling_config, graceful_shutdown_wait_loop_s=d._config.graceful_shutdown_wait_loop_s, graceful_shutdown_timeout_s=d._config.graceful_shutdown_timeout_s, health_check_period_s=d._config.health_check_period_s, health_check_timeout_s=d._config.health_check_timeout_s, ray_actor_options=ray_actor_options_schema, )
def test_get_import_path_basic(self): d = decorated_f.options() # CI may change the parent path, so check only that the suffix matches. assert get_deployment_import_path(d).endswith( "ray.serve.tests.test_util.decorated_f" )
def test_invalid_inline_defined(self): @serve.deployment def inline_f(): pass with pytest.raises(RuntimeError, match="must be importable"): get_deployment_import_path(inline_f, enforce_importable=True) with pytest.raises(RuntimeError, match="must be importable"): get_deployment_import_path(gen_func(), enforce_importable=True) @serve.deployment class InlineCls: pass with pytest.raises(RuntimeError, match="must be importable"): get_deployment_import_path(InlineCls, enforce_importable=True) with pytest.raises(RuntimeError, match="must be importable"): get_deployment_import_path(gen_class(), enforce_importable=True)
def get_import_path(self): if ("is_from_serve_deployment" in self._bound_other_args_to_resolve ): # built by serve top level api, this is ignored for serve.run return "dummy" return get_deployment_import_path(self._deployment)