def _get_run_args(print_args: bool = True): from jina.logging import default_logger from jina.parser import get_main_parser from jina.helper import colored parser = get_main_parser() if len(sys.argv) > 1: from argparse import _StoreAction, _StoreTrueAction args = parser.parse_args() if print_args: from pkg_resources import resource_filename p = parser._actions[-1].choices[sys.argv[1]] default_args = {a.dest: a.default for a in p._actions if isinstance(a, _StoreAction) or isinstance(a, _StoreTrueAction)} with open(resource_filename('jina', '/'.join(('resources', 'jina.logo')))) as fp: logo_str = fp.read() param_str = [] for k, v in sorted(vars(args).items()): j = f'{k.replace("_", "-"): >30.30} = {str(v):30.30}' if default_args.get(k, None) == v: param_str.append(' ' + j) else: param_str.append('🔧️ ' + colored(j, 'blue', 'on_yellow')) param_str = '\n'.join(param_str) default_logger.info(f'\n{logo_str}\n▶️ {" ".join(sys.argv)}\n{param_str}\n') return args else: parser.print_help() exit()
def plot(self, output: str = None, inline_display: bool = False) -> None: """ Visualize the Document recursively. :param output: a filename specifying the name of the image to be created, the suffix svg/jpg determines the file type of the output image :param inline_display: show image directly inside the Jupyter Notebook """ image_type = 'svg' if output and output.endswith('jpg'): image_type = 'jpg' url = self._mermaid_to_url(image_type) showed = False if inline_display: try: from IPython.display import display, Image display(Image(url=url)) showed = True except: # no need to panic users pass if output: download_mermaid_url(url, output) elif not showed: from jina.logging import default_logger default_logger.info(f'Document visualization: {url}')
def fork_hello(args): from_path = os.path.join(os.path.dirname(__file__), args.project) shutil.copytree(from_path, args.destination) full_path = os.path.abspath(args.destination) default_logger.success(f'{args.project} project is forked to {full_path}') default_logger.info( f''' To run the project: ~$ cd {full_path} ~$ python app.py ''' )
def export_api(args: 'Namespace'): from .export import api_to_dict from jina import __version__ from jina.logging import default_logger if args.yaml_path: for yp in args.yaml_path: f_name = (yp % __version__) if '%s' in yp else yp from jina.jaml import JAML with open(f_name, 'w', encoding='utf8') as fp: JAML.dump(api_to_dict(), fp) default_logger.info(f'API is exported to {f_name}') if args.json_path: for jp in args.json_path: f_name = (jp % __version__) if '%s' in jp else jp import json with open(f_name, 'w', encoding='utf8') as fp: json.dump(api_to_dict(), fp, sort_keys=True) default_logger.info(f'API is exported to {f_name}')
def export_api(args: 'Namespace'): import json from .export import api_to_dict from jina.jaml import JAML from jina import __version__ from jina.logging import default_logger from jina.schemas import get_full_schema 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}')
def log_search_results(resp) -> None: search_result = ''.join( [f'- {match.uri} \n' for match in resp.docs[0].matches]) logger.info( f'The search returned the following documents \n{search_result}')
def test_expand_env(self): print(expand_env_var('${PATH}-${AA}')) default_logger.info('aa') default_logger.success('aa')