diff --git a/setup.py b/setup.py index d69e66ce7..44991bf41 100755 --- a/setup.py +++ b/setup.py @@ -68,7 +68,7 @@ from setupbase import ( find_data_files, check_for_dependencies, git_prebuild, - check_for_submodules, + check_submodule_status, update_submodules, require_submodules, UpdateSubmodules, @@ -112,21 +112,37 @@ if os_name == 'windows' and 'sdist' in sys.argv: #------------------------------------------------------------------------------- # Make sure we aren't trying to run without submodules #------------------------------------------------------------------------------- +here = os.path.abspath(os.path.dirname(__file__)) -def ensure_submodules_exist(): - """Check out git submodules before distutils can do anything - - Because distutils cannot be trusted to update the tree - after everything has been set in motion. +def require_clean_submodules(): + """Check on git submodules before distutils can do anything + + Since distutils cannot be trusted to update the tree + after everything has been set in motion, + this is not a distutils command. """ # don't do anything if nothing is actually supposed to happen - for do_nothing in ('-h', '--help', '--help-commands', 'clean'): + for do_nothing in ('-h', '--help', '--help-commands', 'clean', 'submodule'): if do_nothing in sys.argv: return - if not check_for_submodules(): - update_submodules() -ensure_submodules_exist() + status = check_submodule_status(here) + + if status == "missing": + print("checking out submodules for the first time") + update_submodules(here) + elif status == "unclean": + print('\n'.join([ + "Cannot build / install IPython with unclean submodules", + "Please update submodules with", + " python setup.py submodule", + "or", + " git submodule update", + "or commit any submodule changes you have made." + ])) + sys.exit(1) + +require_clean_submodules() #------------------------------------------------------------------------------- # Things related to the IPython documentation diff --git a/setupbase.py b/setupbase.py index d024def3f..4a28694a8 100644 --- a/setupbase.py +++ b/setupbase.py @@ -373,27 +373,10 @@ def check_for_dependencies(): # VCS related #--------------------------------------------------------------------------- -def check_for_submodules(): - """return False if there are any submodules that need to be checked out, - True otherwise. - - This doesn't check if they are up to date, only existence. - """ - here = os.path.dirname(__file__) - submodules = [ - os.path.join(here, 'IPython', 'frontend', 'html', 'notebook', 'static', 'components') - ] - for submodule in submodules: - if not os.path.exists(submodule): - return False - return True +here = os.path.abspath(os.path.dirname(__file__)) -def update_submodules(): - """update git submodules""" - import subprocess - print("updating git submodules") - subprocess.check_call('git submodule init'.split()) - subprocess.check_call('git submodule update --recursive'.split()) +# utils.submodule has checks for submodule status +execfile(pjoin('IPython','utils','submodule.py'), globals()) class UpdateSubmodules(Command): """Update git submodules @@ -418,12 +401,10 @@ class UpdateSubmodules(Command): failure = e print(e) - if not check_for_submodules(): + if not check_submodule_status(here) == 'clean': print("submodules could not be checked out") sys.exit(1) - - # re-scan package data after update - self.distribution.package_data = find_package_data() + def git_prebuild(pkg_dir, build_cmd=build_py): """Return extended build or sdist command class for recording commit @@ -438,10 +419,6 @@ def git_prebuild(pkg_dir, build_cmd=build_py): class MyBuildPy(build_cmd): ''' Subclass to write commit data into installation tree ''' def run(self): - if not check_for_submodules(): - print("submodules missing! Run `setup.py submodule` and try again") - sys.exit(1) - build_cmd.run(self) # this one will only fire for build commands if hasattr(self, 'build_lib'): @@ -478,14 +455,14 @@ def git_prebuild(pkg_dir, build_cmd=build_py): '# GENERATED BY setup.py\n', 'commit = "%s"\n' % repo_commit, ]) - return MyBuildPy + return require_submodules(MyBuildPy) def require_submodules(command): """decorator for instructing a command to check for submodules before running""" class DecoratedCommand(command): def run(self): - if not check_for_submodules(): + if not check_submodule_status(here) == 'clean': print("submodules missing! Run `setup.py submodule` and try again") sys.exit(1) command.run(self)