Skip to content

Commit 0e9d93b

Browse files
authored
[ci] Move simulate_storage from _private/ to _common/ (#53735)
Used by Train and Tune. Only `s3` type was used, so refactored. --------- Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
1 parent ce437fc commit 0e9d93b

File tree

7 files changed

+43
-118
lines changed

7 files changed

+43
-118
lines changed

ci/lint/pydoclint-baseline.txt

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,6 @@ python/ray/_private/node.py
111111
DOC107: Method `Node.kill_all_processes`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
112112
DOC103: Method `Node.kill_all_processes`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [allow_graceful: ].
113113
--------------------
114-
python/ray/_private/parameter.py
115-
DOC101: Method `RayParams.__init__`: Docstring contains fewer arguments than in function signature.
116-
DOC107: Method `RayParams.__init__`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
117-
DOC103: Method `RayParams.__init__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [_system_config: Optional[Dict[str, str]], autoscaling_config: Optional[str], cluster_id: Optional[str], dashboard_agent_listen_port: Optional[int], dashboard_host: Optional[str], dashboard_port: Optional[bool], driver_mode: , enable_object_reconstruction: Optional[bool], env_vars: Optional[Dict[str, str]], external_addresses: Optional[List[str]], gcs_address: Optional[str], gcs_server_port: Optional[int], huge_pages: Optional[bool], include_dashboard: Optional[bool], include_log_monitor: Optional[str], labels: Optional[Dict[str, str]], max_worker_port: Optional[int], memory: Optional[float], metrics_agent_port: Optional[int], metrics_export_port: Optional[int], min_worker_port: Optional[int], no_monitor: Optional[bool], node_id: Optional[str], node_ip_address: Optional[str], node_manager_port: int, node_name: Optional[str], num_cpus: Optional[int], num_gpus: Optional[int], num_redis_shards: Optional[int], object_manager_port: Optional[int], object_ref_seed: Optional[int], object_spilling_directory: Optional[str], object_store_memory: Optional[float], plasma_directory: Optional[str], plasma_store_socket_name: Optional[str], ray_client_server_port: Optional[int], ray_debugger_external: bool, raylet_ip_address: Optional[str], raylet_socket_name: Optional[str], redirect_output: Optional[bool], redis_address: Optional[str], redis_max_clients: Optional[int], redis_password: Optional[str], redis_port: Optional[int], redis_shard_ports: Optional[List[int]], redis_username: Optional[str], resource_isolation_config: Optional[ResourceIsolationConfig], resources: Optional[Dict[str, float]], runtime_env_agent_port: Optional[int], runtime_env_dir_name: Optional[str], session_name: Optional[str], setup_worker_path: Optional[str], storage: Optional[str], temp_dir: Optional[str], tracing_startup_hook: , webui: Optional[str], worker_path: Optional[str], worker_port_list: Optional[List[int]]].
118-
DOC106: Method `RayParams.update`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
119-
DOC103: Method `RayParams.update`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [**kwargs: ]. Arguments in the docstring but not in the function signature: [kwargs: ].
120-
DOC106: Method `RayParams.update_if_absent`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
121-
DOC103: Method `RayParams.update_if_absent`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [**kwargs: ]. Arguments in the docstring but not in the function signature: [kwargs: ].
122-
DOC202: Method `RayParams.update_pre_selected_port` has a return section in docstring, but there are no return statements or annotations
123-
--------------------
124114
python/ray/_private/profiling.py
125115
DOC106: Function `profile`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
126116
DOC107: Function `profile`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
@@ -285,8 +275,6 @@ python/ray/_private/test_utils.py
285275
DOC201: Method `BatchQueue.get_batch` does not have a return section in docstring
286276
DOC101: Function `monitor_memory_usage`: Docstring contains fewer arguments than in function signature.
287277
DOC103: Function `monitor_memory_usage`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [print_interval_s: int, record_interval_s: int]. Arguments in the docstring but not in the function signature: [interval_s: ].
288-
DOC402: Function `simulate_storage` has "yield" statements, but the docstring does not have a "Yields" section
289-
DOC404: Function `simulate_storage` yield type(s) in docstring not consistent with the return annotation. Return annotation exists, but docstring "yields" section does not exist or has 0 type(s).
290278
--------------------
291279
python/ray/_private/usage/usage_lib.py
292280
DOC201: Function `record_extra_usage_tag` does not have a return section in docstring
@@ -2949,56 +2937,3 @@ python/ray/widgets/util.py
29492937
DOC103: Function `_has_missing`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [*deps: Iterable[Union[str, Optional[str]]]]. Arguments in the docstring but not in the function signature: [deps: ].
29502938
DOC103: Function `repr_with_fallback`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [*notebook_deps: Iterable[Union[str, Optional[str]]]]. Arguments in the docstring but not in the function signature: [notebook_deps: ].
29512939
--------------------
2952-
python/ray/workflow/api.py
2953-
DOC101: Function `run`: Docstring contains fewer arguments than in function signature.
2954-
DOC103: Function `run`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [**kwargs: , *args: , dag: DAGNode].
2955-
DOC101: Function `run_async`: Docstring contains fewer arguments than in function signature.
2956-
DOC103: Function `run_async`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [**kwargs: , *args: , dag: DAGNode].
2957-
DOC201: Function `continuation` does not have a return section in docstring
2958-
DOC101: Method `options.__init__`: Docstring contains fewer arguments than in function signature.
2959-
DOC103: Method `options.__init__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [**workflow_options: Dict[str, Any]].
2960-
--------------------
2961-
python/ray/workflow/serialization.py
2962-
DOC101: Method `Manager.save_objectref`: Docstring contains fewer arguments than in function signature.
2963-
DOC103: Method `Manager.save_objectref`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [workflow_id: 'str'].
2964-
DOC107: Function `dump_to_storage`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
2965-
--------------------
2966-
python/ray/workflow/serialization_context.py
2967-
DOC402: Function `workflow_args_serialization_context` has "yield" statements, but the docstring does not have a "Yields" section
2968-
DOC404: Function `workflow_args_serialization_context` yield type(s) in docstring not consistent with the return annotation. Return annotation exists, but docstring "yields" section does not exist or has 0 type(s).
2969-
DOC402: Function `workflow_args_resolving_context` has "yield" statements, but the docstring does not have a "Yields" section
2970-
DOC404: Function `workflow_args_resolving_context` yield type(s) in docstring not consistent with the return annotation. Return annotation exists, but docstring "yields" section does not exist or has 0 type(s).
2971-
--------------------
2972-
python/ray/workflow/storage/filesystem.py
2973-
DOC107: Function `_open_atomic`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
2974-
DOC202: Function `_open_atomic` has a return section in docstring, but there are no return statements or annotations
2975-
DOC402: Function `_open_atomic` has "yield" statements, but the docstring does not have a "Yields" section
2976-
DOC404: Function `_open_atomic` yield type(s) in docstring not consistent with the return annotation. Return annotation exists, but docstring "yields" section does not exist or has 0 type(s).
2977-
--------------------
2978-
python/ray/workflow/task_executor.py
2979-
DOC104: Function `_workflow_task_executor`: Arguments are the same in the docstring and the function signature, but are in a different order.
2980-
DOC105: Function `_workflow_task_executor`: Argument names match, but type hints in these args do not match: func, context, task_id, baked_inputs, runtime_options
2981-
DOC101: Method `_BakedWorkflowInputs.resolve`: Docstring contains fewer arguments than in function signature.
2982-
DOC103: Method `_BakedWorkflowInputs.resolve`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [store: workflow_storage.WorkflowStorage].
2983-
--------------------
2984-
python/ray/workflow/workflow_context.py
2985-
DOC106: Function `workflow_task_context`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
2986-
DOC107: Function `workflow_task_context`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
2987-
DOC402: Function `workflow_task_context` has "yield" statements, but the docstring does not have a "Yields" section
2988-
DOC404: Function `workflow_task_context` yield type(s) in docstring not consistent with the return annotation. Return annotation exists, but docstring "yields" section does not exist or has 0 type(s).
2989-
DOC106: Function `workflow_logging_context`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
2990-
DOC107: Function `workflow_logging_context`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
2991-
DOC402: Function `workflow_logging_context` has "yield" statements, but the docstring does not have a "Yields" section
2992-
DOC404: Function `workflow_logging_context` yield type(s) in docstring not consistent with the return annotation. Return annotation exists, but docstring "yields" section does not exist or has 0 type(s).
2993-
--------------------
2994-
python/ray/workflow/workflow_state_from_dag.py
2995-
DOC201: Function `workflow_state_from_dag` does not have a return section in docstring
2996-
--------------------
2997-
python/ray/workflow/workflow_storage.py
2998-
DOC201: Method `WorkflowIndexingStorage.list_workflow` does not have a return section in docstring
2999-
DOC201: Method `WorkflowStorage.load_actor_class_body` does not have a return section in docstring
3000-
DOC101: Method `WorkflowStorage.load_task_metadata`: Docstring contains fewer arguments than in function signature.
3001-
DOC103: Method `WorkflowStorage.load_task_metadata`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [task_id: TaskID].
3002-
DOC201: Method `WorkflowStorage.list_workflow` does not have a return section in docstring
3003-
DOC201: Method `WorkflowStorage._put` does not have a return section in docstring
3004-
--------------------

python/ray/_common/test_utils.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
"""
77

88
import asyncio
9+
from contextlib import contextmanager
910
import inspect
11+
import os
1012
import time
1113
import traceback
12-
from typing import Any, Callable
14+
from typing import Any, Callable, Iterator
15+
import uuid
1316

1417
import ray
1518
import ray._private.utils
@@ -143,3 +146,34 @@ async def async_wait_for_condition(
143146
if last_ex is not None:
144147
message += f" Last exception: {last_ex}"
145148
raise RuntimeError(message)
149+
150+
151+
@contextmanager
152+
def simulate_s3_bucket(
153+
port: int = 5002,
154+
region: str = "us-west-2",
155+
) -> Iterator[str]:
156+
"""Context manager that simulates an S3 bucket and yields the URI.
157+
158+
Args:
159+
port: The port of the localhost endpoint where S3 is being served.
160+
region: The S3 region.
161+
162+
Yields:
163+
str: URI for the simulated S3 bucket.
164+
"""
165+
from moto.server import ThreadedMotoServer
166+
167+
old_env = os.environ
168+
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
169+
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
170+
os.environ["AWS_SECURITY_TOKEN"] = "testing"
171+
os.environ["AWS_SESSION_TOKEN"] = "testing"
172+
173+
s3_server = f"http://localhost:{port}"
174+
server = ThreadedMotoServer(port=port)
175+
server.start()
176+
url = f"s3://{uuid.uuid4().hex}?region={region}&endpoint_override={s3_server}"
177+
yield url
178+
server.stop()
179+
os.environ = old_env

python/ray/_private/test_utils.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,50 +1774,6 @@ def no_resource_leaks_excluding_node_resources():
17741774
return cluster_resources == available_resources
17751775

17761776

1777-
@contextmanager
1778-
def simulate_storage(
1779-
storage_type: str,
1780-
root: Optional[str] = None,
1781-
port: int = 5002,
1782-
region: str = "us-west-2",
1783-
):
1784-
"""Context that simulates a given storage type and yields the URI.
1785-
1786-
Args:
1787-
storage_type: The storage type to simiulate ("fs" or "s3")
1788-
root: Root directory of the URI to return (e.g., s3 bucket name)
1789-
port: The port of the localhost endpoint where s3 is being served (s3 only)
1790-
region: The s3 region (s3 only)
1791-
"""
1792-
if storage_type == "fs":
1793-
if root is None:
1794-
with tempfile.TemporaryDirectory() as d:
1795-
yield "file://" + d
1796-
else:
1797-
yield "file://" + root
1798-
elif storage_type == "s3":
1799-
from moto.server import ThreadedMotoServer
1800-
1801-
old_env = os.environ
1802-
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
1803-
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
1804-
os.environ["AWS_SECURITY_TOKEN"] = "testing"
1805-
os.environ["AWS_SESSION_TOKEN"] = "testing"
1806-
1807-
root = root or uuid.uuid4().hex
1808-
s3_server = f"http://localhost:{port}"
1809-
server = ThreadedMotoServer(port=port)
1810-
server.start()
1811-
url = f"s3://{root}?region={region}&endpoint_override={s3_server}"
1812-
yield url
1813-
server.stop()
1814-
1815-
os.environ = old_env
1816-
1817-
else:
1818-
raise NotImplementedError(f"Unknown storage type: {storage_type}")
1819-
1820-
18211777
def job_hook(**kwargs):
18221778
"""Function called by reflection by test_cli_integration."""
18231779
cmd = " ".join(kwargs["entrypoint"])

python/ray/train/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
import ray
7-
from ray._private.test_utils import simulate_storage
7+
from ray._common.test_utils import simulate_s3_bucket
88
from ray.cluster_utils import Cluster
99

1010
# Trigger pytest hook to automatically zip test cluster logs to archive dir on failure
@@ -127,7 +127,7 @@ def mock_s3_bucket_uri():
127127

128128
port = 5002
129129
region = "us-west-2"
130-
with simulate_storage("s3", port=port, region=region) as s3_uri:
130+
with simulate_s3_bucket(port=port, region=region) as s3_uri:
131131
s3 = boto3.client(
132132
"s3", region_name=region, endpoint_url=f"http://localhost:{port}"
133133
)

python/ray/train/tests/test_new_persistence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import ray
1616
from ray import train, tune
17-
from ray._private.test_utils import simulate_storage
17+
from ray._common.test_utils import simulate_s3_bucket
1818
from ray.air._internal.uri_utils import URI
1919
from ray.air.constants import EXPR_RESULT_FILE
2020
from ray.train._checkpoint import Checkpoint
@@ -40,7 +40,7 @@ class TestConstants:
4040
def mock_s3_bucket_uri():
4141
port = 5002
4242
region = "us-west-2"
43-
with simulate_storage("s3", port=port, region=region) as s3_uri:
43+
with simulate_s3_bucket(port=port, region=region) as s3_uri:
4444
import boto3
4545

4646
s3 = boto3.client(

python/ray/train/v2/tests/test_persistence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import ray
1616
import ray.train
17-
from ray._private.test_utils import simulate_storage
17+
from ray._common.test_utils import simulate_s3_bucket
1818
from ray.air._internal.uri_utils import URI
1919
from ray.train import (
2020
Checkpoint,
@@ -41,7 +41,7 @@ class TestConstants:
4141
def mock_s3_bucket_uri():
4242
port = 5002
4343
region = "us-west-2"
44-
with simulate_storage("s3", port=port, region=region) as s3_uri:
44+
with simulate_s3_bucket(port=port, region=region) as s3_uri:
4545
import boto3
4646

4747
s3 = boto3.client(

python/ray/tune/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import boto3
44
import pytest
55

6-
from ray._private.test_utils import simulate_storage
6+
from ray._common.test_utils import simulate_s3_bucket
77
from ray.air._internal.uri_utils import URI
88

99
# Trigger pytest hook to automatically zip test cluster logs to archive dir on failure
@@ -17,7 +17,7 @@
1717
def mock_s3_bucket_uri():
1818
port = 5002
1919
region = "us-west-2"
20-
with simulate_storage("s3", port=port, region=region) as s3_uri:
20+
with simulate_s3_bucket(port=port, region=region) as s3_uri:
2121
s3 = boto3.client(
2222
"s3", region_name=region, endpoint_url=f"http://localhost:{port}"
2323
)

0 commit comments

Comments
 (0)