Skip to content

Commit 35047fb

Browse files
author
zhanglei3
committed
Merge branch 'develop' into 'master'
新增模型本地服务器端口参数并在运行模型命令时尝试更新 docker 镜像 See merge request bge/bge-python-sdk!7
2 parents d30d728 + d8bcaa4 commit 35047fb

17 files changed

Lines changed: 157 additions & 77 deletions

.coverage

0 Bytes
Binary file not shown.

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# [0.3.0](https://gitlab.omgut.com/bge/bge-python-sdk/compare/v0.2.4...v0.3.0) (2022-04-22)
1+
## [0.3.2](https://gitlab.omgut.com/bge/bge-python-sdk/compare/v0.2.4...v0.3.2) (2022-06-07)
22

33

44
### Bug Fixes
55

6+
* 修复混淆代码打包错误的问题 ([592bc41](https://gitlab.omgut.com/bge/bge-python-sdk/commit/592bc4112a6ecc0c6c6b92036231fbbb22ba2274))
67
* 修复模型配置命令不输入模型编号无法进入下一步的问题 ([e942e02](https://gitlab.omgut.com/bge/bge-python-sdk/commit/e942e0271c25bb6cba5170c40ead5a6000702cf5))
78
* 专业级变异接口regions参数验证 ([56ab2c8](https://gitlab.omgut.com/bge/bge-python-sdk/commit/56ab2c812e6b7cf78534ba91884952081c57e3fb))
89
* regions参数改为列表传入 ([023554a](https://gitlab.omgut.com/bge/bge-python-sdk/commit/023554acdf471d45a9800753ab2f2e78addf5ed8))
@@ -16,7 +17,7 @@
1617
* 新增专业级变异接口 ([b753be0](https://gitlab.omgut.com/bge/bge-python-sdk/commit/b753be0b57f86d3e74431cbee226430ff6113c5d))
1718
* 增加模型代码混淆功能并使用 rich 增强命令行工具 ([44d83c6](https://gitlab.omgut.com/bge/bge-python-sdk/commit/44d83c6f71d6a3e511b5dc9f46790da2d9745ff8))
1819
* **command:** 增加 bge config list 命令 ([be7e542](https://gitlab.omgut.com/bge/bge-python-sdk/commit/be7e5428efee38026f83acd1d2f33c94b9761c54))
19-
20+
* **model:** 新增模型本地服务器端口参数并在运行模型命令时尝试更新 docker 镜像 ([d408a1c](https://gitlab.omgut.com/bge/bge-python-sdk/commit/d408a1cc4c185b3fb2e8df645c270af207943080))
2021

2122

2223
## [0.2.8](https://gitlab.omgut.com/bge/bge-python-sdk/compare/v0.2.4...v0.2.8) (2022-04-18)

bgesdk/management/commands/model.py

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
from datetime import datetime
1616
from posixpath import join, exists, isdir, relpath
17-
from rich.live import Live
1817
from rich.prompt import Prompt
19-
from rich.table import Table
2018
from time import sleep
2119
from uuid import uuid4
2220

@@ -59,14 +57,12 @@
5957
def handler(event, context):
6058
logging.debug(event)
6159
event = json.loads(event)
62-
biosample_id = event['biosample_id']
6360
access_token = event['access_token']
6461
params = event['params']
6562
return json.dumps({
6663
"model_code": 0,
6764
"model_msg": "success",
6865
"model_data": {
69-
'biosample_id': biosample_id,
7066
'params': params,
7167
'sdk': {
7268
'version': bgesdk.__version__
@@ -158,6 +154,18 @@ def handler(event, context):
158154
ZIP_COMPRESSION = zipfile.ZIP_DEFLATED
159155

160156

157+
class TestServerPortAction(argparse.Action):
158+
159+
def __call__(self, parser, namespace, values, option_string=None):
160+
print(namespace)
161+
if not namespace.test and values:
162+
parser.error(
163+
'argument -p/--port: only allowed with argument -t/--test'
164+
)
165+
else:
166+
namespace.port = values
167+
168+
161169
class Command(BaseCommand):
162170

163171
order = 5
@@ -243,6 +251,15 @@ def add_arguments(self, parser):
243251
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
244252
help='启动本地 HTTP 测试服务器'
245253
)
254+
start_p.add_argument(
255+
'-p',
256+
'--port',
257+
default=TEST_SERVER_PORT,
258+
type=int,
259+
choices=range(1,65536),
260+
metavar="[1-65535]",
261+
help='服务器监听端口'
262+
)
246263
start_p.set_defaults(method=self.start_model, parser=start_p)
247264

248265
expfs_p = model_subparsers.add_parser(
@@ -286,7 +303,7 @@ def add_arguments(self, parser):
286303
help='调用线上稳定版模型。'
287304
)
288305
group = run_p.add_mutually_exclusive_group()
289-
group.add_argument(
306+
draft_a = group.add_argument(
290307
'-d',
291308
'--draft',
292309
default=False,
@@ -300,6 +317,18 @@ def add_arguments(self, parser):
300317
action="store_true",
301318
help='调用本地启动的测试服务器运行模型。'
302319
)
320+
group_2 = run_p.add_mutually_exclusive_group()
321+
group_2.add_argument(
322+
'-p',
323+
'--port',
324+
default=TEST_SERVER_PORT,
325+
type=int,
326+
action=TestServerPortAction,
327+
choices=range(1,65536),
328+
metavar="[1-65535]",
329+
help='服务器监听端口'
330+
)
331+
group_2._group_actions.append(draft_a) # 禁止 -p 与 -d 参数同时提供
303332
group = run_p.add_mutually_exclusive_group()
304333
group.add_argument(
305334
'-a',
@@ -907,9 +936,12 @@ def run_model(self, args):
907936
if draft is True:
908937
result = api.invoke_draft_model(model_id, **params)
909938
elif test is True:
939+
port = args.port
910940
api = API(
911-
access_token, endpoint=TEST_SERVER_ENDPOINT,
912-
timeout=DEFAULT_MODEL_TIMEOUT)
941+
access_token,
942+
endpoint='{}:{}'.format(TEST_SERVER_ENDPOINT, port),
943+
timeout=DEFAULT_MODEL_TIMEOUT
944+
)
913945
result = api.invoke_model(model_id, **params)
914946
else:
915947
result = api.invoke_model(model_id, **params)
@@ -972,7 +1004,7 @@ def install_deps(self, args):
9721004
output('[green]安装完成[/green]')
9731005

9741006
def start_model(self, args):
975-
output('Model debug server is starting ...')
1007+
port = args.port
9761008
home = get_home()
9771009
config_path = self.get_model_config_path()
9781010
config = get_config_parser(config_path)
@@ -992,13 +1024,16 @@ def start_model(self, args):
9921024
name=container_name,
9931025
volumes={home: { 'bind': WORKDIR, 'mode': 'rw' }},
9941026
stop_signal='SIGINT',
995-
ports={TEST_SERVER_PORT: TEST_SERVER_PORT},
1027+
ports={TEST_SERVER_PORT: port},
9961028
user=user,
9971029
detach=True,
9981030
stream=True,
9991031
auto_remove=True)
1032+
output('Model debug server is starting at {}...'.format(port))
10001033
output('Model {} was registered'.format(model_id))
1001-
output('\n\tURL: {}/model/{}'.format(TEST_SERVER_ENDPOINT, model_id))
1034+
output('\n\tURL: {}:{}/model/{}'.format(
1035+
TEST_SERVER_ENDPOINT, port, model_id
1036+
))
10021037
output('\tMethod: GET\n')
10031038
try:
10041039
logs = container.logs(stream=True, follow=True)
@@ -1048,9 +1083,22 @@ def _get_or_pull_image(self, client, image_name):
10481083
with console.status('拉取 docker 镜像中...', spinner='earth'):
10491084
return_code = os.system('docker pull {}'.format(image_name))
10501085
if return_code != 0:
1051-
output('[red]镜像拉取失败,请重试[/red]')
1086+
output(
1087+
'[red]拉取镜像 {} 失败,请重试[/red]'.format(image_name)
1088+
)
1089+
sys.exit(1)
1090+
output('[green]拉取镜像 {} 成功[/green]'.format(image_name))
1091+
else:
1092+
with console.status('更新 docker 镜像中...', spinner='earth'):
1093+
repository, tag = image_name.split(':')
1094+
try:
1095+
client.images.pull(repository, tag)
1096+
except docker.errors.APIError:
1097+
output(
1098+
'[red]更新镜像 {} 失败,请重试[/red]'.format(image_name)
1099+
)
10521100
sys.exit(1)
1053-
output('[green]镜像拉取成功[/green]')
1101+
output('[green]更新镜像 {} 成功[/green]'.format(image_name))
10541102

10551103
def _force_remove_container(self, client, container_name):
10561104
try:

bgesdk/management/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
MODEL_CONTAINER_PREFIX = 'bge-model-'
99
TEST_SERVER_PORT = 9999
10-
TEST_SERVER_ENDPOINT = 'http://0.0.0.0:{}'.format(TEST_SERVER_PORT)
10+
TEST_SERVER_ENDPOINT = 'http://0.0.0.0'
1111

1212
CLIENT_CREDENTIALS_CONFIGS = [
1313
('client_id', {

bgesdk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#-*- coding: utf-8 -*-
22

3-
__version__ = '0.3.1'
3+
__version__ = '0.3.2'

coverage.xml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" ?>
2-
<coverage version="6.3.2" timestamp="1650463561309" lines-valid="678" lines-covered="301" line-rate="0.444" branches-valid="148" branches-covered="67" branch-rate="0.4527" complexity="0">
2+
<coverage version="6.3.2" timestamp="1654591204080" lines-valid="678" lines-covered="320" line-rate="0.472" branches-valid="148" branches-covered="77" branch-rate="0.5203" complexity="0">
33
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
44
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
55
<sources>
66
<source>/home/zhanglei3/Desktop/dev/bge-python-sdk</source>
77
</sources>
88
<packages>
9-
<package name="bgesdk" line-rate="0.444" branch-rate="0.4527" complexity="0">
9+
<package name="bgesdk" line-rate="0.472" branch-rate="0.5203" complexity="0">
1010
<classes>
1111
<class name="__init__.py" filename="bgesdk/__init__.py" complexity="0" line-rate="1" branch-rate="1">
1212
<methods/>
@@ -624,7 +624,7 @@
624624
<line number="125" hits="1"/>
625625
</lines>
626626
</class>
627-
<class name="models.py" filename="bgesdk/models.py" complexity="0" line-rate="0.6029" branch-rate="0.6429">
627+
<class name="models.py" filename="bgesdk/models.py" complexity="0" line-rate="0.8824" branch-rate="1">
628628
<methods/>
629629
<lines>
630630
<line number="3" hits="1"/>
@@ -642,16 +642,16 @@
642642
<line number="73" hits="1"/>
643643
<line number="74" hits="1"/>
644644
<line number="75" hits="1"/>
645-
<line number="76" hits="0"/>
646-
<line number="77" hits="0"/>
645+
<line number="76" hits="1"/>
646+
<line number="77" hits="1"/>
647647
<line number="79" hits="1"/>
648-
<line number="81" hits="0"/>
649-
<line number="82" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="83,84"/>
650-
<line number="83" hits="0"/>
651-
<line number="84" hits="0"/>
648+
<line number="81" hits="1"/>
649+
<line number="82" hits="1" branch="true" condition-coverage="100% (2/2)"/>
650+
<line number="83" hits="1"/>
651+
<line number="84" hits="1"/>
652652
<line number="86" hits="1"/>
653-
<line number="87" hits="0"/>
654-
<line number="88" hits="0"/>
653+
<line number="87" hits="1"/>
654+
<line number="88" hits="1"/>
655655
<line number="91" hits="1"/>
656656
<line number="92" hits="1" branch="true" condition-coverage="100% (2/2)"/>
657657
<line number="93" hits="1"/>
@@ -665,17 +665,17 @@
665665
<line number="101" hits="1"/>
666666
<line number="103" hits="1"/>
667667
<line number="105" hits="1"/>
668-
<line number="106" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="107,111"/>
669-
<line number="107" hits="0"/>
670-
<line number="108" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="109,110"/>
671-
<line number="109" hits="0"/>
672-
<line number="110" hits="0"/>
673-
<line number="111" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="112,117"/>
674-
<line number="112" hits="0"/>
675-
<line number="113" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="114,115"/>
676-
<line number="114" hits="0"/>
677-
<line number="115" hits="0"/>
678-
<line number="117" hits="0"/>
668+
<line number="106" hits="1" branch="true" condition-coverage="100% (2/2)"/>
669+
<line number="107" hits="1"/>
670+
<line number="108" hits="1" branch="true" condition-coverage="100% (2/2)"/>
671+
<line number="109" hits="1"/>
672+
<line number="110" hits="1"/>
673+
<line number="111" hits="1" branch="true" condition-coverage="100% (2/2)"/>
674+
<line number="112" hits="1"/>
675+
<line number="113" hits="1" branch="true" condition-coverage="100% (2/2)"/>
676+
<line number="114" hits="1"/>
677+
<line number="115" hits="1"/>
678+
<line number="117" hits="1"/>
679679
<line number="119" hits="1"/>
680680
<line number="120" hits="1"/>
681681
<line number="122" hits="1"/>

htmlcov/d_823acf8b5a528c84_client_py.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htmlcov/d_823acf8b5a528c84_error_py.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htmlcov/d_823acf8b5a528c84_fs_py.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htmlcov/d_823acf8b5a528c84_http_py.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)