-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcompute_dev.py
59 lines (43 loc) · 2.15 KB
/
compute_dev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import yaml
from packaging.version import Version
def pkg_list_to_dict(depsList: list[str], isPip: bool) -> dict:
depDict = {}
for package in depsList:
if not isPip and type(package) is not str:
continue
try:
pkgName, pkgVer = package.split("==" if isPip else "=")
except ValueError:
raise ValueError(f"Couldn't parse {package} into package name and version (isPip: {isPip})")
depDict[pkgName] = pkgVer
return depDict
def dev_corrections(pipDict: dict) -> None:
if "psycopg2" in pipDict.keys():
ver = pipDict["psycopg2"]
del pipDict["psycopg2"]
pipDict["psycopg2-binary"] = ver
def main() -> None:
for reqLoc in ["manager"]:
with open(reqLoc + "/environment-"+ reqLoc + ".yml", "r") as baseEnvFp:
handle : dict = yaml.load(baseEnvFp, yaml.Loader)
handle["name"] = reqLoc + "-dev"
pipDeps = {}
print(type(handle["dependencies"][-1]))
if type(handle["dependencies"][-1]) is dict and "pip" in handle["dependencies"][-1].keys():
pipDeps :dict = pkg_list_to_dict(handle["dependencies"][-1]["pip"], True)
dev_corrections(pipDeps)
deps :dict = pkg_list_to_dict(handle["dependencies"], False)
print(deps)
dev_corrections(deps)
handle["dependencies"]=[dep + "=" + deps[dep] for dep in deps.keys()]
if len(pipDeps) != 0:
parsedPip = {"pip":[dep + "==" + pipDeps[dep] for dep in pipDeps.keys()]}
if "torch" in pipDeps.keys():
torchloc = parsedPip["pip"].index("torch=="+ pipDeps["torch"])
parsedPip["pip"].insert(torchloc, "--extra-index-url https://download.pytorch.org/whl/cpu")
handle["dependencies"].append(parsedPip)
with open(reqLoc+"/environment.yml", "w") as computedEnvFp:
computedEnvFp.write("---\n")
yaml.dump(handle, computedEnvFp)
if __name__ == "__main__":
main()