diff --git a/setup2.py b/setup2.py index f065fc8..f405da5 100755 --- a/setup2.py +++ b/setup2.py @@ -20,17 +20,20 @@ requires utilities which are not available under Windows.""" #----------------------------------------------------------------------------- # Minimal Python version sanity check #----------------------------------------------------------------------------- +from __future__ import print_function import sys # This check is also made in IPython/__init__, don't forget to update both when # changing Python version requirements. -if sys.version[0:3] < '2.6': - error = """\ -ERROR: 'IPython requires Python Version 2.6 or above.' -Exiting.""" - print >> sys.stderr, error - sys.exit(1) +#~ if sys.version[0:3] < '2.6': + #~ error = """\ +#~ ERROR: 'IPython requires Python Version 2.6 or above.' +#~ Exiting.""" + #~ print >> sys.stderr, error + #~ sys.exit(1) + +PY3 = (sys.version_info[0] >= 3) # At least we're on the python version we need, move on. @@ -50,8 +53,12 @@ if os.path.exists('MANIFEST'): os.remove('MANIFEST') from distutils.core import setup +# On Python 3, we need distribute (new setuptools) to do the 2to3 conversion +if PY3: + import setuptools + # Our own imports -from IPython.utils.path import target_update +from setupbase import target_update from setupbase import ( setup_args, @@ -91,14 +98,14 @@ if os.name == 'posix': elif os.name in ['nt','dos']: os_name = 'windows' else: - print 'Unsupported operating system:',os.name + print('Unsupported operating system:',os.name) sys.exit(1) # Under Windows, 'sdist' has not been supported. Now that the docs build with # Sphinx it might work, but let's not turn it on until someone confirms that it # actually works. if os_name == 'windows' and 'sdist' in sys.argv: - print 'The sdist command is not available under Windows. Exiting.' + print('The sdist command is not available under Windows. Exiting.') sys.exit(1) #------------------------------------------------------------------------------- @@ -187,6 +194,11 @@ packages = find_packages() package_data = find_package_data() data_files = find_data_files() +setup_args['cmdclass'] = {'build_py': record_commit_info('IPython')} +setup_args['packages'] = packages +setup_args['package_data'] = package_data +setup_args['data_files'] = data_files + #--------------------------------------------------------------------------- # Handle scripts, dependencies, and setuptools specific things #--------------------------------------------------------------------------- @@ -247,6 +259,12 @@ if 'setuptools' in sys.modules: setup_args['options'] = {"bdist_wininst": {"install_script": "ipython_win_post_install.py"}} + + if PY3: + setuptools_extra_args['use_2to3'] = True + from setuptools.command.build_py import build_py + setup_args['cmdclass'] = {'build_py': record_commit_info('IPython', build_cmd=build_py)} + setuptools_extra_args['entry_points'] = find_scripts(True, suffix='3') else: # If we are running without setuptools, call this function which will # check for dependencies an inform the user what is needed. This is @@ -258,10 +276,6 @@ else: # Do the actual setup now #--------------------------------------------------------------------------- -setup_args['cmdclass'] = {'build_py': record_commit_info('IPython')} -setup_args['packages'] = packages -setup_args['package_data'] = package_data -setup_args['data_files'] = data_files setup_args.update(setuptools_extra_args) def main(): diff --git a/setupbase.py b/setupbase.py index d711dbc..16d28fe 100644 --- a/setupbase.py +++ b/setupbase.py @@ -251,6 +251,44 @@ def make_man_update_target(manpage): locals() ) return (manpath_gz, [manpath], gz_cmd) +# The two functions below are copied from IPython.utils.path, so we don't need +# to import IPython during setup, which fails on Python 3. + +def target_outdated(target,deps): + """Determine whether a target is out of date. + + target_outdated(target,deps) -> 1/0 + + deps: list of filenames which MUST exist. + target: single filename which may or may not exist. + + If target doesn't exist or is older than any file listed in deps, return + true, otherwise return false. + """ + try: + target_time = os.path.getmtime(target) + except os.error: + return 1 + for dep in deps: + dep_time = os.path.getmtime(dep) + if dep_time > target_time: + #print "For target",target,"Dep failed:",dep # dbg + #print "times (dep,tar):",dep_time,target_time # dbg + return 1 + return 0 + + +def target_update(target,deps,cmd): + """Update a target with a given command given a list of dependencies. + + target_update(target,deps,cmd) -> runs cmd if target is outdated. + + This is just a wrapper around target_outdated() which calls the given + command if target is outdated.""" + + if target_outdated(target,deps): + system(cmd) + #--------------------------------------------------------------------------- # Find scripts #--------------------------------------------------------------------------- diff --git a/setupext/setupext.py b/setupext/setupext.py index a78d7ea..bab51a0 100644 --- a/setupext/setupext.py +++ b/setupext/setupext.py @@ -1,4 +1,5 @@ # encoding: utf-8 +from __future__ import print_function __docformat__ = "restructuredtext en" @@ -27,26 +28,26 @@ def check_display(f): @check_display def print_line(char='='): - print char * 76 + print(char * 76) @check_display def print_status(package, status): initial_indent = "%22s: " % package indent = ' ' * 24 - print fill(str(status), width=76, + print(fill(str(status), width=76, initial_indent=initial_indent, - subsequent_indent=indent) + subsequent_indent=indent)) @check_display def print_message(message): indent = ' ' * 24 + "* " - print fill(str(message), width=76, + print(fill(str(message), width=76, initial_indent=indent, - subsequent_indent=indent) + subsequent_indent=indent)) @check_display def print_raw(section): - print section + print(section) #------------------------------------------------------------------------------- # Tests for specific packages