chore: add api and web host to http obj #803
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.
此拉取请求包含对
swanlab
模块的多项更改,主要集中在改进登录功能、URL处理和代码组织上。最重要的更改包括新增了用于处理URL的属性和方法、更新了登录机制,并进行了重构以提高代码清晰度。主要是为 #792 的实现做准备。
登录功能改进:
在
swanlab/api/__init__.py
中添加了is_login
函数,通过验证HTTP对象的存在来检查用户是否已登录。更新了
swanlab/api/auth/login.py
中的login_request
和login_by_key
函数,使其接受并使用api_host
和web_host
参数。[1] [2]URL处理增强:
在
swanlab/api/http.py
中引入了base_url
、api_host
、web_host
、web_proj_url
和web_exp_url
属性,以便更好地管理URL。[1] [2]移除了硬编码的URL,并在多个文件中替换为动态URL属性,包括
swanlab/data/callback_cloud.py
、swanlab/data/run/metadata/cooperation/__init__.py
和swanlab/data/run/public.py
。[1] [2] [3] [4]代码重构:
重新组织了导入并移除了多个文件中未使用的导入,以提高代码的清晰度和可维护性。[1] [2] [3]
更新了
swanlab/api/__init__.py
中的__all__
,以包含新的is_login
函数。CLI命令更新:
swanlab/cli/commands/auth/login.py
和swanlab/cli/commands/auth/logout.py
中将is_login
替换为has_api_key
,以更好地反映检查API密钥存在的功能。[1] [2]额外改进:
swanlab/package.py
,新增了用于格式化和获取 URL 的函数,例如fmt_web_host
、get_setting_url
和get_login_url
。[1] [2]顺便修复了一下之前的测试(#797)在action执行时的错误问题。
close #804