MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / list_environment

Method list_environment

mod/project/python/environmentMod.py:39–80  ·  view source on GitHub ↗
(get)

Source from the content-addressed store, hash-verified

37
38 @staticmethod
39 def list_environment(get):
40 if get and get.get("sort_not_use/s") in ("1", "true"):
41 sort_not_use = True
42 else:
43 sort_not_use = False
44
45 em = EnvironmentManager()
46 all_project_map = em.all_python_project_map()
47 env_map = {
48 i.bin_path: i.to_dict(
49 project_name=all_project_map.get(i.bin_path, []),
50 can_remove=i.can_remove,
51 can_create=i.can_create,
52 can_set_default=i.can_set_default,
53 path_name=i.path_name,
54 from_panel=any((i.bin_path.startswith(x) for x in (python_manager_path(), pyenv_path()))) and i.env_type == "system"
55 ) for i in em.all_env
56 }
57 data = list(env_map.values())
58 if sort_not_use:
59 data.sort(key=lambda x: (
60 len(x["project_name"]),
61 ("venv", "conda", "system").index(x["type"]),
62 any(i == os.path.dirname(x["bin_path"]) for i in _SYS_BIN_PATH)
63 ))
64 else:
65 data.sort(key=lambda x: (
66 0 - len(x["project_name"]),
67 ("venv", "conda", "system").index(x["type"]),
68 any(i == os.path.dirname(x["bin_path"]) for i in _SYS_BIN_PATH)
69 ))
70 for i in data[::-1]:
71 i["name"] = i["venv_name"] or i["path_name"] or i["version"]
72 if i["type"] == "venv":
73 i["system_data"] = env_map[i["system_path"]]
74 i["can_remove"] = False if i["project_name"] else i["can_remove"]
75 now_env = em.get_default_python_env()
76 if now_env:
77 now_env = env_map[now_env.bin_path]
78 now_env["can_set_default"] = False
79
80 return json_response(True, data={"env_list": data, "now_env": now_env})
81
82 @staticmethod
83 def add_environment(get):

Callers

nothing calls this directly

Calls 12

EnvironmentManagerClass · 0.90
python_manager_pathFunction · 0.90
pyenv_pathFunction · 0.90
json_responseFunction · 0.90
indexMethod · 0.80
dirnameMethod · 0.80
getMethod · 0.45
to_dictMethod · 0.45
valuesMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected