-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename cli to jina_cli (#4890)
* chore: fix readme * chore: fix readme * chore: fix dockerignore * fix: #4845 * style: fix overload and cli autocomplete * fix: cicd export cli Co-authored-by: Jina Dev Bot <dev-bot@jina.ai>
- Loading branch information
Showing
24 changed files
with
276 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
!*requirements.txt | ||
!README.md | ||
!MANIFEST.in | ||
!cli/** | ||
!jina_cli/** | ||
!daemon/** | ||
!docarray/** | ||
!fastentrypoints.py |
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 |
---|---|---|
|
@@ -39,7 +39,7 @@ area/docker: | |
- ./.dockerignore | ||
|
||
area/cli: | ||
- cli/**/* | ||
- jina_cli/**/* | ||
|
||
area/docarray: | ||
- docarray/**/* | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
if __name__ == '__main__': | ||
from cli import main | ||
from jina_cli import main | ||
|
||
main() |
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,68 @@ | ||
import json | ||
|
||
from jina import Flow, __version__ | ||
from jina.jaml import JAML | ||
from jina.logging.predefined import default_logger | ||
from jina.schemas import get_full_schema | ||
from jina_cli.export import api_to_dict | ||
|
||
|
||
def export_kubernetes(args): | ||
"""Export to k8s yaml files | ||
:param args: args from CLI | ||
""" | ||
Flow.load_config(args.flowpath).to_kubernetes_yaml( | ||
output_base_path=args.outpath, k8s_namespace=args.k8s_namespace | ||
) | ||
|
||
|
||
def export_docker_compose(args): | ||
"""Export to Docker compose yaml files | ||
:param args: args from CLI | ||
""" | ||
|
||
Flow.load_config(args.flowpath).to_docker_compose_yaml( | ||
output_path=args.outpath, network_name=args.network_name | ||
) | ||
|
||
|
||
def export_flowchart(args): | ||
"""Export to flowchart file | ||
:param args: args from CLI | ||
""" | ||
Flow.load_config(args.flowpath).plot( | ||
args.outpath, vertical_layout=args.vertical_layout | ||
) | ||
|
||
|
||
def export_schema(args): | ||
"""Export to JSON Schemas | ||
:param args: args from CLI | ||
""" | ||
if args.yaml_path: | ||
dump_api = api_to_dict() | ||
for yp in args.yaml_path: | ||
f_name = (yp % __version__) if '%s' in yp else yp | ||
with open(f_name, 'w', encoding='utf8') as fp: | ||
JAML.dump(dump_api, fp) | ||
default_logger.info(f'API is exported to {f_name}') | ||
|
||
if args.json_path: | ||
dump_api = api_to_dict() | ||
for jp in args.json_path: | ||
f_name = (jp % __version__) if '%s' in jp else jp | ||
with open(f_name, 'w', encoding='utf8') as fp: | ||
json.dump(dump_api, fp, sort_keys=True) | ||
default_logger.info(f'API is exported to {f_name}') | ||
|
||
if args.schema_path: | ||
dump_api = get_full_schema() | ||
for jp in args.schema_path: | ||
f_name = (jp % __version__) if '%s' in jp else jp | ||
with open(f_name, 'w', encoding='utf8') as fp: | ||
json.dump(dump_api, fp, sort_keys=True) | ||
default_logger.info(f'API is exported to {f_name}') |
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,162 @@ | ||
"""Argparser module for the export API""" | ||
|
||
from jina.parsers.base import set_base_parser | ||
from jina.parsers.helper import _chf | ||
|
||
|
||
def set_export_parser(parser=None): | ||
"""Set the parser for exporting | ||
:param parser: the parser configure | ||
:return: the parser | ||
""" | ||
if not parser: | ||
parser = set_base_parser() | ||
|
||
spp = parser.add_subparsers( | ||
dest='export', | ||
description='use `%(prog)-8s [sub-command] --help` ' | ||
'to get detailed information about each sub-command', | ||
required=True, | ||
) | ||
|
||
set_export_flowchart_parser( | ||
spp.add_parser( | ||
'flowchart', | ||
help='Export a Flow YAML file to a flowchart', | ||
formatter_class=_chf, | ||
) | ||
) | ||
|
||
set_export_k8s_parser( | ||
spp.add_parser( | ||
'kubernetes', | ||
help='Export a Flow YAML file to a Kubernetes YAML bundle', | ||
formatter_class=_chf, | ||
) | ||
) | ||
|
||
set_export_docker_compose_parser( | ||
spp.add_parser( | ||
'docker-compose', | ||
help='Export a Flow YAML file to a Docker Compose YAML file', | ||
formatter_class=_chf, | ||
) | ||
) | ||
|
||
set_export_schema_parser( | ||
spp.add_parser( | ||
'schema', | ||
help='Export Jina Executor & Flow API to JSONSchema files', | ||
formatter_class=_chf, | ||
) | ||
) | ||
|
||
return parser | ||
|
||
|
||
def mixin_base_io_parser(parser): | ||
"""Add basic IO parsing args | ||
:param parser: the parser configure | ||
""" | ||
parser.add_argument( | ||
'flowpath', type=str, metavar='INPUT', help='The input file path of a Flow YAML' | ||
) | ||
parser.add_argument( | ||
'outpath', | ||
type=str, | ||
metavar='OUTPUT', | ||
help='The output path', | ||
) | ||
|
||
|
||
def set_export_docker_compose_parser(parser=None): | ||
"""Set the parser for the flow chart export | ||
:param parser: an optional existing parser to build upon | ||
:return: the parser | ||
""" | ||
if not parser: | ||
parser = set_base_parser() | ||
|
||
mixin_base_io_parser(parser) | ||
|
||
parser.add_argument( | ||
'--network_name', | ||
type=str, | ||
help='The name of the network that will be used by the deployment name.', | ||
) | ||
return parser | ||
|
||
|
||
def set_export_k8s_parser(parser=None): | ||
"""Set the parser for the flow chart export | ||
:param parser: an optional existing parser to build upon | ||
:return: the parser | ||
""" | ||
if not parser: | ||
parser = set_base_parser() | ||
|
||
mixin_base_io_parser(parser) | ||
|
||
parser.add_argument( | ||
'--k8s-namespace', | ||
type=str, | ||
help='The name of the k8s namespace to set for the configurations. If None, the name of the Flow will be used.', | ||
) | ||
return parser | ||
|
||
|
||
def set_export_flowchart_parser(parser=None): | ||
"""Set the parser for the flow chart export | ||
:param parser: an optional existing parser to build upon | ||
:return: the parser | ||
""" | ||
if not parser: | ||
parser = set_base_parser() | ||
|
||
mixin_base_io_parser(parser) | ||
|
||
parser.add_argument( | ||
'--vertical-layout', | ||
action='store_true', | ||
default=False, | ||
help='If set, then the flowchart is rendered vertically from top to down.', | ||
) | ||
return parser | ||
|
||
|
||
def set_export_schema_parser(parser=None): | ||
"""Set the parser for the API export | ||
:param parser: an optional existing parser to build upon | ||
:return: the parser | ||
""" | ||
if not parser: | ||
parser = set_base_parser() | ||
|
||
parser.add_argument( | ||
'--yaml-path', | ||
type=str, | ||
nargs='*', | ||
metavar='PATH', | ||
help='The YAML file path for storing the exported API', | ||
) | ||
parser.add_argument( | ||
'--json-path', | ||
type=str, | ||
nargs='*', | ||
metavar='PATH', | ||
help='The JSON file path for storing the exported API', | ||
) | ||
parser.add_argument( | ||
'--schema-path', | ||
type=str, | ||
nargs='*', | ||
metavar='PATH', | ||
help='The JSONSchema file path for storing the exported API', | ||
) | ||
return parser |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.