From 48c15c1ae04e581e7e1735c0230be0a120fa122f Mon Sep 17 00:00:00 2001 From: zhangkai Date: Mon, 11 Jul 2022 10:42:09 +0800 Subject: [PATCH] feat: support key py_modules in root of the config.yml file (#46) * feat: support key py_modules in config.yml file * fix: merge metas_py_modules and root_py_modules of the config.yml * fix: add test case into test_core * test: optimize test * fix: fix the test of core case 5 and 6 * fix: fix py_modules generation method and optimize test --- normalizer/core.py | 8 ++++++-- tests/cases/executor_5/config.yml | 4 ++++ tests/cases/executor_5/foo.py | 7 +++++++ tests/cases/executor_6/config.yml | 2 ++ tests/cases/executor_6/foo.py | 7 +++++++ tests/test_core.py | 10 ++++++++-- 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/cases/executor_5/config.yml create mode 100644 tests/cases/executor_5/foo.py create mode 100644 tests/cases/executor_6/config.yml create mode 100644 tests/cases/executor_6/foo.py diff --git a/normalizer/core.py b/normalizer/core.py index 56511f3..3cca030 100644 --- a/normalizer/core.py +++ b/normalizer/core.py @@ -396,7 +396,6 @@ def normalize( logger.debug(f'=> The environment variables: ') for k, v in env.items(): logger.debug('%20s: -> %20s' % (k, v)) - if not work_path.exists(): raise FileNotFoundError( f'The folder "{work_path}" does not exist, can not normalize' @@ -421,9 +420,14 @@ def normalize( if class_name is None: raise Exception('Not found jtype in config.yml') + + metas_py_modules = config.get('metas', {}).get('py_modules', None); + root_py_modules = config.get('py_modules', None) - py_modules = config.get('metas', {}).get('py_modules', None) + if metas_py_modules and root_py_modules: + raise Exception('The parameter py_modules can only be appear in one of metas and root in config.yml') + py_modules = metas_py_modules if metas_py_modules else root_py_modules if isinstance(py_modules, str): py_glob = [work_path.joinpath(py_modules)] elif isinstance(py_modules, list): diff --git a/tests/cases/executor_5/config.yml b/tests/cases/executor_5/config.yml new file mode 100644 index 0000000..bfcc1b8 --- /dev/null +++ b/tests/cases/executor_5/config.yml @@ -0,0 +1,4 @@ +jtype: Executor5 +py_modules: + - foo.py + \ No newline at end of file diff --git a/tests/cases/executor_5/foo.py b/tests/cases/executor_5/foo.py new file mode 100644 index 0000000..807c657 --- /dev/null +++ b/tests/cases/executor_5/foo.py @@ -0,0 +1,7 @@ +from jina import Executor, requests + +class Executor5(Executor): + @requests + def foo(self): + pass + diff --git a/tests/cases/executor_6/config.yml b/tests/cases/executor_6/config.yml new file mode 100644 index 0000000..1764c53 --- /dev/null +++ b/tests/cases/executor_6/config.yml @@ -0,0 +1,2 @@ +jtype: Executor6 +py_modules: foo.py diff --git a/tests/cases/executor_6/foo.py b/tests/cases/executor_6/foo.py new file mode 100644 index 0000000..55104d3 --- /dev/null +++ b/tests/cases/executor_6/foo.py @@ -0,0 +1,7 @@ +from jina import Executor, requests + +class Executor6(Executor): + @requests + def foo(self): + pass + diff --git a/tests/test_core.py b/tests/test_core.py index 0d0a5b6..fcdbcb6 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -54,6 +54,14 @@ def test_inspect_dummy_execs(): Path(__file__).parent / 'cases' / 'executor_4', Path(__file__).parent / 'cases' / 'executor_4.json', ), + ( + Path(__file__).parent / 'cases' / 'executor_5', + None, + ), + ( + Path(__file__).parent / 'cases' / 'executor_6', + None, + ), ( Path(__file__).parent / 'cases' / 'nested', Path(__file__).parent / 'cases' / 'nested.json', @@ -86,8 +94,6 @@ def test_get_executor_args(package_path, expected_path): assert executor == expected_executor else: core.normalize(package_path, dry_run=True) - - def test_prelude(): imports = [ deps.Package(name='tensorflow', version='2.5.0'),