Skip to content

Commit

Permalink
feat: support key py_modules in root of the config.yml file (#46)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
floralatin committed Jul 11, 2022
1 parent 7cef20c commit 48c15c1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
8 changes: 6 additions & 2 deletions normalizer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions tests/cases/executor_5/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jtype: Executor5
py_modules:
- foo.py

7 changes: 7 additions & 0 deletions tests/cases/executor_5/foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from jina import Executor, requests

class Executor5(Executor):
@requests
def foo(self):
pass

2 changes: 2 additions & 0 deletions tests/cases/executor_6/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jtype: Executor6
py_modules: foo.py
7 changes: 7 additions & 0 deletions tests/cases/executor_6/foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from jina import Executor, requests

class Executor6(Executor):
@requests
def foo(self):
pass

10 changes: 8 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 48c15c1

Please sign in to comment.