mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 20:35:31 +08:00
[Projects] Add small tutorial for projects (#6641)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import argparse
|
||||
import click
|
||||
import copy
|
||||
import jsonschema
|
||||
@@ -386,6 +387,31 @@ def session_start(command, args, shell, name):
|
||||
runner.execute_command(run["command"], config)
|
||||
|
||||
|
||||
@session_cli.command(
|
||||
name="commands",
|
||||
help="Print available commands for sessions of this project.")
|
||||
def session_commands():
|
||||
project_definition = load_project_or_throw()
|
||||
print("Active project: " + project_definition.config["name"])
|
||||
print()
|
||||
|
||||
commands = project_definition.config["commands"]
|
||||
|
||||
for command in commands:
|
||||
print("Command \"{}\":".format(command["name"]))
|
||||
parser = argparse.ArgumentParser(
|
||||
command["name"], description=command.get("help"), add_help=False)
|
||||
params = command.get("params", [])
|
||||
for param in params:
|
||||
name = param.pop("name")
|
||||
if "type" in param:
|
||||
param.pop("type")
|
||||
parser.add_argument("--" + name, **param)
|
||||
help_string = parser.format_help()
|
||||
# Indent the help message by two spaces and print it.
|
||||
print("\n".join([" " + line for line in help_string.split("\n")]))
|
||||
|
||||
|
||||
@session_cli.command(
|
||||
name="execute",
|
||||
context_settings=dict(ignore_unknown_options=True, ),
|
||||
|
||||
@@ -9,7 +9,8 @@ from unittest.mock import patch, DEFAULT
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
from ray.projects.scripts import session_start, session_execute
|
||||
from ray.projects.scripts import (session_start, session_commands,
|
||||
session_execute)
|
||||
import ray
|
||||
|
||||
TEST_DIR = os.path.join(
|
||||
@@ -231,6 +232,17 @@ def test_session_create_multiple():
|
||||
assert result.exit_code == 1
|
||||
|
||||
|
||||
def test_session_commands():
|
||||
result, mock_calls, test_dir = run_test_project(
|
||||
"session-tests/commands-test", session_commands, [])
|
||||
|
||||
assert "This is the first parameter" in result.output
|
||||
assert "This is the second parameter" in result.output
|
||||
|
||||
assert 'Command "first"' in result.output
|
||||
assert 'Command "second"' in result.output
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Make subprocess happy in bazel.
|
||||
os.environ["LC_ALL"] = "en_US.UTF-8"
|
||||
|
||||
Reference in New Issue
Block a user