feat: login with host #815
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
本次 Pull Request 包括多项更改,以优化登录认证流程并增强 SwanLab SDK 中主机格式处理的功能。主要更新包括登录逻辑改进 #792 、引入新的
HostFormatter
类以及环境变量处理的调整。登录认证改进:
docs/登录认证.md
:新增登录认证文档,并提供相关问题链接以供进一步探索。swanlab/api/info.py
:更新LoginInfo
类,使用新的fmt_web_host
函数进行 Web 主机格式化,并修改save
方法以保存 Web 主机和 API 主机信息。主机格式处理增强:
swanlab/data/sdk.py
:引入HostFormatter
类,以标准化主机 URL 格式,并更新登录函数以使用该格式器验证并设置主机环境变量。swanlab/env.py
:为SwanLabEnv
类新增方法,以验证字符串是否为有效主机名,并更新set_default
方法以支持从.netrc
文件读取主机信息(若存在)。兼容性与测试:
swanlab/package.py
:更新get_key
和save_key
函数,使其能够处理不含/api
后缀的主机 URL,以保持向后兼容。test/unit/data/test_sdk.py
:新增HostFormatter
类的测试,并更新登录函数测试以涵盖新的主机参数处理。test/unit/test_env.py
:新增测试以验证通过.netrc
文件设置环境变量的功能。test/unit/test_package.py
:新增测试以确保对包含/api
后缀的主机保持兼容性。本pr已经能实现
swanlab.login(api_key="xxx", host="xxx")
的效果,此函数新增两个可选参数:协议://host:端口号
其中端口号和协议可省略,此时默认https协议。此参数影响登录认证。命令行相关功能将在下一个pr完成