Skip to content

Commit

Permalink
task runtime skeleton (#134)
Browse files Browse the repository at this point in the history
Initial skeleton of the local task runtime, with proofs of concept for docker container management, file path mapping, and I/O stdlib functions like `stdout()` and `write_lines()`.
  • Loading branch information
mlin committed May 24, 2019
1 parent e94850b commit 4895488
Show file tree
Hide file tree
Showing 11 changed files with 926 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ script:
- |
set -ex -o pipefail
make docker
docker run --env TRAVIS_JOB_ID=${TRAVIS_JOB_ID} --env TRAVIS_BRANCH=${TRAVIS_BRANCH} miniwdl coveralls
docker run --env TRAVIS_JOB_ID=${TRAVIS_JOB_ID} --env TRAVIS_BRANCH=${TRAVIS_BRANCH} miniwdl make sopretty
docker run --env TRAVIS_JOB_ID=${TRAVIS_JOB_ID} --env TRAVIS_BRANCH=${TRAVIS_BRANCH} -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp miniwdl bash -c "make sopretty && make && coveralls && make doc"
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ RUN bash -o pipefail -c "pip3 install --user -r <(cat /miniwdl/requirements.txt
# minor source change.
ADD . /miniwdl
WORKDIR /miniwdl
# Run the default make rule, which will trigger typechecking and tests.
ENV PYTHONPATH $PYTHONPATH:/root/.local/lib/python3.6
ENV PATH $PATH:/root/.local/bin
RUN make && make doc
# will trigger typechecking & tests:
CMD make
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ sopretty:
$(MAKE) pretty
@git diff --quiet || (echo "ERROR: source files were modified by black; please fix up this commit with 'make pretty'"; exit 1)

# run tests in a docker image
# build docker image with current source tree, poised to run tests e.g.:
# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp miniwdl
docker:
docker build -t miniwdl .

Expand Down
25 changes: 1 addition & 24 deletions WDL/Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def task(self, obj: WDL.Task) -> Any:
else:
assert isinstance(part, str)
command.append(part)
col_offset, command = _strip_leading_whitespace("".join(command))
col_offset, command = WDL._util.strip_leading_whitespace("".join(command))

# write out a temp file with this fake script
tfn = os.path.join(self._tmpdir, obj.name)
Expand Down Expand Up @@ -830,29 +830,6 @@ def _shellcheck_dummy_value(ty, pos):
return "x" * desired_length


def _strip_leading_whitespace(txt):
lines = txt.split("\n")

to_strip = None
for line in lines:
lsl = len(line.lstrip())
if lsl:
c = len(line) - lsl
assert c >= 0
if to_strip is None or to_strip > c:
to_strip = c
# TODO: do something about mixed tabs & spaces

if not to_strip:
return (0, txt)

for i, line_i in enumerate(lines):
if line_i.lstrip():
lines[i] = line_i[to_strip:]

return (to_strip, "\n".join(lines))


@a_linter
class MixedIndentation(Linter):
# Line of task command mixes tab and space indentation
Expand Down
3 changes: 2 additions & 1 deletion WDL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import errno
import inspect
from typing import List, Optional, Callable
from WDL import _parser, Error, Type, Value, Env, Expr, Tree, Walker, StdLib
from WDL import _util, _parser, Error, Type, Value, Env, Expr, Tree, Walker, StdLib
from WDL.Tree import Decl, StructTypeDef, Task, Call, Scatter, Conditional, Workflow, Document
import WDL.runtime

SourcePosition = Error.SourcePosition
SourceNode = Error.SourceNode
Expand Down
30 changes: 30 additions & 0 deletions WDL/_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# pyre-strict
# misc utility functions...

from typing import Tuple


def strip_leading_whitespace(txt: str) -> Tuple[int, str]:
# Given a multi-line string, determine the largest w such that each line
# begins with at least w whitespace characters. Return w and the string
# with w characters removed from the beginning of each line.
lines = txt.split("\n")

to_strip = None
for line in lines:
lsl = len(line.lstrip())
if lsl:
c = len(line) - lsl
assert c >= 0
if to_strip is None or to_strip > c:
to_strip = c
# TODO: do something about mixed tabs & spaces

if not to_strip:
return (0, txt)

for i, line_i in enumerate(lines):
if line_i.lstrip():
lines[i] = line_i[to_strip:]

return (to_strip, "\n".join(lines))
3 changes: 3 additions & 0 deletions WDL/runtime/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pyre-strict
import WDL.runtime.task
from WDL.runtime.task import run_local_task
Loading

0 comments on commit 4895488

Please sign in to comment.