Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(contrib): no need to give module name in advance
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Aug 19, 2019
1 parent 8e829b7 commit 7b5cc86
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
12 changes: 6 additions & 6 deletions .drone-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ steps:
from_secret: BOT_URL
commands:
- export MSG_LINK=$DRONE_REPO_LINK
- export MSG_TITLE="✅🎁 All images is successfully updated!"
- export MSG_TITLE="✅🎁 All images are successfully delivered!"
- export MSG_CONTENT=""
- ./shell/push-wechatwork.sh

Expand Down Expand Up @@ -90,8 +90,8 @@ steps:
BOT_URL:
from_secret: BOT_URL
commands:
- export MSG_LINK=${DRONE_BUILD_LINK}
- export MSG_TITLE="⌛🗳 Start to build docker image for new release \`$DRONE_SOURCE_BRANCH\`(\`${DRONE_BUILD_NUMBER}\`)"
- export MSG_LINK="https://github.com/gnes-ai/gnes/tree/${DRONE_TAG}"
- export MSG_TITLE="⌛🗳 Start to build docker image for new release \`$DRONE_SOURCE_BRANCH\`(\`${DRONE_TAG}\`)"
- export MSG_CONTENT="click the link below to see the status"
- ./shell/push-wechatwork.sh

Expand Down Expand Up @@ -123,8 +123,8 @@ steps:
BOT_URL:
from_secret: BOT_URL
commands:
- export MSG_LINK=$DRONE_REPO_LINK
- export MSG_TITLE="✅🎁 All images is successfully updated!"
- export MSG_LINK="https://github.com/gnes-ai/gnes/tree/${DRONE_TAG}"
- export MSG_TITLE="✅🎁 All images are successfully delivered!"
- export MSG_CONTENT=""
- ./shell/push-wechatwork.sh

Expand All @@ -134,7 +134,7 @@ steps:
BOT_URL:
from_secret: BOT_URL
commands:
- export MSG_LINK=$DRONE_BUILD_LINK
- export MSG_LINK="https://github.com/gnes-ai/gnes/tree/${DRONE_TAG}"
- export MSG_TITLE="❌🎁 fail to build docker image!"
- export MSG_CONTENT="please inform [$DRONE_COMMIT_AUTHOR]($DRONE_COMMIT_AUTHOR_EMAIL) to modify and fix [\`$DRONE_SOURCE_BRANCH\`]($DRONE_COMMIT_LINK). click the link below to see the details."
- ./shell/push-wechatwork.sh
Expand Down
6 changes: 3 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
BOT_URL:
from_secret: BOT_URL
commands:
- export MSG_LINK=${DRONE_BUILD_LINK}
- export MSG_LINK="https://github.com/gnes-ai/gnes/pull/${DRONE_PULL_REQUEST}"
- export MSG_TITLE="⌛🏗 Start a CI pipeline \`$DRONE_SOURCE_BRANCH\`(\`${DRONE_BUILD_NUMBER}\`)"
- export MSG_CONTENT="submit by [$DRONE_COMMIT_AUTHOR]($DRONE_COMMIT_AUTHOR_EMAIL), click the link below to see the status"
- ./shell/push-wechatwork.sh
Expand Down Expand Up @@ -65,7 +65,7 @@ steps:
BOT_URL:
from_secret: BOT_URL
commands:
- export MSG_LINK=$DRONE_REPO_LINK
- export MSG_LINK="https://github.com/gnes-ai/gnes/pull/${DRONE_PULL_REQUEST}"
- export MSG_TITLE="✅😃 All tests passed, good job! \`$DRONE_SOURCE_BRANCH\`(\`${DRONE_BUILD_NUMBER}\`)"
- export MSG_CONTENT="the branch \`$DRONE_SOURCE_BRANCH\` submit by [$DRONE_COMMIT_AUTHOR]($DRONE_COMMIT_AUTHOR_EMAIL) is ready to merge to master"
- ./shell/push-wechatwork.sh
Expand All @@ -77,7 +77,7 @@ steps:
BOT_URL:
from_secret: BOT_URL
commands:
- export MSG_LINK=$DRONE_BUILD_LINK
- export MSG_LINK="https://github.com/gnes-ai/gnes/pull/${DRONE_PULL_REQUEST}"
- export MSG_TITLE="❌😥 CI pipeline \`$DRONE_SOURCE_BRANCH\`(\`${DRONE_BUILD_NUMBER}\`) is failed!"
- export MSG_CONTENT="please inform [$DRONE_COMMIT_AUTHOR]($DRONE_COMMIT_AUTHOR_EMAIL) to modify and fix [\`$DRONE_SOURCE_BRANCH\`]($DRONE_COMMIT_LINK). click the link below to see the details."
- ./shell/push-wechatwork.sh
Expand Down
13 changes: 5 additions & 8 deletions gnes/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,11 @@ def load_contrib_module():

if contrib:
default_logger.info(
'find a value in $GNES_CONTRIB_MODULE=%s, will try to load these modules from external' % contrib)
for c in contrib.split(','):
if ':' in c:
_name, _path = c.split(':')
m = PathImporter.add_modules(_path)
modules.append(m)
default_logger.info('successfully register %s class, you can now use it via yaml.' % m)
'find a value in $GNES_CONTRIB_MODULE=%s, will load them as external modules' % contrib)
for p in contrib.split(','):
m = PathImporter.add_modules(p)
modules.append(m)
default_logger.info('successfully registered %s class, you can now use it via yaml.' % m)
return modules


Expand All @@ -528,7 +526,6 @@ def add_modules(*paths):
if not os.path.exists(p):
raise FileNotFoundError('cannot import module from %s, file not exist')
module, spec = PathImporter._path_import(p)
sys.modules[spec.name] = module
return module

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions gnes/service/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def post_init(self):
options=[('grpc.max_send_message_length', self.args.max_message_size * 1024 * 1024),
('grpc.max_receive_message_length', self.args.max_message_size * 1024 * 1024)])

foo = PathImporter.add_modules(self.args.pb2_path, self.args.pb2_grpc_path)
m = PathImporter.add_modules(self.args.pb2_path, self.args.pb2_grpc_path)

# build stub
self.stub = getattr(foo, self.args.stub_name)(self.channel)
self.stub = getattr(m, self.args.stub_name)(self.channel)

def close(self):
self.channel.close()
Expand Down
7 changes: 3 additions & 4 deletions tests/test_contrib_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

dirname = os.path.dirname(__file__)
module_path = os.path.join(dirname, 'contrib', 'dummy_contrib.py')
cls_name = 'FooContribEncoder'


@unittest.SkipTest
Expand All @@ -20,7 +19,7 @@ def tearDown(self):
os.remove(self.dump_yaml_path)

def test_load_contrib(self):
os.environ['GNES_CONTRIB_MODULE'] = '%s:%s' % (cls_name, module_path)
os.environ['GNES_CONTRIB_MODULE'] = module_path
from gnes.encoder.base import BaseEncoder, BaseTextEncoder
a = BaseEncoder.load_yaml(self.yaml_path)
self.assertIsInstance(a, BaseTextEncoder)
Expand All @@ -32,14 +31,14 @@ def test_load_contrib(self):
self.assertEqual(b.encode([]), 'hello 531')

def test_bad_name(self):
os.environ['GNES_CONTRIB_MODULE'] = '%s:%s' % ('blah', module_path)
os.environ['GNES_CONTRIB_MODULE'] = module_path
try:
from gnes.encoder.base import BaseEncoder
except AttributeError:
pass

def test_bad_path(self):
os.environ['GNES_CONTRIB_MODULE'] = '%s:%s' % (cls_name, 'blah')
os.environ['GNES_CONTRIB_MODULE'] = 'blah'
try:
from gnes.encoder.base import BaseEncoder
except AttributeError:
Expand Down

0 comments on commit 7b5cc86

Please sign in to comment.