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

docs: docstrings for parsers #1924

Merged
merged 7 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions jina/parsers/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Module containing the base parser for arguments of Jina."""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
import argparse

from .helper import _chf
Expand Down
1 change: 1 addition & 0 deletions jina/parsers/check.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for the check functions"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from .base import set_base_parser


Expand Down
1 change: 1 addition & 0 deletions jina/parsers/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Module for argparse for Client"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from .helper import add_arg_group
from ..enums import RequestType

Expand Down
1 change: 1 addition & 0 deletions jina/parsers/export_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for the export API"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from .base import set_base_parser


Expand Down
1 change: 1 addition & 0 deletions jina/parsers/flow.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for Flow"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
import argparse

from .base import set_base_parser
Expand Down
1 change: 1 addition & 0 deletions jina/parsers/helloworld.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Module for hello world argparser"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
import argparse

from pkg_resources import resource_filename
Expand Down
31 changes: 25 additions & 6 deletions jina/parsers/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Module for helper functions in the parser"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
import argparse
import os
import uuid
from typing import Tuple

_SHOW_ALL_ARGS = 'JINA_FULL_CLI' in os.environ
if _SHOW_ALL_ARGS:
Expand All @@ -12,8 +14,12 @@ def add_arg_group(parser, title):
return parser.add_argument_group(f'{title} arguments')


def UUIDString(astring):
"""argparse type to check if a string is a valid UUID string"""
def UUIDString(astring) -> str:
"""argparse type to check if a string is a valid UUID string
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved

:param astring: the string to check
:return: the string
"""
uuid.UUID(astring)
return astring

Expand Down Expand Up @@ -179,8 +185,12 @@ def _fill_text(self, text, width, indent):
lines = self._para_reformat(text, width)
return '\n'.join(lines)

def _indents(self, line):
"""Return line indent level and "sub_indent" for bullet list text."""
def _indents(self, line) -> Tuple[int, int]:
"""Return line indent level and "sub_indent" for bullet list text.

:param line: the line to check
:return: indentation of line and indentation of sub-items
"""
import re
indent = len(re.match(r'( *)', line).group(1))
list_match = re.match(r'( *)(([*\-+>]+|\w+\)|\w+\.) +)', line)
Expand All @@ -192,7 +202,11 @@ def _indents(self, line):
return (indent, sub_indent)

def _split_paragraphs(self, text):
"""Split text in to paragraphs of like-indented lines."""
"""Split text into paragraphs of like-indented lines.

:param text: the text input
:return: list of paragraphs
"""

import textwrap, re

Expand All @@ -218,7 +232,12 @@ def _split_paragraphs(self, text):
return paragraphs

def _para_reformat(self, text, width):
"""Reformat text, by paragraph."""
"""Format text, by paragraph.

:param text: the text to format
:param width: the width to apply
:return: the new text
"""

import textwrap

Expand Down
1 change: 1 addition & 0 deletions jina/parsers/hub/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for hub build"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from ..helper import add_arg_group
from ...enums import BuildTestLevel

Expand Down
1 change: 1 addition & 0 deletions jina/parsers/hub/list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for hub list"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from ..helper import add_arg_group


Expand Down
1 change: 1 addition & 0 deletions jina/parsers/hub/login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for hub login"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
import os

from ..helper import add_arg_group
Expand Down
1 change: 1 addition & 0 deletions jina/parsers/hub/new.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for hub new"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from ..helper import add_arg_group


Expand Down
1 change: 1 addition & 0 deletions jina/parsers/hub/pushpull.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for hub push & pull"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from ..helper import add_arg_group


Expand Down
5 changes: 5 additions & 0 deletions jina/parsers/logger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""Argparser module Loggers"""
from .base import set_base_parser


def set_logger_parser(parser=None):
"""
:param parser: the parser instance to which we add arguments
:return: the parser instance
"""
if not parser:
parser = set_base_parser()

Expand Down
1 change: 1 addition & 0 deletions jina/parsers/optimizer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for Optimizer"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from .base import set_base_parser
from .peapods.base import mixin_base_ppr_parser

Expand Down
2 changes: 2 additions & 0 deletions jina/parsers/peapods/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Base argparser module for Pea and Pod runtime"""
import argparse

from pkg_resources import resource_filename
Expand All @@ -8,6 +9,7 @@

def mixin_base_ppr_parser(parser):
"""Mixing in arguments required by pea/pod/runtime module into the given parser.
:param parser: the parser instance to which we add arguments
"""

gp = add_arg_group(parser, title='Essential')
Expand Down
2 changes: 2 additions & 0 deletions jina/parsers/peapods/pea.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for Pea runtimes"""
import argparse

from ..helper import add_arg_group, _SHOW_ALL_ARGS, KVAppendAction
Expand All @@ -7,6 +8,7 @@

def mixin_pea_parser(parser):
"""Mixing in arguments required by :class:`BasePea` into the given parser.
:param parser: the parser instance to which we add arguments
"""

gp = add_arg_group(parser, title='Pea')
Expand Down
5 changes: 4 additions & 1 deletion jina/parsers/peapods/pod.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Argparser module for Pod runtimes"""
import argparse

from jina.enums import PollingType, SchedulerType, PodRoleType
from jina.parsers.helper import add_arg_group, _SHOW_ALL_ARGS


def mixin_base_pod_parser(parser):
"""Mixing in arguments required by :class:`BasePod` into the given parser. """
"""Mixing in arguments required by :class:`BasePod` into the given parser.
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
:param parser: the parser instance to which we add arguments
"""
gp = add_arg_group(parser, title='Pod')

gp.add_argument('--uses-before', type=str,
Expand Down
5 changes: 4 additions & 1 deletion jina/parsers/peapods/runtimes/container.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Argparser module for container runtimes"""
from ...helper import add_arg_group, DockerKwargsAppendAction


def mixin_container_runtime_parser(parser):
"""Mixing in arguments required by :class:`ContainerRuntime` into the given parser."""
"""Mixing in arguments required by :class:`ContainerRuntime` into the given parser.
:param parser: the parser instance to which we add arguments
"""
gp = add_arg_group(parser, title='ContainerRuntime')

gp.add_argument('--uses-internal', type=str, default='BaseExecutor',
Expand Down
7 changes: 6 additions & 1 deletion jina/parsers/peapods/runtimes/distributed.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
"""Argparser module for distributed runtimes"""
from jina.helper import random_identity
from jina.parsers.helper import add_arg_group


def mixin_distributed_feature_parser(parser):
"""Mixing in arguments required by :class:`BasePod` into the given parser. """
"""Mixing in arguments required by :class:`BasePod` into the given parser.
:param parser: the parser instance to which we add arguments
"""

gp = add_arg_group(parser, title='Distributed')

gp.add_argument('--silent-remote-logs', action='store_true', default=False,
help='Do not display the streaming of remote logs on local console')

gp.add_argument('--upload-files', type=str, nargs='*', metavar='FILE',

help='''
The files on the host to be uploaded to the remote
workspace. This can be useful when your Pod has more
Expand Down
1 change: 1 addition & 0 deletions jina/parsers/peapods/runtimes/remote.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for remote runtime"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from ...helper import add_arg_group
from .... import __default_host__
from ....enums import CompressAlgo
Expand Down
6 changes: 4 additions & 2 deletions jina/parsers/peapods/runtimes/zed.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for ZED runtime"""
import argparse

from ...helper import add_arg_group, _SHOW_ALL_ARGS
Expand All @@ -7,7 +8,9 @@


def mixin_zed_runtime_parser(parser):
"""Mixing in arguments required by :class:`ZEDRuntime` into the given parser."""
"""Mixing in arguments required by :class:`ZEDRuntime` into the given parser.
:param parser: the parser instance to which we add arguments
"""

gp = add_arg_group(parser, title='ZEDRuntime')

Expand Down Expand Up @@ -80,4 +83,3 @@ def mixin_zed_runtime_parser(parser):
gp.add_argument('--num-part', type=int, default=0,
help='the number of messages expected from upstream, 0 and 1 means single part'
if _SHOW_ALL_ARGS else argparse.SUPPRESS)

5 changes: 4 additions & 1 deletion jina/parsers/peapods/runtimes/zmq.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Argparser module for ZMQ runtimes"""
import os

from ...helper import add_arg_group
from ....helper import random_port


def mixin_zmq_runtime_parser(parser):
"""Mixing in arguments required by :class:`ZMQRuntime` into the given parser."""
"""Mixing in arguments required by :class:`ZMQRuntime` into the given parser.
:param parser: the parser instance to which we add arguments
"""

gp = add_arg_group(parser, title='ZMQRuntime')
gp.add_argument('--port-ctrl', type=int, default=os.environ.get('JINA_CONTROL_PORT', random_port()),
Expand Down
1 change: 1 addition & 0 deletions jina/parsers/ping.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Argparser module for pinging"""
cristianmtr marked this conversation as resolved.
Show resolved Hide resolved
from .base import set_base_parser


Expand Down