-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
66 lines (57 loc) · 1.97 KB
/
setup.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
import subprocess
import sys
def check_poetry_virtualenvs_create():
try:
# Run the Poetry command to get the current value of virtualenvs.create
result = subprocess.run(
["poetry", "config", "virtualenvs.create"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True,
shell=True
)
# Capture the output and strip any extra whitespace
value = result.stdout.strip()
# Convert the value to a boolean
if value.lower() == "true":
return True
elif value.lower() == "false":
return False
else:
raise ValueError(f"Unexpected value returned: {value}")
except subprocess.CalledProcessError as e:
print(f"An error occurred: {e.stderr}")
sys.exit()
def set_poetry_virtualenvs_create(value):
try:
# Set the value of virtualenvs.create
subprocess.run(
["poetry", "config", "virtualenvs.create", str(value).lower()],
check=True,
shell=True
)
print(f"Poetry virtualenvs.create has been set to {value}.")
except subprocess.CalledProcessError as e:
print(f"An error occurred while setting the value: {e.stderr}")
sys.exit()
def install_dependencies():
try:
subprocess.run(
["poetry", "install"],
check=True,
shell=True
)
except subprocess.CalledProcessError as e:
print(f"An error occurred while installing the project: {e.stderr}")
sys.exit()
if __name__ == "__main__":
is_virtualenvs_create_enabled = check_poetry_virtualenvs_create()
switch_back = False
if not is_virtualenvs_create_enabled:
set_poetry_virtualenvs_create(True)
switch_back = True
install_dependencies()
if switch_back:
set_poetry_virtualenvs_create(False)
print(f"FIN is ready to use.")