@@ -29,7 +29,6 @@ import os
2929import re
3030import signal
3131import ssl
32- import stat
3332import subprocess
3433import sys
3534import tempfile
@@ -3495,8 +3494,11 @@ def install_arc_if_required():
34953494 logger .debug ("arc command: %s" , ARC_COMMAND )
34963495 logger .debug ("libphutil path: %s" , LIBPHUTIL_PATH )
34973496
3498- check_call (["git" , "clone" , "--depth" , "1" , ARC_URL , ARC_PATH ])
3499- check_call (["git" , "clone" , "--depth" , "1" , LIBPHUTIL_URL , LIBPHUTIL_PATH ])
3497+ if not os .path .exists (ARC_COMMAND ):
3498+ check_call (["git" , "clone" , "--depth" , "1" , ARC_URL , ARC_PATH ])
3499+
3500+ if not os .path .exists (LIBPHUTIL_PATH ):
3501+ check_call (["git" , "clone" , "--depth" , "1" , LIBPHUTIL_URL , LIBPHUTIL_PATH ])
35003502
35013503
35023504def arc_ping (cwd ):
@@ -4076,41 +4078,78 @@ def check_for_updates():
40764078 update_arc ()
40774079
40784080
4079- def self_update (args ):
4080- """`self-update` command, updates arc and this script"""
4081- if not which_path (GIT_COMMAND [0 ]):
4082- raise Error (
4083- "Failed to find 'git' executable, which is required to install "
4084- "MozPhab's dependencies."
4085- )
4081+ def self_destroy (args ):
4082+ """`self-update` command.
40864083
4084+ This is a one-time command.
4085+ It installs the `moz-phab` from PyPI and deletes the current file.
4086+ Due to the number of possible options for Windows this command will only
4087+ link to a documentation.
4088+ """
40874089 # Update arc.
40884090 if config .arc_last_check >= 0 :
40894091 update_arc ()
40904092
40914093 # Update moz-phab
4092- release = get_self_release ()
4094+ if IS_WINDOWS :
4095+ # ask for manual upgrade
4096+ raise Error (
4097+ "moz-phab now requires Python 3, and is now distributed as a package from "
4098+ "PyPI.\n "
4099+ "Please follow the instructions to install moz-phab on Windows:\n "
4100+ "https://moz-conduit.readthedocs.io/en/latest/mozphab-windows.html"
4101+ )
40934102
4094- if not release ["update_required" ] and not args .force :
4095- logger .info ("Update of `moz-phab` not required" )
4096- return
4103+ os_name = "macos" if sys .platform == "darwin" else "linux"
40974104
4098- logger .info ("Updating `moz-phab` to v%s" % release ["tag" ])
4105+ pip3_command = which ("pip3" )
4106+ if not pip3_command :
4107+ raise Error (
4108+ "Please install Python 3 with pip.\n "
4109+ "https://moz-conduit.readthedocs.io/en/latest/mozphab-%s.html" % os_name
4110+ )
40994111
4100- url = "https://raw.githubusercontent.com/%s/%s/moz-phab" % (
4101- SELF_REPO ,
4102- release ["tag" ],
4103- )
4104- logger .debug ("updating '%s' from %s" % (SELF_FILE , url ))
4105- try :
4106- gh = urllib2 .urlopen (url )
4107- with open (SELF_FILE , "wb" ) as fh :
4108- fh .write (gh .read ())
4109- os .chmod (SELF_FILE , stat .S_IRWXU )
4110- except (urllib2 .HTTPError , urllib2 .URLError ) as e :
4111- raise Error ("Failed to download update: %s" % e )
4112+ call_args = [pip3_command , "install" , "MozPhab" ]
4113+
4114+ check_local_bin = False
4115+ if os_name == "linux" :
4116+ if not hasattr (sys , "real_prefix" ):
4117+ # not in virtualenv
4118+ logger .info (
4119+ "moz-phab can be installed for all users into the system Python "
4120+ "(requires sudo) or just for yourself."
4121+ )
4122+ res = prompt ("Should moz-phab be installed for all users?" , ["Yes" , "No" ])
4123+ if res == "Yes" :
4124+ call_args = ["sudo" ] + call_args
4125+ else :
4126+ check_local_bin = True
4127+ call_args .append ("--user" )
4128+
4129+ check_call (call_args )
4130+
4131+ if not which ("moz-phab" ):
4132+ if check_local_bin and os .path .isfile (
4133+ os .path .join (HOME_DIR , ".local" , "bin" , "moz-phab" )
4134+ ):
4135+ logger .info ("moz-phab is installed but it's not in the PATH." )
4136+ res = prompt (
4137+ "Add ~/.local/bin/ to the PATH by editing the ~/.bash_profile ?" ,
4138+ ["Yes" , "No" ],
4139+ )
4140+ if res == "Yes" :
4141+ with open (os .path .join (HOME_DIR , ".bash_profile" ), "a" ) as f :
4142+ f .write ("export PATH=$PATH:%s/.local/bin" % HOME_DIR )
4143+ else :
4144+ raise Error (
4145+ "moz-phab is not in the PATH, nor it is installed in ~/.local/bin\n "
4146+ "Please run `pip3 show -f MozPhab` to find where it is installed "
4147+ "and change the PATH variable accordingly.\n "
4148+ "You can then delete the old `moz-phab` file: %s" % SELF_FILE
4149+ )
41124150
4113- logger .info ("%s updated" % SELF_FILE )
4151+ os .remove (SELF_FILE )
4152+ logger .info ("%s removed" % SELF_FILE )
41144153
41154154
41164155def apply_patch (diff , cwd ):
@@ -4547,7 +4586,7 @@ def parse_args(argv):
45474586 update_parser .add_argument (
45484587 "--force" , "-f" , action = "store_true" , help = "Force update even if not necessary"
45494588 )
4550- update_parser .set_defaults (func = self_update , needs_repo = False )
4589+ update_parser .set_defaults (func = self_destroy , needs_repo = False )
45514590
45524591 # patch
45534592
@@ -4669,6 +4708,10 @@ def main(argv):
46694708 "or later."
46704709 )
46714710
4711+ logger .warning (
4712+ "moz-phab is now distributed via PyPI. Please run `moz-phab self-update`."
4713+ )
4714+
46724715 args = parse_args (argv )
46734716
46744717 if hasattr (args , "trace" ) and args .trace :
0 commit comments