27
27
logger = logging .getLogger (__name__ )
28
28
logger .addHandler (logging .StreamHandler ())
29
29
logger .setLevel (logging .DEBUG )
30
+ if os .environ .get ("JARVIS_VERBOSITY" , "-1" ) == "1" :
31
+ verbose = " --verbose"
32
+ else :
33
+ verbose = ""
30
34
31
35
32
36
def pretext () -> str :
@@ -66,6 +70,16 @@ def get_arch() -> str | NoReturn:
66
70
return architecture
67
71
68
72
73
+ def confirmation_prompt () -> None :
74
+ """Prompts a confirmation from the user to continue or exit."""
75
+ prompt = input ("Are you sure you want to continue? <Y/N> " )
76
+ if not re .match (r"^[yY](es)?$" , prompt ):
77
+ logger .info (pretext ())
78
+ logger .info ("Bye. Hope to see you soon." )
79
+ logger .info (pretext ())
80
+ exit (0 )
81
+
82
+
69
83
class Env :
70
84
"""Custom configuration variables, passed on to shell scripts as env vars.
71
85
@@ -78,7 +92,8 @@ def __init__(self):
78
92
self .osname : str = platform .system ().lower ()
79
93
self .architecture : str = get_arch ()
80
94
self .pyversion : str = f"{ sys .version_info .major } { sys .version_info .minor } "
81
- self .current_dir : str = os .path .dirname (__file__ )
95
+ self .current_dir : os .PathLike | str = os .path .dirname (__file__ )
96
+ self .python : os .PathLike | str = sys .executable
82
97
83
98
84
99
env = Env ()
@@ -144,12 +159,7 @@ def windows_caveat() -> None | NoReturn:
144
159
)
145
160
logger .info (pretext ())
146
161
logger .info (pretext ())
147
- prompt = input ("Are you sure you want to continue? <Y/N> " )
148
- if not re .match (r"^[yY](es)?$" , prompt ):
149
- logger .info (pretext ())
150
- logger .info ("Bye. Hope to see you soon." )
151
- logger .info (pretext ())
152
- exit (0 )
162
+ confirmation_prompt ()
153
163
154
164
155
165
def unsupported_os () -> NoReturn :
@@ -180,6 +190,24 @@ def unsupported_arch() -> NoReturn:
180
190
exit (1 )
181
191
182
192
193
+ def unsupported_env () -> None :
194
+ """Function to handle installations that are NOT on virtual environments."""
195
+ logger .info (pretext ())
196
+ logger .info (pretext ())
197
+ logger .info (
198
+ center (
199
+ """
200
+ Using a virtual environment is highly recommended to avoid version conflicts in dependencies
201
+ * Creating Virtual Environments: https://docs.python.org/3/library/venv.html#creating-virtual-environments
202
+ * How Virtual Environments work: https://docs.python.org/3/library/venv.html#how-venvs-work
203
+ """
204
+ )
205
+ )
206
+ logger .info (pretext ())
207
+ logger .info (pretext ())
208
+ confirmation_prompt ()
209
+
210
+
183
211
class Requirements :
184
212
"""Install locations for pinned, locked and upgrade-able packages.
185
213
@@ -252,7 +280,7 @@ def dev_uninstall() -> None:
252
280
logger .info (center ("Uninstalling dev dependencies" ))
253
281
logger .info (pretext ())
254
282
run_subprocess (
255
- " python -m pip uninstall --no-cache-dir sphinx==5.1.1 pre-commit recommonmark gitverse -y"
283
+ f" { env . python } -m pip uninstall{ verbose } --no-cache-dir sphinx==5.1.1 pre-commit recommonmark gitverse -y"
256
284
)
257
285
258
286
@@ -262,18 +290,19 @@ def main_uninstall() -> None:
262
290
logger .info (pretext ())
263
291
logger .info (center ("Uninstalling ALL dependencies" ))
264
292
logger .info (pretext ())
265
- exc = thread_worker (
293
+ exception = thread_worker (
266
294
[
267
- f"python -m pip uninstall --no-cache-dir -r { requirements .pinned } -y" ,
268
- f"python -m pip uninstall --no-cache-dir -r { requirements .locked } -y" ,
269
- f"python -m pip uninstall --no-cache-dir -r { requirements .upgrade } -y" ,
270
- f"python -m pip uninstall --no-cache-dir { ' ' .join (os_specific_pip ())} -y" ,
295
+ f"{ env . python } -m pip uninstall{ verbose } --no-cache-dir -r { requirements .pinned } -y" ,
296
+ f"{ env . python } -m pip uninstall{ verbose } --no-cache-dir -r { requirements .locked } -y" ,
297
+ f"{ env . python } -m pip uninstall{ verbose } --no-cache-dir -r { requirements .upgrade } -y" ,
298
+ f"{ env . python } -m pip uninstall{ verbose } --no-cache-dir { ' ' .join (os_specific_pip ())} -y" ,
271
299
]
272
300
)
273
301
logger .info (pretext ())
274
- logger .info (center ("Cleanup has completed!" )) if exc else logger .info (
275
- center ("One or many cleanup threads have failed!!" )
276
- )
302
+ if exception :
303
+ logger .error (center ("One or more cleanup threads have failed!!" ))
304
+ else :
305
+ logger .info (center ("Cleanup has completed!" ))
277
306
logger .info (pretext ())
278
307
279
308
@@ -282,13 +311,22 @@ def os_agnostic() -> None:
282
311
logger .info (pretext ())
283
312
logger .info (center ("Installing OS agnostic dependencies" ))
284
313
logger .info (pretext ())
285
- thread_worker (
314
+ exception = thread_worker (
286
315
[
287
- f"python -m pip install --no-cache -r { requirements .pinned } " ,
288
- f"python -m pip install --no-cache -r { requirements .locked } " ,
289
- f"python -m pip install --no-cache --upgrade -r { requirements .upgrade } " ,
316
+ f"{ env . python } -m pip install{ verbose } --no-cache -r { requirements .pinned } " ,
317
+ f"{ env . python } -m pip install{ verbose } --no-cache -r { requirements .locked } " ,
318
+ f"{ env . python } -m pip install{ verbose } --no-cache --upgrade -r { requirements .upgrade } " ,
290
319
]
291
320
)
321
+ logger .info (pretext ())
322
+ if exception :
323
+ logger .error (center ("One or more installation threads have failed!!" ))
324
+ logger .error (
325
+ center ("Please set JARVIS_VERBOSITY=1 and retry to identify root cause." )
326
+ )
327
+ else :
328
+ logger .info (center ("Installation has completed!" ))
329
+ logger .info (pretext ())
292
330
293
331
294
332
def init () -> None :
@@ -299,6 +337,9 @@ def init() -> None:
299
337
if env .architecture != "amd64" :
300
338
unsupported_arch ()
301
339
340
+ if sys .prefix == sys .base_prefix :
341
+ unsupported_env ()
342
+
302
343
pyversion : str = (
303
344
f"{ sys .version_info .major } .{ sys .version_info .minor } .{ sys .version_info .micro } "
304
345
)
@@ -314,7 +355,9 @@ def init() -> None:
314
355
"Please use any python version between 3.10.* and 3.11.*"
315
356
)
316
357
exit (1 )
317
- run_subprocess ("python -m pip install --upgrade pip setuptools wheel" )
358
+ run_subprocess (
359
+ f"{ env .python } -m pip install{ verbose } --upgrade pip setuptools wheel"
360
+ )
318
361
319
362
320
363
def dev_install () -> None :
@@ -324,7 +367,7 @@ def dev_install() -> None:
324
367
logger .info (center ("Installing dev dependencies" ))
325
368
logger .info (pretext ())
326
369
run_subprocess (
327
- " python -m pip install sphinx==5.1.1 pre-commit recommonmark gitverse"
370
+ f" { env . python } -m pip install{ verbose } sphinx==5.1.1 pre-commit recommonmark gitverse"
328
371
)
329
372
330
373
0 commit comments