@@ -220,8 +220,7 @@ def ensure(pip=None, pyvenv=None):
220220 try :
221221 if pyvenv :
222222 if os .path .exists (pyvenv ):
223- answer = input (REMOVE_VENV % pyvenv )
224- if answer .lower () == "y" :
223+ if input (REMOVE_VENV % pyvenv ).lower () == "y" :
225224 shutil .rmtree (pyvenv )
226225 else :
227226 sys .exit (0 )
@@ -233,8 +232,8 @@ def ensure(pip=None, pyvenv=None):
233232 shutil .rmtree (inst .VENV )
234233 raise RuntimeError (
235234 "Could not execute ensurepip --upgrade: %s"
236- % ("Probably you are using the system Python (%s)" % sys . executable )
237- )
235+ % ("Probably you are using the system Python (%s)" %
236+ sys . executable ) )
238237
239238
240239def get_requirements_branch (version , inst , from_fork ):
@@ -268,6 +267,7 @@ def install_standalone(venv):
268267 """
269268 Install the standalone Django applications if possible
270269 """
270+ errors = []
271271 print ("The standalone applications are not installed yet" )
272272 if sys .platform == "win32" :
273273 if os .path .exists ("python\\ python._pth.old" ):
@@ -285,10 +285,13 @@ def install_standalone(venv):
285285 print ("Applications " + app + " are not installed yet \n " )
286286
287287 subprocess .check_call (
288- [pycmd , "-m" , "pip" , "install" , "--find-links" , URL_STANDALONE , app ]
288+ [pycmd , "-m" , "pip" , "install" , "--find-links" , URL_STANDALONE ,
289+ app ]
289290 )
290291 except Exception as exc :
291- print ("%s: could not install %s" % (exc , app ))
292+ # for instance is somebody removed a wheel from the wheelhouse
293+ errors .append ("%s: could not install %s" % (exc , app ))
294+ return errors
292295
293296
294297def before_checks (inst , venv , port , remove , usage ):
@@ -312,15 +315,18 @@ def before_checks(inst, venv, port, remove, usage):
312315
313316 # check user
314317 user = getpass .getuser ()
315- if (inst is server and user != "root" ) or (inst is devel_server and user != "root" ):
318+ if (inst is server and user != "root" ) or (
319+ inst is devel_server and user != "root" ):
316320 sys .exit (
317321 "Error: you cannot perform a server or devel_server "
318322 "installation unless "
319323 "you are root. If you do not have root permissions, you "
320324 "can install the engine in user mode.\n \n " + usage
321325 )
322- elif (inst is user and user == "root" ) or (inst is devel and user == "root" ):
323- sys .exit ("Error: you cannot perform a user or devel installation" " as root." )
326+ elif (inst is user and user == "root" ) or (
327+ inst is devel and user == "root" ):
328+ sys .exit ("Error: you cannot perform a user or devel installation"
329+ " as root." )
324330
325331 # check if there is a DbServer running
326332 if not remove :
@@ -421,13 +427,13 @@ def install(inst, version, from_fork):
421427 else :
422428 if os .path .exists ("python\\ python._pth.old" ):
423429 subprocess .check_call (
424- [pycmd , "-m" , "pip" , "install" , "--upgrade" , "pip" , "wheel" , "urllib3" ]
425- )
430+ [pycmd , "-m" , "pip" , "install" , "--upgrade" , "pip" , "wheel" ,
431+ "urllib3" ] )
426432 else :
427433 subprocess .check_call ([pycmd , "-m" , "ensurepip" , "--upgrade" ])
428434 subprocess .check_call (
429- [pycmd , "-m" , "pip" , "install" , "--upgrade" , "pip" , "wheel" , "urllib3" ]
430- )
435+ [pycmd , "-m" , "pip" , "install" , "--upgrade" , "pip" , "wheel" ,
436+ "urllib3" ] )
431437
432438 # install the requirements
433439 branch = get_requirements_branch (version , inst , from_fork )
@@ -437,8 +443,8 @@ def install(inst, version, from_fork):
437443 mac = ("" ,)
438444 req = (
439445 f"https://raw.githubusercontent.com/gem/oq-engine/{ branch } /"
440- "requirements-py%d%d-%s%s.txt" % (PYVER [:2 ] + PLATFORM [sys .platform ] + mac )
441- )
446+ "requirements-py%d%d-%s%s.txt" % (PYVER [:2 ] + PLATFORM [sys .platform ]
447+ + mac ) )
442448
443449 subprocess .check_call (
444450 [
@@ -463,7 +469,8 @@ def install(inst, version, from_fork):
463469 )
464470 elif re .match (r"\d+(\.\d+)+" , version ): # install an official version
465471 subprocess .check_call (
466- [pycmd , "-m" , "pip" , "install" , "--upgrade" , "openquake.engine==" + version ]
472+ [pycmd , "-m" , "pip" , "install" , "--upgrade" ,
473+ "openquake.engine==" + version ]
467474 )
468475 else : # install a branch from github (only for user or server)
469476 commit = latest_commit (version )
@@ -473,7 +480,7 @@ def install(inst, version, from_fork):
473480 )
474481 fix_version (commit , inst .VENV )
475482
476- install_standalone (inst .VENV )
483+ errors = install_standalone (inst .VENV )
477484
478485 # create openquake.cfg
479486 if inst is server or inst is devel_server :
@@ -513,7 +520,8 @@ def install(inst, version, from_fork):
513520 "\\ Scripts\\ activate.ps1 (in PowerShell)"
514521 )
515522 elif inst in (user , devel ):
516- print (f"Please activate the venv with source { inst .VENV } " "/bin/activate" )
523+ print (f"Please activate the venv with source { inst .VENV } "
524+ "/bin/activate" )
517525
518526 # create systemd services
519527 if (inst is server and os .path .exists ("/run/systemd/system" )) or (
@@ -536,7 +544,8 @@ def install(inst, version, from_fork):
536544 command = command ,
537545 )
538546 f .write (srv )
539- subprocess .check_call (["systemctl" , "enable" , "--now" , service_name ])
547+ subprocess .check_call (
548+ ["systemctl" , "enable" , "--now" , service_name ])
540549 subprocess .check_call (["systemctl" , "start" , service_name ])
541550
542551 if inst in (user , server ):
@@ -553,14 +562,16 @@ def install(inst, version, from_fork):
553562 zipfile .ZipFile (tmp ).extractall (inst .VENV )
554563 os .remove (tmp )
555564 path = os .path .join (
556- inst .VENV , "demos" , "hazard" , "AreaSourceClassicalPSHA" , "job.ini"
557- )
565+ inst .VENV , "demos" , "hazard" , "AreaSourceClassicalPSHA" ,
566+ "job.ini" )
558567 msg = (
559568 "You can run a test calculation with the command\n "
560569 f"{ oqreal } engine --run { path } "
561570 )
562571 print ("The engine was installed successfully.\n " + msg )
563572
573+ return errors
574+
564575
565576def remove (inst ):
566577 """
@@ -590,31 +601,36 @@ def remove(inst):
590601
591602if __name__ == "__main__" :
592603 parser = argparse .ArgumentParser (
593- description = __doc__ , formatter_class = argparse . RawDescriptionHelpFormatter
594- )
604+ description = __doc__ ,
605+ formatter_class = argparse . RawDescriptionHelpFormatter )
595606 parser .add_argument (
596607 "inst" ,
597608 choices = ["server" , "user" , "devel" , "devel_server" ],
598609 nargs = "?" ,
599610 help = "the kind of installation you want" ,
600611 )
601612 parser .add_argument ("--venv" , help = "venv directory" )
602- parser .add_argument ("--remove" , action = "store_true" , help = "disinstall the engine" )
613+ parser .add_argument ("--remove" , action = "store_true" ,
614+ help = "disinstall the engine" )
603615 parser .add_argument ("--version" , help = "version to install (default stable)" )
604616 parser .add_argument ("--dbport" , help = "DbServer port (default 1907 or 1908)" )
605617 # NOTE: This flag should be set when installing the engine from an action
606618 # triggered by a fork
607619 parser .add_argument (
608- "--from_fork" , dest = "from_fork" , action = "store_true" , help = argparse . SUPPRESS
609- )
620+ "--from_fork" , dest = "from_fork" , action = "store_true" ,
621+ help = argparse . SUPPRESS )
610622 parser .set_defaults (from_fork = False )
611623 args = parser .parse_args ()
612624 if args .inst :
613625 inst = globals ()[args .inst ]
614- before_checks (inst , args .venv , args .dbport , args .remove , parser .format_usage ())
626+ before_checks (inst , args .venv , args .dbport , args .remove ,
627+ parser .format_usage ())
615628 if args .remove :
616629 remove (inst )
617630 else :
618- install (inst , args .version , args .from_fork )
631+ errors = install (inst , args .version , args .from_fork )
632+ if errors :
633+ # NB: even if one of the tools is missing, the engine will work
634+ sys .exit ('\n ' .join (errors ))
619635 else :
620636 sys .exit ("Please specify the kind of installation" )
0 commit comments