From 999f4ff0e10608974e72516bb5a884bc4e07026a Mon Sep 17 00:00:00 2001 From: Leonid Shamis Date: Tue, 2 Aug 2022 15:39:09 -0700 Subject: [PATCH 1/4] Add example for scripting with cmd interface --- mrp/examples/16_script/README.md | 7 +++++++ mrp/examples/16_script/get_foo.py | 4 ++++ mrp/examples/16_script/launch.py | 12 ++++++++++++ mrp/examples/16_script/msetup.py | 27 +++++++++++++++++++++++++++ mrp/examples/16_script/set_foo.py | 2 ++ mrp/src/mrp/cmd/up.py | 8 ++++++++ 6 files changed, 60 insertions(+) create mode 100644 mrp/examples/16_script/README.md create mode 100644 mrp/examples/16_script/get_foo.py create mode 100644 mrp/examples/16_script/launch.py create mode 100644 mrp/examples/16_script/msetup.py create mode 100644 mrp/examples/16_script/set_foo.py diff --git a/mrp/examples/16_script/README.md b/mrp/examples/16_script/README.md new file mode 100644 index 0000000000..f19cf3ce7c --- /dev/null +++ b/mrp/examples/16_script/README.md @@ -0,0 +1,7 @@ +# Example 16: Scripting msetup commands + +All `mrp` commands are available in both CLI and script form. + +In this example we demo a `launch.py` script that runs processes sequentially. + +Running launch.py brings up a `redis` server, runs a command to set `foo=bar`, then runs another command to print the value of `foo`. diff --git a/mrp/examples/16_script/get_foo.py b/mrp/examples/16_script/get_foo.py new file mode 100644 index 0000000000..16f7b21ce9 --- /dev/null +++ b/mrp/examples/16_script/get_foo.py @@ -0,0 +1,4 @@ +import redis +print("============") +print("foo =", redis.Redis().get("foo")) +print("============") diff --git a/mrp/examples/16_script/launch.py b/mrp/examples/16_script/launch.py new file mode 100644 index 0000000000..bd09c04de9 --- /dev/null +++ b/mrp/examples/16_script/launch.py @@ -0,0 +1,12 @@ +import mrp +import time + +mrp.import_msetup(".") + +mrp.cmd.up("redis") +time.sleep(0.5) + +mrp.cmd.up("set_foo", wait=True) +mrp.cmd.up("get_foo", attach=True, wait=True) + +mrp.cmd.down("redis", wait=True) diff --git a/mrp/examples/16_script/msetup.py b/mrp/examples/16_script/msetup.py new file mode 100644 index 0000000000..b080cdd98a --- /dev/null +++ b/mrp/examples/16_script/msetup.py @@ -0,0 +1,27 @@ +import mrp + +mrp.process( + name="redis", + runtime=mrp.Docker(image="redis"), +) + +mrp.process( + name="set_foo", + runtime=mrp.Conda( + channels=["conda-forge"], + dependencies=["redis-py"], + run_command=["python", "set_foo.py"], + ), +) + +mrp.process( + name="get_foo", + runtime=mrp.Conda( + channels=["conda-forge"], + dependencies=["redis-py"], + run_command=["python", "get_foo.py"], + ), +) + +if __name__ == "__main__": + mrp.main() diff --git a/mrp/examples/16_script/set_foo.py b/mrp/examples/16_script/set_foo.py new file mode 100644 index 0000000000..b02aa3ab6f --- /dev/null +++ b/mrp/examples/16_script/set_foo.py @@ -0,0 +1,2 @@ +import redis +redis.Redis().set("foo", "bar") diff --git a/mrp/src/mrp/cmd/up.py b/mrp/src/mrp/cmd/up.py index 3fc9c985c9..6ceb4b4e21 100644 --- a/mrp/src/mrp/cmd/up.py +++ b/mrp/src/mrp/cmd/up.py @@ -98,6 +98,7 @@ def callback(system_state): @click.option("-f", "--force/--noforce", is_flag=True, default=False) @click.option("--reset_logs", is_flag=True, default=False) @click.option("--attach", is_flag=True, default=False) +@click.option("--wait", is_flag=True, default=False) def cli( *cmd_procs, procs=None, @@ -109,6 +110,7 @@ def cli( force=False, reset_logs=False, attach=False, + wait=False, ): procs = procs or [] @@ -128,6 +130,9 @@ def cli( if attach and not run: raise ValueError("Cannot attach without running") + if wait and not run: + raise ValueError("Cannot wait without running") + down_existing(names, force) if reset_logs: @@ -185,3 +190,6 @@ def cli( if attach: mrp.cmd.attach(names[0]) + + if wait: + mrp.cmd.wait(*names) From 335186c0fd0660c5a8254467ac5e092cce1917c9 Mon Sep 17 00:00:00 2001 From: Leonid Shamis Date: Tue, 2 Aug 2022 15:42:26 -0700 Subject: [PATCH 2/4] black --- mrp/examples/16_script/get_foo.py | 1 + mrp/examples/16_script/set_foo.py | 1 + 2 files changed, 2 insertions(+) diff --git a/mrp/examples/16_script/get_foo.py b/mrp/examples/16_script/get_foo.py index 16f7b21ce9..f0e7ce4886 100644 --- a/mrp/examples/16_script/get_foo.py +++ b/mrp/examples/16_script/get_foo.py @@ -1,4 +1,5 @@ import redis + print("============") print("foo =", redis.Redis().get("foo")) print("============") diff --git a/mrp/examples/16_script/set_foo.py b/mrp/examples/16_script/set_foo.py index b02aa3ab6f..fcbbfcafc9 100644 --- a/mrp/examples/16_script/set_foo.py +++ b/mrp/examples/16_script/set_foo.py @@ -1,2 +1,3 @@ import redis + redis.Redis().set("foo", "bar") From cbf9fbc3e8a32f54de4db6dfe969f60fd40ecf61 Mon Sep 17 00:00:00 2001 From: Leonid Shamis Date: Tue, 2 Aug 2022 16:13:15 -0700 Subject: [PATCH 3/4] version bump --- mrp/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrp/setup.py b/mrp/setup.py index 15e5ddebf4..927b05edf4 100644 --- a/mrp/setup.py +++ b/mrp/setup.py @@ -4,7 +4,7 @@ setup( name="mrp", - version="1.0.0", + version="1.0.1", author="Leonid Shamis", package_dir={"": "src"}, packages=find_packages( From e2a2c7e5ce63d36397bfc56993a849709ffccd8b Mon Sep 17 00:00:00 2001 From: lshamis Date: Mon, 15 Aug 2022 14:16:52 -0700 Subject: [PATCH 4/4] Update setup.py bump version --- mrp/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrp/setup.py b/mrp/setup.py index 927b05edf4..857ede50e4 100644 --- a/mrp/setup.py +++ b/mrp/setup.py @@ -4,7 +4,7 @@ setup( name="mrp", - version="1.0.1", + version="1.0.3", author="Leonid Shamis", package_dir={"": "src"}, packages=find_packages(