From 133507fb5e65bef4a40a6de3a0e948a23108c4e0 2010-10-30 03:29:16 From: Fernando Perez Date: 2010-10-30 03:29:16 Subject: [PATCH] Merge branch 'version-info' into trunk --- diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..7a56bcb --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +IPython/.git_commit_info.ini export-subst diff --git a/.gitignore b/.gitignore index 01d9a61..1f1c943 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ +build +./dist docs/dist docs/build/* docs/source/api/generated -*.pyc +*.py[co] build *.egg-info -*.py~ +*~ *.bak diff --git a/COPYING.txt b/COPYING.txt index 96ad879..64205fe 100644 --- a/COPYING.txt +++ b/COPYING.txt @@ -1,77 +1,85 @@ -IPython is licensed under the terms of the new or revised BSD license, as follows: +============================= + The IPython licensing terms +============================= -Copyright (c) 2008, IPython Development Team +IPython is licensed under the terms of the Modified BSD License (also known as +New or Revised BSD), as follows: + +Copyright (c) 2008-2010, IPython Development Team +Copyright (c) 2001-2007, Fernando Perez. +Copyright (c) 2001, Janko Hauser +Copyright (c) 2001, Nathaniel Gray All rights reserved. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -Redistributions of source code must retain the above copyright notice, this list of -conditions and the following disclaimer. +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this list -of conditions and the following disclaimer in the documentation and/or other -materials provided with the distribution. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. -Neither the name of the IPython Development Team nor the names of its contributors -may be used to endorse or promote products derived from this software without -specific prior written permission. +Neither the name of the IPython Development Team nor the names of its +contributors may be used to endorse or promote products derived from this +software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. About the IPython Development Team ---------------------------------- -Fernando Perez began IPython in 2001 based on code from Janko Hauser -and Nathaniel Gray . Fernando is still the project lead. +Fernando Perez began IPython in 2001 based on code from Janko Hauser + and Nathaniel Gray . Fernando is still +the project lead. + +The IPython Development Team is the set of all contributors to the IPython +project. This includes all of the IPython subprojects. A full list with +details is kept in the documentation directory, in the file +``about/credits.txt``. -The IPython Development Team is the set of all contributors to the IPython project. -This includes all of the IPython subprojects. Here is a list of the currently active contributors: +The core team that coordinates development on GitHub can be found here: +http://github.com/ipython. As of late 2010, it consists of: - * Matthieu Brucher - * Ondrej Certik - * Laurent Dufrechou - * Robert Kern - * Brian E. Granger - * Fernando Perez (project leader) - * Benjamin Ragan-Kelley - * Ville M. Vainio - * Gael Varoququx - * Stefan van der Walt - * Tech-X Corporation - * Barry Wark +* Brian E. Granger +* Jonathan March +* Evan Patterson +* Fernando Perez +* Min Ragan-Kelley +* Robert Kern -If your name is missing, please add it. Our Copyright Policy -------------------- -IPython uses a shared copyright model. Each contributor maintains copyright over -their contributions to IPython. But, it is important to note that these +IPython uses a shared copyright model. Each contributor maintains copyright +over their contributions to IPython. But, it is important to note that these contributions are typically only changes to the repositories. Thus, the IPython source code, in its entirety is not the copyright of any single person or -institution. Instead, it is the collective copyright of the entire IPython -Development Team. If individual contributors want to maintain a record of what -changes/contributions they have specific copyright on, they should indicate their -copyright in the commit message of the change, when they commit the change to -one of the IPython repositories. +institution. Instead, it is the collective copyright of the entire IPython +Development Team. If individual contributors want to maintain a record of what +changes/contributions they have specific copyright on, they should indicate +their copyright in the commit message of the change, when they commit the +change to one of the IPython repositories. -With this in mind, the following banner should be used in any source code file to -indicate the copyright and license terms: +With this in mind, the following banner should be used in any source code file +to indicate the copyright and license terms: -#------------------------------------------------------------------------------- -# Copyright (C) 2008 The IPython Development Team +#----------------------------------------------------------------------------- +# Copyright (c) 2010, IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. # -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#------------------------------------------------------------------------------- \ No newline at end of file +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- diff --git a/IPython/.git_commit_info.ini b/IPython/.git_commit_info.ini new file mode 100644 index 0000000..19c2a55 --- /dev/null +++ b/IPython/.git_commit_info.ini @@ -0,0 +1,9 @@ +# This is an ini file that may contain information about the code state +[commit hash] + +# The line below may contain a valid hash if it has been substituted during +# 'git archive' +archive_subst_hash=$Format:%h$ + +# This line may be modified by the install process +install_hash= diff --git a/IPython/__init__.py b/IPython/__init__.py index 8dcab7c..c2573af 100755 --- a/IPython/__init__.py +++ b/IPython/__init__.py @@ -6,10 +6,14 @@ IPython. IPython is a set of tools for interactive and exploratory computing in Python. """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2009 The IPython Development Team +# Copyright (c) 2008-2010, IPython Development Team. +# Copyright (c) 2001-2007, Fernando Perez +# Copyright (c) 2001, Janko Hauser +# Copyright (c) 2001, Nathaniel Gray # -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- @@ -45,6 +49,7 @@ from .frontend.terminal.embed import embed from .core.error import TryNext from .core.interactiveshell import InteractiveShell from .testing import test +from .utils.sysinfo import sys_info # Release data __author__ = '' @@ -52,4 +57,3 @@ for author, email in release.authors.itervalues(): __author__ += author + ' <' + email + '>\n' __license__ = release.license __version__ = release.version -__revision__ = release.revision diff --git a/IPython/core/release.py b/IPython/core/release.py index 5f9a306..0f7d422 100644 --- a/IPython/core/release.py +++ b/IPython/core/release.py @@ -1,39 +1,40 @@ # -*- coding: utf-8 -*- """Release data for the IPython project.""" -#***************************************************************************** -# Copyright (C) 2008-2009 The IPython Development Team -# Copyright (C) 2001-2008 Fernando Perez -# Copyright (c) 2001 Janko Hauser and Nathaniel Gray -# +#----------------------------------------------------------------------------- +# Copyright (c) 2008-2010, IPython Development Team. +# Copyright (c) 2001-2007, Fernando Perez +# Copyright (c) 2001, Janko Hauser +# Copyright (c) 2001, Nathaniel Gray # -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#***************************************************************************** +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- # Name of the package for release purposes. This is the name which labels # the tarballs and RPMs made by distutils, so it's best to lowercase it. name = 'ipython' -# For versions with substrings (like 0.6.16.svn), use an extra . to separate -# the new substring. We have to avoid using either dashes or underscores, -# because bdist_rpm does not accept dashes (an RPM) convention, and -# bdist_deb does not accept underscores (a Debian convention). +# IPython version information. An empty _version_extra corresponds to a full +# release. 'dev' as a _version_extra string means this is a development +# version +_version_major = 0 +_version_minor = 11 +_version_micro = '' # use '' for first of series, number for 1 and above +_version_extra = 'dev' +#_version_extra = '' # Uncomment this for full releases -development = True # change this to False to do a release -version_base = '0.11.alpha1' -branch = 'ipython' -# This needs to be updated to something that is meaningful for git -revision = '0' +# Construct full version string from these. +_ver = [_version_major, _version_minor] +if _version_micro: + _ver.append(_version_micro) +if _version_extra: + _ver.append(_version_extra) -if development: - if branch == 'ipython': - version = '%s.git' % (version_base) - else: - version = '%s.git.%s' % (version_base, branch) -else: - version = version_base +__version__ = '.'.join(map(str, _ver)) +version = __version__ # backwards compatibility name description = "An interactive computing environment for Python" @@ -95,8 +96,8 @@ The parallel computing architecture has the following main features: * Robust error handling in parallel code. -The latest development version is always available from IPython's `Launchpad -site `_. +The latest development version is always available from IPython's `GitHub +site `_. """ license = 'BSD' diff --git a/IPython/frontend/terminal/ipapp.py b/IPython/frontend/terminal/ipapp.py index 442e98a..874a63f 100755 --- a/IPython/frontend/terminal/ipapp.py +++ b/IPython/frontend/terminal/ipapp.py @@ -322,7 +322,6 @@ class IPAppConfigLoader(BaseAppConfigLoader): # Crash handler for this application #----------------------------------------------------------------------------- - _message_template = """\ Oops, $self.app_name crashed. We do our best to make it stable, but... @@ -354,7 +353,7 @@ class IPAppCrashHandler(CrashHandler): def __init__(self, app): contact_name = release.authors['Fernando'][0] contact_email = release.authors['Fernando'][1] - bug_tracker = 'https://bugs.launchpad.net/ipython/+filebug' + bug_tracker = 'http://github.com/ipython/ipython/issues' super(IPAppCrashHandler,self).__init__( app, contact_name, contact_email, bug_tracker ) diff --git a/IPython/kernel/clusterdir.py b/IPython/kernel/clusterdir.py index 6a7c296..0fb8874 100755 --- a/IPython/kernel/clusterdir.py +++ b/IPython/kernel/clusterdir.py @@ -325,7 +325,7 @@ class ClusterDirCrashHandler(CrashHandler): def __init__(self, app): contact_name = release.authors['Brian'][0] contact_email = release.authors['Brian'][1] - bug_tracker = 'https://bugs.launchpad.net/ipython/+filebug' + bug_tracker = 'http://github.com/ipython/ipython/issues' super(ClusterDirCrashHandler,self).__init__( app, contact_name, contact_email, bug_tracker ) diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index db139b1..cfccb8e 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -115,7 +115,7 @@ have['gobject'] = test_for('gobject') def report(): """Return a string with a summary report of test-related variables.""" - out = [ sys_info() ] + out = [ sys_info(), '\n'] avail = [] not_avail = [] diff --git a/IPython/utils/sysinfo.py b/IPython/utils/sysinfo.py index 974c956..7aa7077 100644 --- a/IPython/utils/sysinfo.py +++ b/IPython/utils/sysinfo.py @@ -1,6 +1,6 @@ # encoding: utf-8 """ -Utilities for getting information about a system. +Utilities for getting information about IPython and the system it's running in. """ #----------------------------------------------------------------------------- @@ -16,37 +16,122 @@ Utilities for getting information about a system. import os import platform +import pprint import sys import subprocess +from ConfigParser import ConfigParser + from IPython.core import release #----------------------------------------------------------------------------- +# Globals +#----------------------------------------------------------------------------- +COMMIT_INFO_FNAME = '.git_commit_info.ini' + +#----------------------------------------------------------------------------- # Code #----------------------------------------------------------------------------- +def pkg_commit_hash(pkg_path): + """Get short form of commit hash given directory `pkg_path` + + There should be a file called 'COMMIT_INFO.txt' in `pkg_path`. This is a + file in INI file format, with at least one section: ``commit hash``, and two + variables ``archive_subst_hash`` and ``install_hash``. The first has a + substitution pattern in it which may have been filled by the execution of + ``git archive`` if this is an archive generated that way. The second is + filled in by the installation, if the installation is from a git archive. + + We get the commit hash from (in order of preference): + + * A substituted value in ``archive_subst_hash`` + * A written commit hash value in ``install_hash` + * git output, if we are in a git repository + + If all these fail, we return a not-found placeholder tuple + + Parameters + ---------- + pkg_path : str + directory containing package + + Returns + ------- + hash_from : str + Where we got the hash from - description + hash_str : str + short form of hash + """ + # Try and get commit from written commit text file + pth = os.path.join(pkg_path, COMMIT_INFO_FNAME) + if not os.path.isfile(pth): + raise IOError('Missing commit info file %s' % pth) + cfg_parser = ConfigParser() + cfg_parser.read(pth) + archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash') + if not archive_subst.startswith('$Format'): # it has been substituted + return 'archive substitution', archive_subst + install_subst = cfg_parser.get('commit hash', 'install_hash') + if install_subst != '': + return 'installation', install_subst + # maybe we are in a repository + proc = subprocess.Popen('git rev-parse --short HEAD', + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=pkg_path, shell=True) + repo_commit, _ = proc.communicate() + if repo_commit: + return 'repository', repo_commit.strip() + return '(none found)', '' + + +def pkg_info(pkg_path): + """Return dict describing the context of this package + + Parameters + ---------- + pkg_path : str + path containing __init__.py for package + + Returns + ------- + context : dict + with named parameters of interest + """ + src, hsh = pkg_commit_hash(pkg_path) + return dict( + ipython_version=release.version, + ipython_path=pkg_path, + commit_source=src, + commit_hash=hsh, + sys_version=sys.version, + sys_executable=sys.executable, + sys_platform=sys.platform, + platform=platform.platform(), + os_name=os.name, + ) + + def sys_info(): """Return useful information about IPython and the system, as a string. - Examples - -------- - In [1]: print(sys_info()) - IPython version: 0.11.bzr.r1340 # random - BZR revision : 1340 - Platform info : os.name -> posix, sys.platform -> linux2 - : Linux-2.6.31-17-generic-i686-with-Ubuntu-9.10-karmic - Python info : 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) - [GCC 4.4.1] - """ - out = [] - out.append('IPython version: %s' % release.version) - out.append('BZR revision : %s' % release.revision) - out.append('Platform info : os.name -> %s, sys.platform -> %s' % - (os.name,sys.platform) ) - out.append(' : %s' % platform.platform()) - out.append('Python info : %s' % sys.version) - out.append('') # ensure closing newline - return '\n'.join(out) + Example + ------- + In [2]: print sys_info() + {'commit_hash': '144fdae', # random + 'commit_source': 'repository', + 'ipython_path': '/home/fperez/usr/lib/python2.6/site-packages/IPython', + 'ipython_version': '0.11.dev', + 'os_name': 'posix', + 'platform': 'Linux-2.6.35-22-generic-i686-with-Ubuntu-10.10-maverick', + 'sys_executable': '/usr/bin/python', + 'sys_platform': 'linux2', + 'sys_version': '2.6.6 (r266:84292, Sep 15 2010, 15:52:39) \\n[GCC 4.4.5]'} + """ + p = os.path + path = p.dirname(p.abspath(p.join(__file__, '..'))) + return pprint.pformat(pkg_info(path)) def _num_cpus_unix(): diff --git a/MANIFEST.in b/MANIFEST.in index 765367a..124c74b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -18,6 +18,7 @@ graft IPython/scripts graft IPython/testing graft IPython/utils +include IPython/.git_commit_info.ini graft docs exclude docs/\#* diff --git a/README.txt b/README.txt index 6d8f595..74d0093 100644 --- a/README.txt +++ b/README.txt @@ -18,14 +18,9 @@ For full details, see the installation section of the manual. The basic parts of IPython only need the Python standard library, but much of its more advanced functionality requires extra packages. -Officially, IPython requires Python version 2.5 or 2.6. We have *not* yet -started to port IPython to Python 3.0. - -.. warning:: - - IPython 0.10 has only been well tested with Python 2.5 and 2.6. Parts of - it may work with Python 2.4, but we do not officially support Python 2.4 - anymore. If you need to use 2.4, you can still run IPython 0.9. +Officially, IPython requires Python version 2.6 or 2.7. An experimental port +of IPython to Python 3.x has been sarted, and is available at +http://github.com/takowl/ipython/tree/ipython-py3k. Instant running diff --git a/docs/source/development/testing.txt b/docs/source/development/testing.txt index 51dfa48..abda16a 100644 --- a/docs/source/development/testing.txt +++ b/docs/source/development/testing.txt @@ -49,28 +49,22 @@ it system-wide or having configure anything, by typing at the terminal: python ipython.py -and similarly, you can execute the built-in test suite with: - -.. code-block:: bash - - python iptest.py +In order to run the test suite, you must at least be able to import IPython, +even if you haven't fully installed the user-facing scripts yet (common in a +development environment). You can then run the tests with: +.. code-block:: bash -This script manages intelligently both nose and trial, choosing the correct -test system for each of IPython's components. + python -c "import IPython; IPython.test()" -Once you have either installed it or at least configured your system to be -able to import IPython, you can run the tests with: +Once you have installed IPython either via a full install or using: .. code-block:: bash - python -c "import IPython; IPython.test()" + python setup.py develop -This should work as long as IPython can be imported, even if you haven't fully -installed the user-facing scripts yet (common in a development environment). -Once you have installed IPython, you will have available system-wide a script -called :file:`iptest` that does the exact same as the :file:`iptest.py` script -in the source directory, so you can then test simply with: +you will have available a system-wide script called :file:`iptest` that runs +the full test suite. You can then run the suite with: .. code-block:: bash @@ -83,26 +77,25 @@ Regardless of how you run things, you should eventually see something like: ********************************************************************** Test suite completed for system with the following information: - IPython version: 0.11.bzr.r1340 - BZR revision : 1340 - Platform info : os.name -> posix, sys.platform -> linux2 - : Linux-2.6.31-17-generic-i686-with-Ubuntu-9.10-karmic - Python info : 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) - [GCC 4.4.1] - - Running from an installed IPython: True + {'commit_hash': '144fdae', + 'commit_source': 'repository', + 'ipython_path': '/home/fperez/usr/lib/python2.6/site-packages/IPython', + 'ipython_version': '0.11.dev', + 'os_name': 'posix', + 'platform': 'Linux-2.6.35-22-generic-i686-with-Ubuntu-10.10-maverick', + 'sys_executable': '/usr/bin/python', + 'sys_platform': 'linux2', + 'sys_version': '2.6.6 (r266:84292, Sep 15 2010, 15:52:39) \n[GCC 4.4.5]'} Tools and libraries available at test time: curses foolscap gobject gtk pexpect twisted wx wx.aui zope.interface - Tools and libraries NOT available at test time: - objc - - Ran 11 test groups in 36.244s + Ran 9 test groups in 67.213s Status: OK + If not, there will be a message indicating which test group failed and how to rerun that group individually. For example, this tests the :mod:`IPython.utils` subpackage, the :option:`-v` option shows progress @@ -110,7 +103,7 @@ indicators: .. code-block:: bash - $ python iptest.py -v IPython.utils + $ iptest -v IPython.utils ..........................SS..SSS............................S.S... ......................................................... ---------------------------------------------------------------------- @@ -126,7 +119,7 @@ example, this lets you run the specific test :func:`test_rehashx` inside the .. code-block:: bash - $ python iptest.py -vv IPython.core.tests.test_magic:test_rehashx + $ iptest -vv IPython.core.tests.test_magic:test_rehashx IPython.core.tests.test_magic.test_rehashx(True,) ... ok IPython.core.tests.test_magic.test_rehashx(True,) ... ok @@ -146,6 +139,16 @@ package basis: trial IPython.kernel +.. note:: + + The system information summary printed above is accessible from the top + level package. If you encounter a problem with IPython, it's useful to + include this information when reporting on the mailing list; use:: + + from IPython import sys_info + print sys_info() + + and include the resulting information in your query. For developers: writing tests ============================= diff --git a/setup.py b/setup.py index 834cb5f..e4d8e4f 100755 --- a/setup.py +++ b/setup.py @@ -6,12 +6,16 @@ Under Posix environments it works like a typical setup.py script. Under Windows, the command sdist is not supported, since IPython requires utilities which are not available under Windows.""" -#------------------------------------------------------------------------------- -# Copyright (C) 2008 The IPython Development Team +#----------------------------------------------------------------------------- +# Copyright (c) 2008-2010, IPython Development Team. +# Copyright (c) 2001-2007, Fernando Perez +# Copyright (c) 2001, Janko Hauser +# Copyright (c) 2001, Nathaniel Gray # -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#------------------------------------------------------------------------------- +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- #----------------------------------------------------------------------------- # Minimal Python version sanity check @@ -55,7 +59,8 @@ from setupbase import ( find_package_data, find_scripts, find_data_files, - check_for_dependencies + check_for_dependencies, + record_commit_info, ) isfile = os.path.isfile @@ -239,6 +244,7 @@ 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['scripts'] = scripts diff --git a/setupbase.py b/setupbase.py index 666ecea..37571a5 100644 --- a/setupbase.py +++ b/setupbase.py @@ -1,5 +1,4 @@ # encoding: utf-8 - """ This module defines the things that are used in setup.py for building IPython @@ -9,8 +8,7 @@ This includes: * Functions for finding things like packages, package data, etc. * A function for checking dependencies. """ - -__docformat__ = "restructuredtext en" +from __future__ import print_function #------------------------------------------------------------------------------- # Copyright (C) 2008 The IPython Development Team @@ -22,9 +20,11 @@ __docformat__ = "restructuredtext en" #------------------------------------------------------------------------------- # Imports #------------------------------------------------------------------------------- +import os +import sys -import os, sys - +from ConfigParser import ConfigParser +from distutils.command.build_py import build_py from glob import glob from setupext import install_data_ext @@ -38,7 +38,7 @@ isfile = os.path.isfile pjoin = os.path.join def oscmd(s): - print ">", s + print(">", s) os.system(s) # A little utility we'll need below, since glob() does NOT allow you to do @@ -175,9 +175,9 @@ def make_dir_struct(tag,base,out_base): # filenames, we must join back with the dirpath to get full valid file # paths: pfiles = [pjoin(dirpath,f) for f in filenames] - # Finally, generate the entry we need, which is a triple of (tag,output + # Finally, generate the entry we need, which is a pari of (output # path, files) for use as a data_files parameter in install_data. - out.append((tag,out_path,pfiles)) + out.append((out_path, pfiles)) return out @@ -194,7 +194,8 @@ def find_data_files(): # Simple file lists can be made by hand manpages = filter(isfile, glob(pjoin('docs','man','*.1.gz'))) - igridhelpfiles = filter(isfile, glob(pjoin('IPython','extensions','igrid_help.*'))) + igridhelpfiles = filter(isfile, + glob(pjoin('IPython','extensions','igrid_help.*'))) # For nested structures, use the utility above example_files = make_dir_struct( @@ -209,15 +210,15 @@ def find_data_files(): ) # And assemble the entire output list - data_files = [ ('data',manpagebase, manpages), - ('data',pjoin(docdirbase,'extensions'),igridhelpfiles), + data_files = [ (manpagebase, manpages), + (pjoin(docdirbase, 'extensions'), igridhelpfiles), ] + manual_files + example_files ## import pprint # dbg - ## print '*'*80 - ## print 'data files' + ## print('*'*80) + ## print('data files') ## pprint.pprint(data_files) - ## print '*'*80 + ## print('*'*80) return data_files @@ -271,8 +272,10 @@ def find_scripts(): # post-install scripts MUST reside in the scripts/ dir, otherwise distutils # doesn't find them. if 'bdist_wininst' in sys.argv: - if len(sys.argv) > 2 and ('sdist' in sys.argv or 'bdist_rpm' in sys.argv): - print >> sys.stderr,"ERROR: bdist_wininst must be run alone. Exiting." + if len(sys.argv) > 2 and \ + ('sdist' in sys.argv or 'bdist_rpm' in sys.argv): + print("ERROR: bdist_wininst must be run alone. Exiting.", + file=sys.stderr) sys.exit(1) scripts.append(pjoin('scripts','ipython_win_post_install.py')) @@ -288,7 +291,7 @@ def check_for_dependencies(): This function should NOT be called if running under setuptools! """ from setupext.setupext import ( - print_line, print_raw, print_status, print_message, + print_line, print_raw, print_status, check_for_zopeinterface, check_for_twisted, check_for_foolscap, check_for_pyopenssl, check_for_sphinx, check_for_pygments, @@ -312,3 +315,61 @@ def check_for_dependencies(): check_for_pygments() check_for_nose() check_for_pexpect() + + +def record_commit_info(pkg_dir, build_cmd=build_py): + """ Return extended build command class for recording commit + + The extended command tries to run git to find the current commit, getting + the empty string if it fails. It then writes the commit hash into a file + in the `pkg_dir` path, named ``.git_commit_info.ini``. + + In due course this information can be used by the package after it is + installed, to tell you what commit it was installed from if known. + + To make use of this system, you need a package with a .git_commit_info.ini + file - e.g. ``myproject/.git_commit_info.ini`` - that might well look like + this:: + + # This is an ini file that may contain information about the code state + [commit hash] + # The line below may contain a valid hash if it has been substituted + # during 'git archive' + archive_subst_hash=$Format:%h$ + # This line may be modified by the install process + install_hash= + + The .git_commit_info file above is also designed to be used with git + substitution - so you probably also want a ``.gitattributes`` file in the + root directory of your working tree that contains something like this:: + + myproject/.git_commit_info.ini export-subst + + That will cause the ``.git_commit_info.ini`` file to get filled in by ``git + archive`` - useful in case someone makes such an archive - for example with + via the github 'download source' button. + + Although all the above will work as is, you might consider having something + like a ``get_info()`` function in your package to display the commit + information at the terminal. See the ``pkg_info.py`` module in the nipy + package for an example. + """ + class MyBuildPy(build_cmd): + ''' Subclass to write commit data into installation tree ''' + def run(self): + build_py.run(self) + import subprocess + proc = subprocess.Popen('git rev-parse --short HEAD', + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True) + repo_commit, _ = proc.communicate() + # We write the installation commit even if it's empty + cfg_parser = ConfigParser() + cfg_parser.read(pjoin(pkg_dir, '.git_commit_info.ini')) + cfg_parser.set('commit hash', 'install_hash', repo_commit) + out_pth = pjoin(self.build_lib, pkg_dir, '.git_commit_info.ini') + out_file = open(out_pth, 'wt') + cfg_parser.write(out_file) + out_file.close() + return MyBuildPy diff --git a/tools/build_release b/tools/build_release index 494452c..1a9c830 100755 --- a/tools/build_release +++ b/tools/build_release @@ -20,16 +20,16 @@ for d in ['build','dist',pjoin('docs','build'),pjoin('docs','dist'), remove_tree(d) # Build source and binary distros -c('./setup.py sdist --formats=gztar,zip') +sh('./setup.py sdist --formats=gztar,zip') # Build eggs -c('python2.6 ./setupegg.py bdist_egg') +sh('python2.6 ./setupegg.py bdist_egg') # Call the windows build separately, so that the extra Windows scripts don't # get pulled into Unix builds (setup.py has code which checks for # bdist_wininst) -c("python setup.py bdist_wininst --install-script=ipython_win_post_install.py") +sh("python setup.py bdist_wininst --install-script=ipython_win_post_install.py") # Change name so retarded Vista runs the installer correctly -c("rename 's/linux-i686/win32-setup/' dist/*.exe") -c("rename 's/linux-x86_64/win32-setup/' dist/*.exe") +sh("rename 's/linux-i686/win32-setup/' dist/*.exe") +sh("rename 's/linux-x86_64/win32-setup/' dist/*.exe") diff --git a/tools/compile.py b/tools/compile.py deleted file mode 100755 index be34c42..0000000 --- a/tools/compile.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -"""Script to check that all code in a directory compiles correctly. - -Usage: - - compile.py - -This script verifies that all Python files in the directory where run, and all -of its subdirectories, compile correctly. - -Before a release, call this script from the top-level directory. -""" - -import sys - -from toollib import compile_tree - -if __name__ == '__main__': - compile_tree() diff --git a/tools/make_tarball.py b/tools/make_tarball.py index 87acda3..11738be 100755 --- a/tools/make_tarball.py +++ b/tools/make_tarball.py @@ -9,7 +9,7 @@ import shutil from toollib import * -tag = commands.getoutput('git describe') +tag = commands.getoutput('git describe --tags') base_name = 'ipython-%s' % tag tar_name = '%s.tgz' % base_name @@ -21,5 +21,5 @@ tar_name = '%s.tgz' % base_name start_dir = os.getcwd() cd('..') git_tpl = 'git archive --format=tar --prefix={0}/ HEAD | gzip > {1}' -c(git_tpl.format(base_name, tar_name)) -c('mv {0} tools/'.format(tar_name)) +sh(git_tpl.format(base_name, tar_name)) +sh('mv {0} tools/'.format(tar_name)) diff --git a/tools/toollib.py b/tools/toollib.py index 206bd7a..b0fa830 100644 --- a/tools/toollib.py +++ b/tools/toollib.py @@ -11,14 +11,16 @@ pjoin = os.path.join cd = os.chdir # Utility functions -def c(cmd): - """Run system command, raise SystemExit if it returns an error.""" +def sh(cmd): + """Run system command in shell, raise SystemExit if it returns an error.""" print "$",cmd stat = os.system(cmd) #stat = 0 # Uncomment this and comment previous to run in debug mode if stat: raise SystemExit("Command %s failed with code: %s" % (cmd, stat)) +# Backwards compatibility +c = sh def get_ipdir(): """Get IPython directory from command line, or assume it's the one above.""" @@ -39,17 +41,8 @@ def get_ipdir(): def compile_tree(): """Compile all Python files below current directory.""" - vstr = '.'.join(map(str,sys.version_info[:2])) - stat = os.system('python %s/lib/python%s/compileall.py .' % - (sys.prefix,vstr)) + stat = os.system('python -m compileall .') if stat: msg = '*** ERROR: Some Python files in tree do NOT compile! ***\n' msg += 'See messages above for the actual file that produced it.\n' raise SystemExit(msg) - - -def version_info(): - """Return bzr version info as a dict.""" - out = os.popen('bzr version-info') - pairs = (l.split(':',1) for l in out) - return dict(((k,v.strip()) for (k,v) in pairs)) diff --git a/tools/update_revnum.py b/tools/update_revnum.py deleted file mode 100755 index 7e03e74..0000000 --- a/tools/update_revnum.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python -"""Change the revision number in release.py - -This edits in-place release.py to update the revision number from bzr info. - -Usage: - -./update_revnum.py""" - -import os -import pprint -import re - -from toollib import * - -if __name__ == '__main__': - ver = version_info() - - pprint.pprint(ver) - - rfile = open('../IPython/core/release.py','rb').read() - newcont = re.sub(r'revision\s*=.*', - "revision = '%s'" % ver['revno'], - rfile) - - newcont = re.sub(r'^branch\s*=[^=].*', - "branch = '%s'" % ver['branch-nick'], - newcont) - - f = open('../IPython/core/release.py','wb') - f.write(newcont) - f.close()