Skip to content

Commit

Permalink
Add 'law luigid' sub cli.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Jun 6, 2024
1 parent 34ba133 commit bd0cd88
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/api/cli/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ law.cli
completion
config
software
quickstart
luigid
5 changes: 5 additions & 0 deletions docs/api/cli/luigid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
law.cli.luigid
==============

.. automodule:: law.cli.luigid
:members:
5 changes: 5 additions & 0 deletions docs/api/cli/quickstart.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
law.cli.quickstart
==================

.. automodule:: law.cli.quickstart
:members:
9 changes: 5 additions & 4 deletions law/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import law


progs = ["run", "index", "config", "software", "completion", "location", "quickstart"]
progs = ["run", "index", "config", "software", "completion", "location", "quickstart", "luigid"]


def run(argv=None):
Expand Down Expand Up @@ -51,13 +51,14 @@ def run(argv=None):
# argv that is passed to the prog execution when set
prog_argv = None

# parse args and dispatch execution, with "run" being a special case
# parse args and dispatch execution, considering some special cases
prog = argv[0] if argv else None
if prog == "run":
# only pass the prog and the task family to the parser
# and let luigi's parsing handle the rest downstream in execute
args = parser.parse_args(argv[:2])
prog_argv = ["law run"] + argv
elif prog == "luigid":
args = parser.parse_args(argv[:1])
prog_argv = ["law luigid"] + argv
else:
args = parser.parse_args(argv)

Expand Down
10 changes: 9 additions & 1 deletion law/cli/completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _law_complete() {
local index_file="${LAW_INDEX_FILE:-${law_home}/index}"

# common parameters
local common_params="run index config software completion location quickstart --help --version"
local common_params="run index config software completion location quickstart luigid --help --version"

# the current word
local cur="${COMP_WORDS[COMP_CWORD]}"
Expand Down Expand Up @@ -204,6 +204,14 @@ _law_complete() {
COMPREPLY=( $( compgen -W "$( echo ${words} )" -P "--" -- "${inp}" ) )
return "0"

# complete the "luigid" subcommand
elif [ "${sub_cmd}" = "luigid" ]; then
local words="help background pidfile logdir state-path address unix-socket port"
local inp="${cur##-}"
inp="${inp##-}"
COMPREPLY=( $( compgen -W "$( echo ${words} )" -P "--" -- "${inp}" ) )
return "0"

fi
}

Expand Down
42 changes: 42 additions & 0 deletions law/cli/luigid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# coding: utf-8

"""
"law luigid" cli subprogram.
"""


from law.config import Config


def setup_parser(sub_parsers):
"""
Sets up the command line parser for the *luigid* subprogram and adds it to *sub_parsers*.
This is identical to running ``luigid`` directly from the command line, but this also loads the
law config prior to starting the scheduler process and optionally syncrhonizes it with luigi's
config.
"""
parser = sub_parsers.add_parser(
"luigid",
prog="law luigid",
description="Starts the 'luigid' central scheduler.",
add_help=False,
)

parser.add_argument(
"arguments",
nargs="*",
help="luigid arguments",
)


def execute(args, argv):
"""
Initializes the law config object and executes the *luigid* subprogram with parsed commandline
*args*.
"""
# initialize the config
Config.instance()

# forward to luigid
from luigi.cmdline import luigid
luigid(argv[2:])
3 changes: 1 addition & 2 deletions law/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import os
import sys

from luigi.cmdline import luigi_run

from law.config import Config
from law.task.base import Task
from law.util import abort
Expand Down Expand Up @@ -90,6 +88,7 @@ def execute(args, argv):
abort("task '{}' not found".format(args.task_family))

# run luigi
from luigi.cmdline import luigi_run
sys.argv[0] += " run"
luigi_run([task_family] + argv[3:])

Expand Down

0 comments on commit bd0cd88

Please sign in to comment.