Skip to content

Commit

Permalink
alpha/launch (#652)
Browse files Browse the repository at this point in the history
* 更新环境变量配置
* alpha版launch
* version: 0.3.15a0
  • Loading branch information
SAKURA-CAT authored Jul 25, 2024
1 parent ec274f1 commit 4e1d0d4
Show file tree
Hide file tree
Showing 27 changed files with 854 additions and 161 deletions.
14 changes: 10 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,32 @@
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": ["${file}"],
"args": [
"${file}"
],
"console": "integratedTerminal"
},
{
"name": "(跳过云)进行所有单元测试",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": ["test/unit"],
"args": [
"test/unit"
],
"console": "integratedTerminal",
"env": {
"TEST_CLOUD_SKIP": "true"
"is_skip_cloud_test": "true"
}
},
{
"name": "进行所有单元测试",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": ["test/unit"],
"args": [
"test/unit"
],
"console": "integratedTerminal"
},
// 打包命令
Expand Down
45 changes: 21 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

- [标准开发流程](#标准开发流程)
- [本地调试](#本地调试)
- [IDE 与插件](#IDE与插件)
- [配置 Python 环境](#配置python环境)
- [调试脚本](#调试脚本)
- [IDE 与插件](#IDE与插件)
- [配置 Python 环境](#配置python环境)
- [调试脚本](#调试脚本)
- [本地测试](#本地测试)
- [python 脚本调试](#python-脚本调试)
- [单元测试](#单元测试)
- [python 脚本调试](#python-脚本调试)
- [单元测试](#单元测试)

## 标准开发流程

1. 浏览 GitHub 上的[Issues](https://github.com/SwanHubX/SwanLab/issues),查看你愿意添加的功能或修复的错误,以及它们是否已被
Pull Request。

- 如果没有,请创建一个[新 Issue](https://github.com/SwanHubX/SwanLab/issues/new/choose)——这将帮助项目跟踪功能请求和错误报告,并确保不重复工作。
- 如果没有,请创建一个[新 Issue](https://github.com/SwanHubX/SwanLab/issues/new/choose)——这将帮助项目跟踪功能请求和错误报告,并确保不重复工作。

2. 如果你是第一次为开源项目贡献代码,请转到 [本项目首页](https://github.com/SwanHubX/SwanLab) 并单击右上角的"Fork"
按钮。这将创建你用于开发的仓库的个人副本。

- 将 Fork 的项目克隆到你的计算机,并添加指向`swanlab`项目的远程链接:
- 将 Fork 的项目克隆到你的计算机,并添加指向`swanlab`项目的远程链接:

```bash
git clone https://github.com/<your-username>/swanlab.git
Expand All @@ -33,20 +33,20 @@

3. 开发你的贡献

- 确保您的 Fork 与主存储库同步:
- 确保您的 Fork 与主存储库同步:

```bash
git checkout main
git pull upstream main
```

- 创建一个`git`分支,您将在其中发展您的贡献。为分支使用合理的名称,例如:
- 创建一个`git`分支,您将在其中发展您的贡献。为分支使用合理的名称,例如:

```bash
git checkout -b <username>/<short-dash-seperated-feature-description>
```

- 当你取得进展时,在本地提交你的改动,例如:
- 当你取得进展时,在本地提交你的改动,例如:

```bash
git add changed-file.py tests/test-changed-file.py
Expand All @@ -55,27 +55,27 @@

4. 发起贡献:

- [Github Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)
- 当您的贡献准备就绪后,将您的分支推送到 GitHub:
- [Github Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)
- 当您的贡献准备就绪后,将您的分支推送到 GitHub:

```bash
git push origin <username>/<short-dash-seperated-feature-description>
```

- 分支上传后, `GitHub`将打印一个 URL,用于将您的贡献作为拉取请求提交。在浏览器中打开该 URL,为您的拉取请求编写信息丰富的标题和详细描述,然后提交。
- 分支上传后, `GitHub`将打印一个 URL,用于将您的贡献作为拉取请求提交。在浏览器中打开该 URL,为您的拉取请求编写信息丰富的标题和详细描述,然后提交。

- 请将相关 Issue(现有 Issue 或您创建的 Issue)链接到您的 PR。请参阅 PR 页面的右栏。或者,在 PR
描述中提及“修复问题链接” - GitHub 将自动进行链接。
- 请将相关 Issue(现有 Issue 或您创建的 Issue)链接到您的 PR。请参阅 PR 页面的右栏。或者,在 PR
描述中提及“修复问题链接” - GitHub 将自动进行链接。

- 我们将审查您的贡献并提供反馈。要合并审阅者建议的更改,请将编辑提交到您的分支,然后再次推送到分支(无需重新创建拉取请求,它将自动跟踪对分支的修改),例如:
- 我们将审查您的贡献并提供反馈。要合并审阅者建议的更改,请将编辑提交到您的分支,然后再次推送到分支(无需重新创建拉取请求,它将自动跟踪对分支的修改),例如:

```bash
git add tests/test-changed-file.py
git commit -m "test(sdk): Add a test case to address reviewer feedback"
git push origin <username>/<short-dash-seperated-feature-description>
```

- 一旦您的拉取请求被审阅者批准,它将被合并到存储库的主分支中。
- 一旦您的拉取请求被审阅者批准,它将被合并到存储库的主分支中。

## 本地调试

Expand Down Expand Up @@ -141,7 +141,8 @@ Ps: 如果你不想使用 VSCode 进行开发,可以前往`.vscode/launch.json

### python 脚本调试

在完成你的改动后,可以将你用于测试的 python 脚本放到根目录或`test`文件夹下,然后通过[VSCode 脚本](#调试脚本)中的"运行当前文件"来运行你的 Python 测试脚本, 这样你的脚本运行将使用到已改动后的 swanlab。
在完成你的改动后,可以将你用于测试的 python 脚本放到根目录或`test`文件夹下,然后通过[VSCode 脚本](#调试脚本)中的"
运行当前文件"来运行你的 Python 测试脚本, 这样你的脚本运行将使用到已改动后的 swanlab。

### 单元测试

Expand All @@ -155,11 +156,7 @@ export PYTHONPATH=. && pytest test/unit
针对这种情况,请在本地根目录下创建`.env`文件,并填写如下环境变量配置:

```dotenv
TEST_CLOUD_SKIP=true
SWANLAB_RUNTIME=test-no-cloud
```

这样就可以跳过云端测试,只进行本地的部分功能测试。

> 事实上`TEST_CLOUD_SKIP`环境变量可以是任意值,只要存在即可跳过云端测试。
如果想进行完整的测试,请联系项目维护者,我们会提供测试环境的配置。
这样就可以跳过云端测试,只进行本地的部分功能测试。 如果想进行完整的测试,请联系项目维护者,我们会提供测试环境的配置。
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ click
pyyaml
psutil
pynvml
rich
22 changes: 22 additions & 0 deletions swanlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,27 @@

from .data.run.main import config
from .package import get_package_version
from .env import SwanLabEnv

# 设置默认环境变量
SwanLabEnv.set_default()
# 检查当前需要检查的环境变量
SwanLabEnv.check()

__version__ = get_package_version()

__all__ = [
"login",
"init",
"log",
"finish",
"Audio",
"Image",
"Text",
"Run",
"State",
"get_run",
"get_config",
"config",
"__version__",
]
8 changes: 3 additions & 5 deletions swanlab/api/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ def input_api_key(
def code_login(api_key: str) -> LoginInfo:
"""
代码内登录,此时会覆盖本地token文件
Parameters
----------
api_key : str
用户api_key
:param api_key: 用户的api_key
:return: 登录信息
:raises ValidationError: 登录失败
"""
tip = "Waiting for the swanlab cloud response."
login_info: LoginInfo = FONT.loading(tip, login_by_key, args=(api_key,), interval=0.5)
Expand Down
10 changes: 10 additions & 0 deletions swanlab/api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,19 @@ def get(self, url: str, params: dict = None) -> dict:
get请求
"""
url = self.base_url + url
self.__before_request()
resp = self.__session.get(url, params=params)
return decode_response(resp)

def patch(self, url: str, data: dict = None) -> Union[dict, str]:
"""
patch请求
"""
url = self.base_url + url
self.__before_request()
resp = self.__session.patch(url, json=data)
return decode_response(resp)

def __get_cos(self):
cos = self.get(f"/project/{self.groupname}/{self.projname}/runs/{self.exp_id}/sts")
self.__cos = CosClient(cos)
Expand Down
1 change: 1 addition & 0 deletions swanlab/cli/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
from .auth import login, logout
from .dashboard import watch
from .converter import convert
from .task import task
26 changes: 26 additions & 0 deletions swanlab/cli/commands/task/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
@DATE: 2024/7/17 17:16
@File: __init__.py.py
@IDE: pycharm
@Description:
启动!
beta版
"""
from .launch import launch
from .list import list
import click

__all__ = ["task"]


@click.group()
def task():
pass


# noinspection PyTypeChecker
task.add_command(launch)
# noinspection PyTypeChecker
task.add_command(list)
Loading

0 comments on commit 4e1d0d4

Please sign in to comment.