Skip to content

Commit

Permalink
Keep Kedro-Docker plugin docstring from appearing in kedro -h (kedr…
Browse files Browse the repository at this point in the history
…o-org#56)

* Keep Kedro-Docker plugin docstring from appearing in `kedro -h`

Signed-off-by: Deepyaman Datta <deepyaman.datta@utexas.edu>
Signed-off-by: Yassine Alouini <yalouini@idmog.com>
  • Loading branch information
deepyaman authored and Yassine Alouini committed Feb 24, 2023
1 parent fa7b6bb commit 0b1aac5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
4 changes: 2 additions & 2 deletions kedro-docker/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ repos:
language: system
types: [file, python]
files: ^kedro-docker/tests/
entry: pylint --disable=missing-docstring,redefined-outer-name,no-self-use,invalid-name,protected-access,too-many-arguments
entry: pylint --disable=missing-docstring,redefined-outer-name,invalid-name,protected-access,too-many-arguments
stages: [commit]
# The same pylint checks, but running on all files. It's for manual run with `make lint`
- id: pylint-kedro_docker
Expand All @@ -68,7 +68,7 @@ repos:
language: system
pass_filenames: false
stages: [manual]
entry: pylint --disable=missing-docstring,redefined-outer-name,no-self-use,invalid-name,protected-access,too-many-arguments kedro-docker/tests
entry: pylint --disable=missing-docstring,redefined-outer-name,invalid-name,protected-access,too-many-arguments kedro-docker/tests
- id: isort
name: "Sort imports"
language: system
Expand Down
38 changes: 15 additions & 23 deletions kedro-docker/kedro_docker/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Kedro plugin for packaging a project with Docker """
# pylint: disable=unused-argument
import shlex
import subprocess
from pathlib import Path
Expand Down Expand Up @@ -39,13 +40,13 @@
DIVE_IMAGE = "wagoodman/dive:latest"


def _image_callback(ctx, param, value): # pylint: disable=unused-argument
def _image_callback(ctx, param, value):
image = value or Path.cwd().name
check_docker_image_exists(image)
return image


def _port_callback(ctx, param, value): # pylint: disable=unused-argument
def _port_callback(ctx, param, value):
if is_port_in_use(value):
raise KedroCliError(
f"Port {value} is already in use on the host. "
Expand Down Expand Up @@ -87,14 +88,11 @@ def _make_docker_args_option(**kwargs):


@click.group(name="Kedro-Docker")
def commands():
"""Kedro plugin for packaging a project with Docker"""
def commands(): # pylint: disable=missing-function-docstring
pass


@commands.group(
name="docker", context_settings=dict(help_option_names=["-h", "--help"])
)
@commands.group(name="docker", context_settings={"help_option_names": ["-h", "--help"]})
def docker_group():
"""Dockerize your Kedro project."""
# check that docker is running
Expand Down Expand Up @@ -196,18 +194,18 @@ def docker_build(


def _mount_info() -> Dict[str, Union[str, Tuple]]:
res = dict(
host_root=str(Path.cwd()),
container_root="/home/kedro_docker",
mount_volumes=DOCKER_DEFAULT_VOLUMES,
)
res = {
"host_root": str(Path.cwd()),
"container_root": "/home/kedro_docker",
"mount_volumes": DOCKER_DEFAULT_VOLUMES,
}
return res


@forward_command(docker_group, "run")
@_make_image_option(callback=_image_callback)
@_make_docker_args_option()
def docker_run(image, docker_args, args, **kwargs): # pylint: disable=unused-argument
def docker_run(image, docker_args, args, **kwargs):
"""Run the pipeline in the Docker container.
Any extra arguments unspecified in this help
are passed to `docker run` as is.
Expand All @@ -230,9 +228,7 @@ def docker_run(image, docker_args, args, **kwargs): # pylint: disable=unused-ar
@forward_command(docker_group, "ipython")
@_make_image_option(callback=_image_callback)
@_make_docker_args_option()
def docker_ipython(
image, docker_args, args, **kwargs
): # pylint: disable=unused-argument
def docker_ipython(image, docker_args, args, **kwargs):
"""Run ipython in the Docker container.
Any extra arguments unspecified in this help are passed to
`kedro ipython` command inside the container as is.
Expand Down Expand Up @@ -261,9 +257,7 @@ def docker_jupyter():
@_make_image_option(callback=_image_callback)
@_make_port_option()
@_make_docker_args_option()
def docker_jupyter_notebook(
docker_args, port, image, args, **kwargs
): # pylint: disable=unused-argument):
def docker_jupyter_notebook(docker_args, port, image, args, **kwargs):
"""Run jupyter notebook in the Docker container.
Any extra arguments unspecified in this help are passed to
`kedro jupyter notebook` command inside the container as is.
Expand Down Expand Up @@ -292,9 +286,7 @@ def docker_jupyter_notebook(
@_make_image_option(callback=_image_callback)
@_make_port_option()
@_make_docker_args_option()
def docker_jupyter_lab(
docker_args, port, image, args, **kwargs
): # pylint: disable=unused-argument):
def docker_jupyter_lab(docker_args, port, image, args, **kwargs):
"""Run jupyter lab in the Docker container.
Any extra arguments unspecified in this help are passed to
`kedro jupyter lab` command inside the container as is.
Expand All @@ -319,7 +311,7 @@ def docker_jupyter_lab(
@forward_command(docker_group, "cmd")
@_make_image_option(callback=_image_callback)
@_make_docker_args_option()
def docker_cmd(args, docker_args, image, **kwargs): # pylint: disable=unused-argument):
def docker_cmd(args, docker_args, image, **kwargs):
"""Run arbitrary command from ARGS in the Docker container.
If ARGS are not specified, this will invoke `kedro run` inside the container.
Expand Down
26 changes: 13 additions & 13 deletions kedro-docker/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ def test_make_container_name(args):
class TestComposeDockerRunArgs:
def test_args(self, tmp_path):
"""Test composing the arguments for `docker run` command"""
kwargs = dict(
host_root=str(tmp_path),
container_root="/home/kedro/projectname",
optional_args=[("-arg1", "projectname"), ("--arg4", "x4")],
required_args=[("-arg2", None), ("-arg3", "x2")],
user_args=["-arg1", "-arg2=y2", "-arg3", "y3"],
)
kwargs = {
"host_root": str(tmp_path),
"container_root": "/home/kedro/projectname",
"optional_args": [("-arg1", "projectname"), ("--arg4", "x4")],
"required_args": [("-arg2", None), ("-arg3", "x2")],
"user_args": ["-arg1", "-arg2=y2", "-arg3", "y3"],
}
expected = ["-arg2", "-arg3", "x2", "--arg4", "x4"] + kwargs["user_args"]
assert compose_docker_run_args(**kwargs) == expected

def test_mount(self, tmp_path):
"""Test composing the arguments with volumes to mount"""
host_root = tmp_path.resolve()
kwargs = dict(
host_root=str(host_root),
container_root="/home/kedro/projectname",
mount_volumes=("conf/local", "data", "logs"),
user_args=["-v", "y1"],
)
kwargs = {
"host_root": str(host_root),
"container_root": "/home/kedro/projectname",
"mount_volumes": ("conf/local", "data", "logs"),
"user_args": ["-v", "y1"],
}
expected = []
for _vol in kwargs["mount_volumes"]:
_mount_vol = f"{host_root / _vol}:{kwargs['container_root']}/{_vol}"
Expand Down

0 comments on commit 0b1aac5

Please sign in to comment.