Skip to content
Permalink
Browse files

feat(contrib): no need to give module name in advance

  • Loading branch information...
hanxiao committed Aug 19, 2019
1 parent 8e829b7 commit 7b5cc86a585c75965b224cb7f668cae2bb854885
Showing with 19 additions and 23 deletions.
  1. +6 −6 .drone-cd.yml
  2. +3 −3 .drone.yml
  3. +5 −8 gnes/helper.py
  4. +2 −2 gnes/service/grpc.py
  5. +3 −4 tests/test_contrib_module.py
@@ -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

@@ -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

@@ -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

@@ -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
@@ -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
@@ -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
@@ -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
@@ -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


@@ -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
@@ -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()
@@ -3,7 +3,6 @@

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


@unittest.SkipTest
@@ -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)
@@ -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:

0 comments on commit 7b5cc86

Please sign in to comment.
You can’t perform that action at this time.