-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcompute_security.py
55 lines (39 loc) · 1.75 KB
/
compute_security.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
#In a seperate file for now
import yaml
def quick_figure(package: str, ver):
return package if ver == -1 else package + "==" + ver
def dev_alt(altList:list, pkg: str) -> list:
pkgName, pkgVer = pkg.split("==") if len(pkg.split("==")) == 2 else [pkg, -1]
if pkgName == "psycopg2":
altList.append(quick_figure("psycopg2-binary",pkgVer))
elif pkgName == "torch":
altList.append("-i https://download.pytorch.org/whl/cpu")
altList.append(pkg)
def transcribe(envLoc: str, envName: str):
with open(envLoc + "environment-"+ envName + ".yml", "r") as baseEnvFp:
normalDeps=[]
devDeps=[]
condaDeps : list = yaml.load(baseEnvFp, yaml.Loader)["dependencies"]
for dep in condaDeps[:-1]:
dep = dep.replace("=", "==")
normalDeps.append(dep)
dev_alt(devDeps, dep)
if type(condaDeps[-1]) is dict and "pip" in condaDeps[-1].keys():
for dep in condaDeps[-1]["pip"]:
normalDeps.append(dep)
dev_alt(devDeps, dep)
#FIXME: Sometimes this doesn't update existing req files
with open(envLoc+"reqs.txt", "w") as computedReqs:
for line in normalDeps:
computedReqs.write(line + "\n")
print(devDeps)
with open(envLoc+"reqsDev.txt", "w") as computedDevReqs:
for line in devDeps:
computedDevReqs.write(line + "\n")
def main() -> None:
envList = [[a+"/",a] for a in ["manager"]]
envList.append(["","core"])
for r in envList:
transcribe(*r)
if __name__ == "__main__":
main()