Esempio n. 1
0
    def __init__(self, args: Optional[argparse.Namespace] = None, **kwargs):
        if args and isinstance(args, argparse.Namespace):
            self.args = args
        else:
            self.args = ArgNamespace.kwargs2namespace(kwargs, set_hub_parser())
        self.logger = JinaLogger(self.__class__.__name__, **vars(args))

        with ImportExtensions(required=True):
            import rich
            import cryptography
            import filelock

            assert rich  #: prevent pycharm auto remove the above line
            assert cryptography
            assert filelock
Esempio n. 2
0
def get_main_parser():
    """The main parser for Jina

    :return: the parser
    """
    from jina.parsers.base import set_base_parser
    from jina.parsers.create import set_new_project_parser
    from jina.parsers.export_api import set_export_api_parser
    from jina.parsers.flow import set_flow_parser
    from jina.parsers.helloworld import set_hello_parser
    from jina.parsers.helper import _SHOW_ALL_ARGS, _chf
    from jina.parsers.hubble import set_hub_parser
    from jina.parsers.ping import set_ping_parser

    # create the top-level parser
    parser = set_base_parser()

    sp = parser.add_subparsers(
        dest='cli',
        required=True,
    )

    set_hello_parser(
        sp.add_parser(
            'hello',
            help='Hello Jina!',
            description='Start hello world demos.',
            formatter_class=_chf,
        ))

    set_pod_parser(
        sp.add_parser(
            'executor',
            help='Start an Executor',
            description=
            'Start an Executor. Executor is how Jina processes Document.',
            formatter_class=_chf,
        ))

    set_flow_parser(
        sp.add_parser(
            'flow',
            description=
            'Start a Flow. Flow is how Jina streamlines and distributes Executors.',
            help='Start a Flow',
            formatter_class=_chf,
        ))

    set_ping_parser(
        sp.add_parser(
            'ping',
            help='Ping an Executor',
            description='Ping a Deployment and check its network connectivity.',
            formatter_class=_chf,
        ))

    set_new_project_parser(
        sp.add_parser(
            'new',
            help='Create a new Jina project',
            description=
            'Create a new Jina toy project with the predefined template.',
            formatter_class=_chf,
        ))

    set_gateway_parser(
        sp.add_parser(
            'gateway',
            description=
            'Start a Gateway that receives client Requests via gRPC/REST interface',
            **(dict(help='Start a Gateway')) if _SHOW_ALL_ARGS else {},
            formatter_class=_chf,
        ))

    set_hub_parser(
        sp.add_parser(
            'hub',
            help='Push/pull an Executor to/from Jina Hub',
            description='Push/Pull an Executor to/from Jina Hub',
            formatter_class=_chf,
        ))

    set_help_parser(
        sp.add_parser(
            'help',
            help='Show help text of a CLI argument',
            description='Show help text of a CLI argument',
            formatter_class=_chf,
        ))
    # Below are low-level / internal / experimental CLIs, hidden from users by default

    set_pod_parser(
        sp.add_parser(
            'pod',
            description='Start a Pod. '
            'You should rarely use this directly unless you '
            'are doing low-level orchestration',
            formatter_class=_chf,
            **(dict(help='Start a Pod')) if _SHOW_ALL_ARGS else {},
        ))

    set_deployment_parser(
        sp.add_parser(
            'deployment',
            description='Start a Deployment. '
            'You should rarely use this directly unless you '
            'are doing low-level orchestration',
            formatter_class=_chf,
            **(dict(help='Start a Deployment')) if _SHOW_ALL_ARGS else {},
        ))

    set_client_cli_parser(
        sp.add_parser(
            'client',
            description=
            'Start a Python client that connects to a remote Jina gateway',
            formatter_class=_chf,
            **(dict(help='Start a Client')) if _SHOW_ALL_ARGS else {},
        ))

    set_export_api_parser(
        sp.add_parser(
            'export-api',
            description=
            'Export Jina API to JSON/YAML file for 3rd party applications',
            formatter_class=_chf,
            **(dict(help='Export Jina API to file')) if _SHOW_ALL_ARGS else {},
        ))

    return parser