# openxlab-cli
## Getting started
### 代码结构
```
├─openxlab
│ ├─config 存放通用配置
│ ├─demo 给出的一个demo,模型中心,应用中心可以创建自己的文件夹
│ ├─types 通用参数定义
│ ├─utils 存放通用方法
│ ├─xlab 主站逻辑
```
### 架构说明
types 中定义定义命令基类
- sub_command_list 填入下一级命令对应的类定义
- add_args 用于添加当前命令的参数 --xxx
- take_action 用于定义当前命令的行为,未实现默认使用 argparse 的 help
命令继承基类实现,通过 sub_command_list 实现多级子命令
### 安装依赖环境
```
python -m pip install .
```
### 本地测试
```
python -m openxlab.cli
python -m openxlab.cli demo help
python -m openxlab.cli demo upload
```
### testpypi 联调
```
修改 config -> version.py 的版本 +1
pip install build
打包, 命令将生成一个 dist 目录
python -m build
本地安装
pip install .\dist\openxlab-0.0.7-py3-none-any.whl
# 上传 pip 包到 test pypi
twine upload --repository testpypi dist/*
# 从 test pypi 下载
pip install -i https://test.pypi.org/simple/ openxlab==0.0.1
从 test pypi 更新
pip install -i https://test.pypi.org/simple/ -U openxlab
```
### ak和sk的设置
设置ak,sk的有一下几种方法,任选一种即可:
1. 本地使用python -m openxlab.cli config命令调试,按照提示输入对应的access key和secret access key。完成后会在~/.openxlab目录下生成config.json文件,格式如下:
```json
{
"ak": "xxx",
"sk": "xxx"
}
```
2. 直接在~/.openxlab目录下创建对应的config.json文件,格式如上。
3. 设置环境变量。可以将access key设置到名为OPENXLAB_AK的环境变量下,secret access key设置到名为OPENXLAB_SK的环境变量下。
### token的获取
在设置好ak和sk之后,业务方可以调用openxlab.xlab.handler.user_token.get_jwt方法获得token。
```python
def get_jwt(ak=None, sk=None):
return get_token(ak, sk).jwt
```
该方法拥有ak和sk两个可选参数,允许业务方调用该方法时传递ak和sk。ak和sk生效的优先级如下:
```
get_jwt方法中的ak和sk参数(如果不为空) > ~/.openxlab/config.json文件 > OPENXLAB_AK和OPENXLAB_SK环境变量。
```
如果上面三者都为空,则在调用get_jwt方法时会抛出异常如下:
```python
ValueError("Local config must not be empty before get token via api. "
"Please use the 'openxlab config' command to set the config")
```
get_jwt方法调用成功后,会在~/.openxlab目录下生成token.json文件,格式如下:
```json
{
"expiration": "2023-05-16 16:29:03",
"jwt": "Bearer eyJxxx",
"refresh_expiration": "2023-05-23 15:29:03",
"refresh_time": "2023-05-16 15:29:03",
"refresh_token": "Bearer eyJxxx",
"sso_uid": "xxx"
}
```
# Change Log
## v0.1.0
- Release the initial version
Raw data
{
"_id": null,
"home_page": "",
"name": "openxlab-test",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "ai,openxlab-test",
"author": "Openxlab Contributors",
"author_email": "openxlab@example.com",
"download_url": "https://files.pythonhosted.org/packages/5c/7d/117fa90bbcb32c0bd89b32faf76c3647eeb1875d2f24c14ef6ea8fee84e0/openxlab_test-0.0.26.tar.gz",
"platform": null,
"description": "# openxlab-cli\n\n## Getting started\n\n### \u4ee3\u7801\u7ed3\u6784\n\n```\n\u251c\u2500openxlab\n\u2502 \u251c\u2500config \u5b58\u653e\u901a\u7528\u914d\u7f6e\n\u2502 \u251c\u2500demo \u7ed9\u51fa\u7684\u4e00\u4e2ademo\uff0c\u6a21\u578b\u4e2d\u5fc3\uff0c\u5e94\u7528\u4e2d\u5fc3\u53ef\u4ee5\u521b\u5efa\u81ea\u5df1\u7684\u6587\u4ef6\u5939\n\u2502 \u251c\u2500types \u901a\u7528\u53c2\u6570\u5b9a\u4e49\n\u2502 \u251c\u2500utils \u5b58\u653e\u901a\u7528\u65b9\u6cd5\n\u2502 \u251c\u2500xlab \u4e3b\u7ad9\u903b\u8f91\n```\n\n### \u67b6\u6784\u8bf4\u660e\n\ntypes \u4e2d\u5b9a\u4e49\u5b9a\u4e49\u547d\u4ee4\u57fa\u7c7b\n\n- sub_command_list \u586b\u5165\u4e0b\u4e00\u7ea7\u547d\u4ee4\u5bf9\u5e94\u7684\u7c7b\u5b9a\u4e49\n- add_args \u7528\u4e8e\u6dfb\u52a0\u5f53\u524d\u547d\u4ee4\u7684\u53c2\u6570 --xxx\n- take_action \u7528\u4e8e\u5b9a\u4e49\u5f53\u524d\u547d\u4ee4\u7684\u884c\u4e3a\uff0c\u672a\u5b9e\u73b0\u9ed8\u8ba4\u4f7f\u7528 argparse \u7684 help\n\n\u547d\u4ee4\u7ee7\u627f\u57fa\u7c7b\u5b9e\u73b0\uff0c\u901a\u8fc7 sub_command_list \u5b9e\u73b0\u591a\u7ea7\u5b50\u547d\u4ee4\n\n### \u5b89\u88c5\u4f9d\u8d56\u73af\u5883\n\n```\npython -m pip install .\n```\n\n### \u672c\u5730\u6d4b\u8bd5\n\n```\n python -m openxlab.cli\n python -m openxlab.cli demo help \n python -m openxlab.cli demo upload\n```\n\n### testpypi \u8054\u8c03\n\n```\n\u4fee\u6539 config -> version.py \u7684\u7248\u672c +1\n\npip install build\n\n\u6253\u5305\uff0c \u547d\u4ee4\u5c06\u751f\u6210\u4e00\u4e2a dist \u76ee\u5f55\npython -m build\n\n\u672c\u5730\u5b89\u88c5\npip install .\\dist\\openxlab-0.0.7-py3-none-any.whl\n\n# \u4e0a\u4f20 pip \u5305\u5230 test pypi\ntwine upload --repository testpypi dist/*\n\n# \u4ece test pypi \u4e0b\u8f7d\npip install -i https://test.pypi.org/simple/ openxlab==0.0.1\n\n\u4ece test pypi \u66f4\u65b0\npip install -i https://test.pypi.org/simple/ -U openxlab\n```\n\n### ak\u548csk\u7684\u8bbe\u7f6e\n\n\u8bbe\u7f6eak\uff0csk\u7684\u6709\u4e00\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff0c\u4efb\u9009\u4e00\u79cd\u5373\u53ef\uff1a\n\n1. \u672c\u5730\u4f7f\u7528python -m openxlab.cli config\u547d\u4ee4\u8c03\u8bd5\uff0c\u6309\u7167\u63d0\u793a\u8f93\u5165\u5bf9\u5e94\u7684access key\u548csecret access key\u3002\u5b8c\u6210\u540e\u4f1a\u5728~/.openxlab\u76ee\u5f55\u4e0b\u751f\u6210config.json\u6587\u4ef6\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a\n\n ```json\n {\n \"ak\": \"xxx\",\n \"sk\": \"xxx\"\n }\n ```\n\n2. \u76f4\u63a5\u5728~/.openxlab\u76ee\u5f55\u4e0b\u521b\u5efa\u5bf9\u5e94\u7684config.json\u6587\u4ef6\uff0c\u683c\u5f0f\u5982\u4e0a\u3002\n3. \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u53ef\u4ee5\u5c06access key\u8bbe\u7f6e\u5230\u540d\u4e3aOPENXLAB_AK\u7684\u73af\u5883\u53d8\u91cf\u4e0b\uff0csecret access key\u8bbe\u7f6e\u5230\u540d\u4e3aOPENXLAB_SK\u7684\u73af\u5883\u53d8\u91cf\u4e0b\u3002\n\n### token\u7684\u83b7\u53d6\n\n\u5728\u8bbe\u7f6e\u597dak\u548csk\u4e4b\u540e\uff0c\u4e1a\u52a1\u65b9\u53ef\u4ee5\u8c03\u7528openxlab.xlab.handler.user_token.get_jwt\u65b9\u6cd5\u83b7\u5f97token\u3002\n\n```python\ndef get_jwt(ak=None, sk=None):\n return get_token(ak, sk).jwt\n```\n\n\u8be5\u65b9\u6cd5\u62e5\u6709ak\u548csk\u4e24\u4e2a\u53ef\u9009\u53c2\u6570\uff0c\u5141\u8bb8\u4e1a\u52a1\u65b9\u8c03\u7528\u8be5\u65b9\u6cd5\u65f6\u4f20\u9012ak\u548csk\u3002ak\u548csk\u751f\u6548\u7684\u4f18\u5148\u7ea7\u5982\u4e0b\uff1a\n\n```\nget_jwt\u65b9\u6cd5\u4e2d\u7684ak\u548csk\u53c2\u6570(\u5982\u679c\u4e0d\u4e3a\u7a7a\uff09 > ~/.openxlab/config.json\u6587\u4ef6 > OPENXLAB_AK\u548cOPENXLAB_SK\u73af\u5883\u53d8\u91cf\u3002 \n```\n\n\u5982\u679c\u4e0a\u9762\u4e09\u8005\u90fd\u4e3a\u7a7a\uff0c\u5219\u5728\u8c03\u7528get_jwt\u65b9\u6cd5\u65f6\u4f1a\u629b\u51fa\u5f02\u5e38\u5982\u4e0b\uff1a\n\n```python\nValueError(\"Local config must not be empty before get token via api. \"\n \"Please use the 'openxlab config' command to set the config\")\n```\n\nget_jwt\u65b9\u6cd5\u8c03\u7528\u6210\u529f\u540e\uff0c\u4f1a\u5728~/.openxlab\u76ee\u5f55\u4e0b\u751f\u6210token.json\u6587\u4ef6\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a\n\n```json\n{\n \"expiration\": \"2023-05-16 16:29:03\",\n \"jwt\": \"Bearer eyJxxx\",\n \"refresh_expiration\": \"2023-05-23 15:29:03\",\n \"refresh_time\": \"2023-05-16 15:29:03\",\n \"refresh_token\": \"Bearer eyJxxx\",\n \"sso_uid\": \"xxx\"\n}\n```\n# Change Log\n\n\n## v0.1.0 \n\n- Release the initial version\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "openxlab tools",
"version": "0.0.26",
"project_urls": {
"repository": "https://github.com/xxx/xxxx"
},
"split_keywords": [
"ai",
"openxlab-test"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "303e79bd10b5a072de3d60d1a96a835a630bd2bb7ed0731cc8ba7b623044a1b3",
"md5": "4349e5108c5f4121a14ce26d818d1b8a",
"sha256": "930a54e86141cd92f0415798e878a3852697bd03788dd9d2d3da71d49eaa5bc3"
},
"downloads": -1,
"filename": "openxlab_test-0.0.26-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4349e5108c5f4121a14ce26d818d1b8a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 297897,
"upload_time": "2023-12-21T12:33:08",
"upload_time_iso_8601": "2023-12-21T12:33:08.204771Z",
"url": "https://files.pythonhosted.org/packages/30/3e/79bd10b5a072de3d60d1a96a835a630bd2bb7ed0731cc8ba7b623044a1b3/openxlab_test-0.0.26-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5c7d117fa90bbcb32c0bd89b32faf76c3647eeb1875d2f24c14ef6ea8fee84e0",
"md5": "bf051247dc609549667c4cb02254f05f",
"sha256": "d36deb5e0178720ed5ce596c70dad5749e2dd58eda0d01a573415e4f3f0532a2"
},
"downloads": -1,
"filename": "openxlab_test-0.0.26.tar.gz",
"has_sig": false,
"md5_digest": "bf051247dc609549667c4cb02254f05f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 271000,
"upload_time": "2023-12-21T12:33:10",
"upload_time_iso_8601": "2023-12-21T12:33:10.741823Z",
"url": "https://files.pythonhosted.org/packages/5c/7d/117fa90bbcb32c0bd89b32faf76c3647eeb1875d2f24c14ef6ea8fee84e0/openxlab_test-0.0.26.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-21 12:33:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "xxx",
"github_project": "xxxx",
"github_not_found": true,
"lcname": "openxlab-test"
}