From 92590141d6a806873067b0f2089bf600aac70679 Mon Sep 17 00:00:00 2001 From: ZeYi Lin <944270057@qq.com> Date: Sat, 30 Dec 2023 21:04:47 +0800 Subject: [PATCH 1/3] add `__get_command` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 获取执行训练时的完整命令行信息 --- swanlab/database/system.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/swanlab/database/system.py b/swanlab/database/system.py index bd33f4a8..1bbfd7af 100644 --- a/swanlab/database/system.py +++ b/swanlab/database/system.py @@ -75,6 +75,16 @@ def __get_gpu_info(): return info +def __get_command(): + """获取执行训练时的完整命令行信息 + 比如在运行`python main.py -i 123`时,full_command为`main.py -i 123` + """ + import sys + + full_command = " ".join(sys.argv) + return full_command + + def get_system_info(): """获取系统信息""" return { From 68cffdc23b506dffc0783e64c2f8104a35045da1 Mon Sep 17 00:00:00 2001 From: ZeYi Lin <944270057@qq.com> Date: Sun, 31 Dec 2023 15:43:55 +0800 Subject: [PATCH 2/3] feat/add __get_pip_requirement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 获取当前项目的pip环境 --- swanlab/database/system.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/swanlab/database/system.py b/swanlab/database/system.py index 1bbfd7af..9a956da2 100644 --- a/swanlab/database/system.py +++ b/swanlab/database/system.py @@ -85,6 +85,23 @@ def __get_command(): return full_command +def __get_pip_requirement(): + """获取当前项目下的全部Python环境,是1个很长的、带换行的文件列表,建议后续存储在swanlog目录下""" + try: + # 运行pip命令获取当前环境下的环境目录 + result = subprocess.run(["pip", "freeze"], stdout=subprocess.PIPE, text=True) + + # 检查命令是否成功运行 + if result.returncode == 0: + return result.stdout + else: + print(f"Error: {result.stderr}") + return None + except Exception as e: + print(f"An error occurred: {e}") + return None + + def get_system_info(): """获取系统信息""" return { From 6d472368615523308060ea71c92e53562cd00fb2 Mon Sep 17 00:00:00 2001 From: ZeYi Lin <944270057@qq.com> Date: Sun, 31 Dec 2023 15:54:33 +0800 Subject: [PATCH 3/3] Fixbug/__get_remote_url catch error --- swanlab/database/system.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/swanlab/database/system.py b/swanlab/database/system.py index 9a956da2..63f2a95f 100644 --- a/swanlab/database/system.py +++ b/swanlab/database/system.py @@ -35,7 +35,9 @@ def __get_remote_url(): """ try: # 运行git命令获取远程仓库URL - result = subprocess.run(["git", "config", "--get", "remote.origin.url"], stdout=subprocess.PIPE, text=True) + result = subprocess.run( + ["git", "config", "--get", "remote.origin.url"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True + ) # 检查命令是否成功运行 if result.returncode == 0: