This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupVenv.py
109 lines (85 loc) · 3.68 KB
/
setupVenv.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import subprocess
class myInstaller:
def __init__(self):
self.og = "&&"
self.command = ""
self.environmentName = "PrivateVenv"
self.first = True
def run(self):
String = "This step of the process will upgrade your pip \n" \
"And install virtual environment if it isent installed\n" \
"Do you want to continue? [y/n]"
# INSTALL PREREQUISITES
if self.userCheck(String):
print("python -m pip install --upgrade pip")
a = subprocess.run("python -m pip install --upgrade pip", capture_output=True)
if a.returncode == 0:
print(a.stdout.decode().split(' ')[0] + " " + a.stdout.decode().split(' ')[1] + " " +
a.stdout.decode().split(' ')[2])
else:
print(a.stderr.decode())
print("\npip install virtualenv")
a = subprocess.run("pip install virtualenv", capture_output=True)
if a.returncode == 0:
print(a.stdout.decode().split(' ')[0] + " " + a.stdout.decode().split(' ')[1] + " " +
a.stdout.decode().split(' ')[2])
else:
print(a.stderr.decode())
# CREATING ENVIRONMENT IN FOLDER
path = str(os.path.dirname(os.path.realpath(__file__)))
subprocess.run("python -m venv " + self.environmentName)
print("\n environment : " + self.environmentName + ". Created as folder in directory")
print(path)
# Sending Commands to this Environment
String = "This step of the process will Attmept to \n" \
"install all dependencies from requirements.txt \nin the new environment " \
"Do you want to continue? [y/n]"
if self.userCheck(String):
pass
self.crossProcessCom_()
def crossProcessCom_(self):
dir_path = str(os.path.dirname(os.path.realpath(__file__)))
path = str(dir_path + "\\" + self.environmentName + "\\Scripts\\")
command = "cd " + path + " & activate.bat & " + "pip install -r " + dir_path + "\\requirements.txt"
pipUpgrade = "cd " + path + " & activate.bat & " + "python -m pip install --upgrade pip"
print("\n" + command + "\n")
subprocess.run(pipUpgrade, shell=True)
a = subprocess.run(command, capture_output=True, shell=True)
if a.returncode != 0:
print(a.stderr)
return False
print("\nDependencies List")
textReturn = a.stdout.decode().split('\n')
for r in textReturn:
pStr = r.split(':')
Str = pStr[0].split(' ')
if Str[0] == "Collecting":
operation = Str[0] + "\t"
name = Str[1]
print(str(operation) + str(name))
elif Str[0] == "Requirement":
operation = "Already installed \t"
name = pStr[1].split(' ') # == "setuptools"
print(str(operation) + str(name[1]))
else:
pass
# print("\n"+r+"\n")
def userCheck(self, Question):
accept = False
print("\n" + Question)
while True:
try:
val = str(input(":"))
except ValueError:
print("sorry i did not understand that input '" + val + "' plaese try again")
continue
if val == "y" or val == "Y":
return True
elif val == "n" or val == "N":
return False
else:
print("sorry i did not understand that input '" + val + "' plaese try again")
return accept
install = myInstaller()
install.run()