-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'law quickstart' cli, close #164.
- Loading branch information
Showing
11 changed files
with
176 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# coding: utf-8 | ||
|
||
""" | ||
"law quickstart" cli subprogram. | ||
""" | ||
|
||
|
||
import os | ||
import shutil | ||
|
||
from law.config import Config | ||
from law.util import law_src_path | ||
|
||
|
||
_cfg = Config.instance() | ||
|
||
|
||
def setup_parser(sub_parsers): | ||
""" | ||
Sets up the command line parser for the *quickstart* subprogram and adds it to *sub_parsers*. | ||
""" | ||
parser = sub_parsers.add_parser( | ||
"quickstart", | ||
prog="law quickstart", | ||
description="Quickstart to create a minimal project structure and law configuration.", | ||
) | ||
|
||
parser.add_argument( | ||
"--directory", | ||
"-d", | ||
help="the directory where the quickstart files are created; default: current directory", | ||
) | ||
parser.add_argument( | ||
"--no-tasks", | ||
action="store_true", | ||
help="skip creating tasks", | ||
) | ||
parser.add_argument( | ||
"--no-config", | ||
action="store_true", | ||
help="skip creating the law.cfg file", | ||
) | ||
parser.add_argument( | ||
"--no-setup", | ||
action="store_true", | ||
help="skip creating the setup.sh file", | ||
) | ||
|
||
|
||
def execute(args): | ||
""" | ||
Executes the *quickstart* subprogram with parsed commandline *args*. | ||
""" | ||
# get the quickstart directory | ||
qs_dir = law_src_path("templates", "quickstart") | ||
|
||
# prepare the directory if it does not exist yet | ||
out_dir = os.path.normpath(os.path.abspath(args.directory)) | ||
if not os.path.exists(out_dir): | ||
os.makedirs(out_dir) | ||
|
||
# copy tasks | ||
if not args.no_tasks: | ||
dst = os.path.join(out_dir, "my_package") | ||
shutil.copytree(os.path.join(qs_dir, "my_package"), dst) | ||
print("created {}".format(dst)) | ||
|
||
# copy config | ||
if not args.no_config: | ||
shutil.copy2(os.path.join(qs_dir, "law.cfg"), out_dir) | ||
print("created {}".format(os.path.join(out_dir, "law.cfg"))) | ||
|
||
# copy setup | ||
if not args.no_setup: | ||
shutil.copy2(os.path.join(qs_dir, "setup.sh"), out_dir) | ||
print("created {}".format(os.path.join(out_dir, "setup.sh"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
; law configuration example | ||
; for more info, see https://law.readthedocs.io/en/latest/config.html | ||
|
||
[modules] | ||
; the task modules that should be scanned by "law index" | ||
my_package.tasks | ||
|
||
|
||
[logging] | ||
; log levels mapped to python modules | ||
law: INFO | ||
luigi-interface: INFO | ||
gfal2: WARNING | ||
|
||
|
||
[luigi_core] | ||
; luigi core settings | ||
local_scheduler: True | ||
scheduler_host: 127.0.0.1 | ||
scheduler_port: 8080 | ||
parallel_scheduling: False | ||
no_lock: True | ||
log_level: INFO | ||
|
||
|
||
[luigi_scheduler] | ||
; luigi scheduler settings | ||
record_task_history: False | ||
remove_delay: 86400 | ||
retry_delay: 30 | ||
worker_disconnect_delay: 30 | ||
|
||
|
||
[luigi_worker] | ||
; luigi worker settings | ||
ping_interval: 20 | ||
wait_interval: 20 | ||
check_unfulfilled_deps: False | ||
cache_task_completion: True | ||
keep_alive: True | ||
force_multiprocessing: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# coding: utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# coding: utf-8 | ||
|
||
""" | ||
Location of tasks. | ||
""" | ||
|
||
import law | ||
|
||
|
||
class MyTask(law.Task): | ||
|
||
def output(self): | ||
return law.LocalFileTarget("$QS_DATA/output.txt") | ||
|
||
def run(self): | ||
self.output().dump("output of {!r}".format(self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Setup script for the quickstart template. Custom environment variables are prefixed with "QS_". | ||
|
||
action() { | ||
# local variables | ||
local shell_is_zsh="$( [ -z "${ZSH_VERSION}" ] && echo "false" || echo "true" )" | ||
local this_file="$( ${shell_is_zsh} && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )" | ||
local this_dir="$( cd "$( dirname "${this_file}" )" && pwd )" | ||
|
||
# global variables | ||
export QS_BASE="${this_dir}" | ||
export QS_DATA="${QS_BASE}/data" | ||
export PYTHONPATH="${QS_BASE}:${PYTHONPATH}" | ||
export LAW_HOME="${QS_BASE}/.law" | ||
export LAW_CONFIG_FILE="${QS_BASE}/law.cfg" | ||
|
||
# detect law | ||
if ! type type &> /dev/null; then | ||
>&2 echo "law not found, please adjust PATH and PYTHONPATH or 'pip install law'" | ||
else | ||
source "$( law completion )" "" | ||
fi | ||
} | ||
action |