Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d0166b9
delete swanlog
SAKURA-CAT Jun 15, 2024
b8bd459
Merge branch 'main' into feat/toolkit
SAKURA-CAT Jun 19, 2024
292c90c
delete Unused code
SAKURA-CAT Jun 19, 2024
d17233b
refactor code
SAKURA-CAT Jun 19, 2024
e1b09be
change import
SAKURA-CAT Jun 19, 2024
654a81a
use SwanLabSharedSettings
SAKURA-CAT Jun 19, 2024
07c01b1
update callback
SAKURA-CAT Jun 19, 2024
65496ad
update use swankit
SAKURA-CAT Jun 19, 2024
c66ba33
update base
SAKURA-CAT Jun 19, 2024
ebecfe4
delete file
SAKURA-CAT Jun 19, 2024
512b554
update test env
SAKURA-CAT Jun 19, 2024
cf21ad0
uppdate test
SAKURA-CAT Jun 19, 2024
f537c63
update package test
SAKURA-CAT Jun 19, 2024
7b68461
del data requirement
Zeyi-Lin Jun 20, 2024
861c78d
Revert "del data requirement"
SAKURA-CAT Jun 20, 2024
2b6efba
add test
SAKURA-CAT Jun 20, 2024
0785171
change dependence (#633)
SAKURA-CAT Jun 20, 2024
d4a409d
update package test
SAKURA-CAT Jun 20, 2024
7d0aba2
Merge branch 'main' into feat/toolkit
SAKURA-CAT Jun 21, 2024
b115280
fix test
SAKURA-CAT Jun 21, 2024
7096c47
Update CONTRIBUTING.md
SAKURA-CAT Jun 21, 2024
76f5d11
add version check
SAKURA-CAT Jun 22, 2024
c2af173
update env config
SAKURA-CAT Jun 22, 2024
0f4fcc7
Update pytest_sdk.py
SAKURA-CAT Jun 22, 2024
3ed5290
add skip test
SAKURA-CAT Jun 22, 2024
6a353d7
Update CONTRIBUTING.md
SAKURA-CAT Jun 22, 2024
3e8365b
Update CONTRIBUTING.md
SAKURA-CAT Jun 22, 2024
f3254cf
update version
SAKURA-CAT Jun 22, 2024
b6189c0
delete package_path
SAKURA-CAT Jun 23, 2024
77d86b3
Update pytest_package.py
SAKURA-CAT Jun 23, 2024
5e2ec00
update check
SAKURA-CAT Jun 23, 2024
595e942
Update create_experiment.py
SAKURA-CAT Jun 23, 2024
6385b27
Update conftest.py
SAKURA-CAT Jun 23, 2024
770e223
delete watch test
SAKURA-CAT Jun 23, 2024
86a0a89
update watch
SAKURA-CAT Jun 23, 2024
decd3a4
update version
SAKURA-CAT Jun 23, 2024
256379d
Update package.py
SAKURA-CAT Jun 23, 2024
60995ba
Update package.py
SAKURA-CAT Jun 23, 2024
9945217
change test
SAKURA-CAT Jun 23, 2024
b0f2b8f
Update CONTRIBUTING.md
Zeyi-Lin Jun 23, 2024
88680e2
Update CONTRIBUTING.md
Zeyi-Lin Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ package-lock.json
# test
temp/
tutils/config.json
tutils/package.mock.json
package.mock.json
.env

# playground
playground/
Expand Down
88 changes: 56 additions & 32 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
## 📦 目录

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

## 标准开发流程

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

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

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

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

Expand Down Expand Up @@ -50,8 +53,9 @@
git commit -m "feat(integrations): Add integration with the `awesomepyml` library"
```

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)发起贡献:
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:

```bash
Expand All @@ -60,11 +64,12 @@

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

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

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

```python
```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 All @@ -74,21 +79,22 @@

## 本地调试

### IDE与插件
### IDE 与插件

1. **使用VSCode作为你的开发IDE**
1. **使用 VSCode 作为你的开发 IDE**

SwanLab仓库已经配好了[VSCode](https://code.visualstudio.com/)的环境、插件与调试脚本(位于`.vscode`文件夹中),使用VSCode开发SwanLab会有最好的体验。
SwanLab 仓库已经配好了[VSCode](https://code.visualstudio.com/)的环境、插件与调试脚本(位于`.vscode`
文件夹中),使用 VSCode 开发 SwanLab 会有最好的体验。

2. **安装VSCode插件(可选)**
2. **安装 VSCode 插件(可选)**

用VSCode打开项目,进入 [扩展] ,在搜索框输入“@recommended”,会出现一系列推荐插件,推荐全部安装这些插件。
用 VSCode 打开项目,进入 [扩展] ,在搜索框输入“@recommended”,会出现一系列推荐插件,推荐全部安装这些插件。

![vscode-recommend](/readme_files/contribution_images/vscode_recommend.png)
![vscode-recommend](/readme_files/contribution_images/vscode_recommend.png)

### 配置Python环境
### 配置 Python 环境

SwanLab项目环境需要`python>=3.8`的支持。
SwanLab 项目环境需要`python>=3.8`的支持。

必须性的 python 依赖集中记录在项目根目录下的 `requirements.txt`。

Expand All @@ -97,6 +103,7 @@ SwanLab项目环境需要`python>=3.8`的支持。
```Bash
# swanlab所依赖的包
pip install -r requirements.txt
pip install -r requirements-media.txt
```

编译、开发、单元测试等工作需要使用以下命令额外安装依赖:
Expand All @@ -106,34 +113,51 @@ pip install -r requirements.txt
pip install -r requirements-dev.txt
```

## 调试脚本
### 调试脚本

1. **VSCode调试脚本**
1. **VSCode 调试脚本**

在 VSCode-运行和调试 中,项目配置好了一系列调试脚本:

![img](/readme_files/contribution_images/debug.png)

- **开启一个实验**:运行`test/create_experiment.py`脚本

- **运行当前文件**:使用配置好的Python环境运行你选中的文件
- **运行当前文件**:使用配置好的 Python 环境运行你选中的文件

- **测试当前文件**:使用 debug 模式测试你选中的文件

- **进行所有单元测试**:运行`test/unit`中的脚本对 swanlab 基础功能进行完整单元测试

- **构建项目**:打包项目为 whl 文件(pip 安装包格式)

Ps: 如果你不想使用 VSCode 进行开发,可以前往`.vscode/launch.json`,查看每个调试项对应的命令,了解其配置。

- **测试当前文件**:使用debug模式测试你选中的文件
## 本地测试

- **进行所有单元测试**:运行`test/unit`中的脚本对swanlab基础功能进行完整单元测试
进行测试的前提是你已经安装完毕所有的所需依赖。

- **构建项目**:打包项目为whl文件(pip安装包格式)
### python 脚本调试

Ps: 如果你不想使用VSCode进行开发,可以前往`.vscode/launch.json`,查看每个调试项对应的命令
在完成你的改动后,可以将你用于测试的 python 脚本放到根目录或`test`文件夹下,然后通过[VSCode 脚本](#调试脚本)中的"运行当前文件"来运行你的 Python 测试脚本, 这样你的脚本运行将使用到已改动后的 swanlab

## 调试流程
### 单元测试

<=================== 已过期,记得更改 ===================>
可以通过[VSCode 脚本](#调试脚本)或者在项目根目录下运行以下命令进行单元测试:

- 首次调试时,依次启动脚本:**开启一个实验 -> 后端开发 -> 前端开发**
```Bash
export PYTHONPATH=. && pytest test/unit
```

由于 swanlab 涉及与云端的交互,而云端部分是闭源的,所以如果你是第一次贡献代码,可能无法进行完整的测试。
针对这种情况,请在本地根目录下创建`.env`文件,并填写如下环境变量配置:

```dotenv
TEST_CLOUD_SKIP=true
```

- 第1次执行“开启一个实验”会在根目录下创建日志文件夹(默认为`swanlog`),“后端开发”将基于这个文件夹开启
这样就可以跳过云端测试,只进行本地的部分功能测试

- 后续调试时,依次启动脚本:**后端开发 -> 前端开发 -> 开启一个实验**
> 事实上`TEST_CLOUD_SKIP`环境变量可以是任意值,只要存在即可跳过云端测试。

- 因为已经存在日志文件夹,所以“后端开发”直接可以启用
如果想进行完整的测试,请联系项目维护者,我们会提供测试环境的配置
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build-backend = "hatchling.build"

[project]
name = "swanlab" # 项目名称
dynamic = ["version", "dependencies", "readme"] # 动态配置版本,依赖,可选依赖,readme
dynamic = ["version", "dependencies", "optional-dependencies", "readme"] # 动态配置版本,依赖,可选依赖,readme
description = "Python library for streamlined tracking and management of AI training processes." # 项目描述
license = "Apache-2.0" # 项目许可证
requires-python = ">=3.8" # python版本要求,我们只维护python3.8以上版本
Expand Down Expand Up @@ -56,6 +56,9 @@ pattern = ".*\"version\":\\s*\"(?P<version>[^\"]+)\""
[tool.hatch.metadata.hooks.requirements_txt]
filename = "requirements.txt"

[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
media = ["requirements-media.txt"] # pip install "swanlab[meida]"

[tool.hatch.metadata.hooks.fancy-pypi-readme] # 动态设置readme
content-type = "text/markdown"
fragments = [{ path = "README.md" }]
Expand Down Expand Up @@ -87,7 +90,7 @@ include = [
"/test", # 包含一些测试脚本,确保测试成功
"/README.md", # 包含readme
"/requirements.txt", # 包含依赖
"/requirements-swan.txt", # 包含可选依赖
"/requirements-media.txt", # 包含可选依赖
]

[tool.hatch.build.targets.wheel]
Expand Down
11 changes: 2 additions & 9 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# pytest

build

pytest

pytest-asyncio

nanoid
omegaconf
ipython
ipython<8.13; python_version < '3.9'
ipykernel

# Packages used in unit test scripts
torch
torchvision
torchvision
python-dotenv
4 changes: 4 additions & 0 deletions requirements-media.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
soundfile
pillow
matplotlib
numpy
22 changes: 2 additions & 20 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
# for swanlab
swankit==0.1.0b7
swanboard==0.1.2b3

# data process
soundfile
pillow
matplotlib
numpy

# web server
swankit==0.1.0b10
swanboard==0.1.2b8
cos-python-sdk-v5
fastapi>=0.110.1
uvicorn>=0.14.0
requests
click


# database
ujson
pyyaml


# Information collection
psutil
pynvml
10 changes: 5 additions & 5 deletions swanlab/api/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
进行一些交互定义和数据请求
"""
from swanlab.error import ValidationError
from swanlab.utils import FONT
from swankit.log import FONT
from swanlab.package import get_user_setting_path, get_host_api
from swanlab.api.info import LoginInfo
from swanlab.log import swanlog
from swanlab.utils.judgment import in_jupyter
from swanlab.env import in_jupyter
import getpass
import requests
import sys
Expand Down Expand Up @@ -46,8 +46,8 @@ def login_by_key(api_key: str, timeout: int = 20, save: bool = True) -> LoginInf


def input_api_key(
tip: str = "Paste an API key from your profile and hit enter, or press 'CTRL-C' to quit: ",
again: bool = False,
tip: str = "Paste an API key from your profile and hit enter, or press 'CTRL-C' to quit: ",
again: bool = False,
) -> str:
"""让用户输入apikey
此时有两条消息,第一条消息为固定格式,第二条消息
Expand Down Expand Up @@ -112,7 +112,7 @@ def terminal_login(api_key: str = None) -> LoginInfo:
raise e


def _abort_tip(tp, val, tb):
def _abort_tip(tp, _, __):
"""处理用户在input_api_key输入时按下CTRL+C的情况"""
if tp == KeyboardInterrupt:
print("\n" + FONT.red("Aborted!"))
Expand Down
2 changes: 1 addition & 1 deletion swanlab/api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from swanlab.data.modules import MediaBuffer
from swanlab.error import NetworkError, ApiError
from swanlab.package import get_host_api
from swanlab.utils import FONT
from swankit.log import FONT
from swanlab.log import swanlog
import requests

Expand Down
8 changes: 2 additions & 6 deletions swanlab/api/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
@Description:
定义认证数据格式
"""
import os.path
import requests
from swanlab.utils.key import save_key
from swanlab.env import get_swanlab_folder
from swanlab.package import get_host_api
from swanlab.package import save_key
from typing import Union


Expand Down Expand Up @@ -90,8 +87,7 @@ def save(self):
"""
保存登录信息
"""
path = os.path.join(get_swanlab_folder(), ".netrc")
return save_key(path, get_host_api(), "user", self.api_key)
return save_key("user", self.api_key)


class ProjectInfo:
Expand Down
2 changes: 1 addition & 1 deletion swanlab/cli/commands/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import click
from swanlab.package import is_login
from swanlab.api.auth import terminal_login
from swanlab.utils import FONT
from swankit.log import FONT


@click.command()
Expand Down
6 changes: 3 additions & 3 deletions swanlab/cli/commands/auth/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"""
import click
from swanlab.package import is_login
from swanlab.utils import FONT
from swanlab.env import get_swanlab_folder
from swankit.log import FONT
from swanlab.env import get_save_dir
import shutil
import sys

Expand All @@ -24,7 +24,7 @@ def logout():
confirm = input(FONT.swanlab("Are you sure you want to logout? (y/N): "))
if confirm.lower() == "y":
try:
shutil.rmtree(get_swanlab_folder())
shutil.rmtree(get_save_dir())
return print(FONT.swanlab("Logout successfully. You can use `" + command + "` to login again."))
except Exception as e:
return print(FONT.swanlab("Logout failed. Reason:" + str(e)))
Expand Down
Loading