Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose programmatic equivalent of CLI commands #1854

Merged
merged 48 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d030306
export `covalent_start` and `covalent_stop`
araghukas Nov 20, 2023
290481f
check server stopped
araghukas Nov 20, 2023
fab67cd
update changelog
araghukas Nov 20, 2023
46b395c
move commands to main namespace
araghukas Nov 20, 2023
f706575
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2023
afb9aad
improve docstrings
araghukas Nov 21, 2023
9eba72a
fix `covalent_is_running` to return bool
araghukas Nov 21, 2023
a1004e3
reorder `covalent_is_running` conditions
araghukas Nov 21, 2023
8622ac3
`quiet` mode to suppress stdout; more docstrings
araghukas Nov 21, 2023
7e4117b
use poll function instead of while loop
araghukas Nov 21, 2023
58a48b2
explain package
araghukas Nov 21, 2023
bd367cb
add api docs entry
araghukas Nov 21, 2023
c784193
update api docs
araghukas Nov 21, 2023
e430db5
restore import from `._programmatic`
araghukas Nov 21, 2023
10cd66e
update api docs
araghukas Nov 21, 2023
4cbe7d3
Merge branch 'develop' into 1853-programmatic-cli-commands
araghukas Nov 21, 2023
e18852d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2023
8ea150a
add test for new functions
araghukas Nov 21, 2023
e023bde
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2023
60f9ca2
add test for `covalent_is_running`
araghukas Nov 21, 2023
112c5f4
removing covalent's dependency on dispatcher
kessler-frost Nov 21, 2023
d7c6c05
ignore pip reqs in new package
araghukas Nov 21, 2023
2b4d947
refactor docstrings
araghukas Nov 21, 2023
bca8bc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2023
7d18fa4
update docs
araghukas Nov 21, 2023
f6e0e3a
revert api docs
araghukas Nov 21, 2023
d54ee56
include 'Returns' in docstrings so maybe docs will render 🤷 pls
araghukas Nov 21, 2023
ea1c6a6
remove useless 'Returns' from docstrings 🤦‍♂️
araghukas Nov 21, 2023
d7ef463
try autofunction refs to main namespace instead
araghukas Nov 21, 2023
8b107eb
revert using main namespace refs
araghukas Nov 21, 2023
de284c1
add more logging and edit messages
araghukas Nov 22, 2023
13bfdb6
refactor hanging tests
araghukas Nov 22, 2023
f308f8e
refactor tests into functional tests
araghukas Nov 22, 2023
e7709ea
Revert "refactor tests into functional tests"
araghukas Nov 23, 2023
cf6f286
create global var for timeout
araghukas Nov 23, 2023
07fa34e
use mock start and stop commands
araghukas Nov 23, 2023
11247fc
Merge branch 'develop' into 1853-programmatic-cli-commands
kessler-frost Nov 23, 2023
73ac729
Merge branch 'develop' into 1853-programmatic-cli-commands
kessler-frost Nov 23, 2023
3294979
Merge branch 'develop' into 1853-programmatic-cli-commands
kessler-frost Nov 23, 2023
f7220c6
Merge branch 'develop' into 1853-programmatic-cli-commands
kessler-frost Nov 23, 2023
61c27b8
renamed server check function and added import error check tests
kessler-frost Nov 24, 2023
243982b
None wasn't an acceptable value to redirect_stdout
kessler-frost Nov 24, 2023
0e1e07c
refactor to use subprocess
araghukas Nov 24, 2023
ea53935
refactor as multiple tests w/ patched start/stop
araghukas Nov 24, 2023
cf6e48a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 24, 2023
0491ab1
add nopycln inside new tests
araghukas Nov 24, 2023
2b7f126
renaming things a bit
kessler-frost Nov 24, 2023
1daecca
Merge branch 'develop' into 1853-programmatic-cli-commands
kessler-frost Nov 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
quiet mode to suppress stdout; more docstrings
araghukas committed Nov 21, 2023
commit 8622ac30c24408b00457dd57f4b22aac9ea9ca48
38 changes: 30 additions & 8 deletions covalent/_programmatic/commands.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
# limitations under the License.

"""Functions providing programmatic access to Covalent CLI commands."""
import contextlib
import sys
import time
from typing import Any, Dict, Optional

@@ -29,10 +31,21 @@
app_log = logger.app_log


def _call_cli_command(func: click.Command, **kwargs: Dict[str, Any]) -> Any:
"""Call the CLI command ``func`` with the specified kwargs."""
ctx = click.Context(func)
ctx.invoke(func, **kwargs)
def _call_cli_command(
cmd: click.Command,
*,
quiet: bool = False,
**kwargs: Dict[str, Any]
) -> None:
"""Call a CLI command with the specified kwargs.

Args:
func: The CLI command to call.
quiet: Suppress stdout. Defaults to False.
"""
with contextlib.redirect_stdout(None if quiet else sys.stdout):
ctx = click.Context(cmd)
ctx.invoke(cmd, **kwargs)


def covalent_is_running() -> bool:
@@ -56,8 +69,11 @@ def covalent_start(
no_cluster: bool = False,
no_triggers: bool = False,
triggers_only: bool = False,
*,
quiet: bool = False,
) -> None:
"""Start the Covalent server. Wrapper for the `covalent start` CLI command.
This function returns immediately if the local Covalent server is already running.

Args:
develop: Start local server in develop mode. Defaults to False.
@@ -69,6 +85,7 @@ def covalent_start(
no_cluster: Start server without Dask cluster. Defaults to False.
no_triggers: Start server without a triggers server. Defaults to False.
triggers_only: Start only the triggers server. Defaults to False.
quiet: Suppress stdout. Defaults to False.
"""
if covalent_is_running():
return
@@ -85,19 +102,24 @@ def covalent_start(
"triggers_only": triggers_only,
}

_call_cli_command(start, **kwargs)
_call_cli_command(start, quiet=quiet, **kwargs)

while not covalent_is_running():
app_log.debug("Waiting for Covalent Server to be to dispatch-ready...")
time.sleep(1)


def covalent_stop() -> None:
"""Stop the Covalent server. Wrapper for the `covalent stop` CLI command."""
def covalent_stop(*, quiet: bool = False) -> None:
"""Stop the Covalent server. Wrapper for the `covalent stop` CLI command.
This function returns immediately if the local Covalent server is not running.

Args:
quiet: Suppress stdout. Defaults to False.
"""
if not covalent_is_running():
santoshkumarradha marked this conversation as resolved.
Show resolved Hide resolved
return

_call_cli_command(stop)
_call_cli_command(stop, quiet=quiet)

while covalent_is_running():
app_log.debug("Waiting for Covalent Server to stop...")