Skip to content

Commit a6a7bd4

Browse files
authored
update collect env script to work in multiple python env (#3672)
1 parent 279571d commit a6a7bd4

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

scripts/collect_env.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,23 @@ def get_libc_version():
388388
return "-".join(platform.libc_ver())
389389

390390

391-
def get_python_packages(run_lambda):
392-
conda = os.environ.get("CONDA_EXE", "conda")
393-
pyenv = "conda"
394-
out = run_and_read_all(run_lambda, f"{conda} list")
395-
if out is None:
396-
pyenv = "pip"
397-
out = run_and_read_all(
398-
run_lambda, f"{sys.executable} -mpip list --format=freeze"
399-
)
400-
401-
return pyenv, "\n".join(
391+
def filter_python_packages(data):
392+
predefined_list = {
393+
"torch",
394+
"numpy",
395+
"intel",
396+
"mkl",
397+
"dpcpp",
398+
"ccl",
399+
"mpi",
400+
"pti",
401+
"transformers",
402+
"deepspeed",
403+
"libuv",
404+
}
405+
return [
402406
line
403-
for line in out.splitlines()
407+
for line in data.splitlines()
404408
if not line.startswith("#")
405409
and any(
406410
name in line
@@ -418,7 +422,26 @@ def get_python_packages(run_lambda):
418422
"libuv",
419423
}
420424
)
421-
)
425+
]
426+
427+
428+
def get_python_packages(run_lambda):
429+
conda = os.environ.get("CONDA_EXE", "conda")
430+
pyenv = "conda"
431+
out = run_and_read_all(run_lambda, f"{conda} list")
432+
pkgs_filtered = []
433+
try:
434+
pkgs_filtered = filter_python_packages(out)
435+
except Exception:
436+
pass
437+
if len(pkgs_filtered) == 0:
438+
pyenv = "pip"
439+
out = run_and_read_all(
440+
run_lambda, f"{sys.executable} -mpip list --format=freeze"
441+
)
442+
pkgs_filtered = filter_python_packages(out)
443+
444+
return pyenv, "\n".join(pkgs_filtered)
422445

423446

424447
def get_env_info():

0 commit comments

Comments
 (0)