##// END OF EJS Templates
Complete support of git commit info with IPython.sys_info()....
Fernando Perez -
Show More
@@ -6,10 +6,14 b' IPython.'
6 6 IPython is a set of tools for interactive and exploratory computing in Python.
7 7 """
8 8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2009 The IPython Development Team
9 # Copyright (c) 2008-2010, IPython Development Team.
10 # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
11 # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
12 # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
10 13 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
14 # Distributed under the terms of the Modified BSD License.
15 #
16 # The full license is in the file COPYING.txt, distributed with this software.
13 17 #-----------------------------------------------------------------------------
14 18
15 19 #-----------------------------------------------------------------------------
@@ -45,6 +49,7 b' from .frontend.terminal.embed import embed'
45 49 from .core.error import TryNext
46 50 from .core.interactiveshell import InteractiveShell
47 51 from .testing import test
52 from .utils.sysinfo import sys_info
48 53
49 54 # Release data
50 55 __author__ = ''
@@ -52,4 +57,3 b' for author, email in release.authors.itervalues():'
52 57 __author__ += author + ' <' + email + '>\n'
53 58 __license__ = release.license
54 59 __version__ = release.version
55 __revision__ = release.revision
@@ -1,39 +1,40 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Release data for the IPython project."""
3 3
4 #*****************************************************************************
5 # Copyright (C) 2008-2009 The IPython Development Team
6 # Copyright (C) 2001-2008 Fernando Perez <fperez@colorado.edu>
7 # Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and Nathaniel Gray
8 # <n8gray@caltech.edu>
4 #-----------------------------------------------------------------------------
5 # Copyright (c) 2008-2010, IPython Development Team.
6 # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
7 # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
8 # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
9 9 #
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
12 #*****************************************************************************
10 # Distributed under the terms of the Modified BSD License.
11 #
12 # The full license is in the file COPYING.txt, distributed with this software.
13 #-----------------------------------------------------------------------------
13 14
14 15 # Name of the package for release purposes. This is the name which labels
15 16 # the tarballs and RPMs made by distutils, so it's best to lowercase it.
16 17 name = 'ipython'
17 18
18 # For versions with substrings (like 0.6.16.svn), use an extra . to separate
19 # the new substring. We have to avoid using either dashes or underscores,
20 # because bdist_rpm does not accept dashes (an RPM) convention, and
21 # bdist_deb does not accept underscores (a Debian convention).
19 # IPython version information. An empty _version_extra corresponds to a full
20 # release. 'dev' as a _version_extra string means this is a development
21 # version
22 _version_major = 0
23 _version_minor = 11
24 _version_micro = '' # use '' for first of series, number for 1 and above
25 _version_extra = 'dev'
26 #_version_extra = '' # Uncomment this for full releases
22 27
23 development = True # change this to False to do a release
24 version_base = '0.11.alpha1'
25 branch = 'ipython'
26 # This needs to be updated to something that is meaningful for git
27 revision = '0'
28 # Construct full version string from these.
29 _ver = [_version_major, _version_minor]
30 if _version_micro:
31 _ver.append(_version_micro)
32 if _version_extra:
33 _ver.append(_version_extra)
28 34
29 if development:
30 if branch == 'ipython':
31 version = '%s.git' % (version_base)
32 else:
33 version = '%s.git.%s' % (version_base, branch)
34 else:
35 version = version_base
35 __version__ = '.'.join(map(str, _ver))
36 36
37 version = __version__ # backwards compatibility name
37 38
38 39 description = "An interactive computing environment for Python"
39 40
@@ -95,8 +96,8 b' The parallel computing architecture has the following main features:'
95 96
96 97 * Robust error handling in parallel code.
97 98
98 The latest development version is always available from IPython's `Launchpad
99 site <http://launchpad.net/ipython>`_.
99 The latest development version is always available from IPython's `GitHub
100 site <http://github.com/ipython>`_.
100 101 """
101 102
102 103 license = 'BSD'
@@ -115,7 +115,7 b" have['gobject'] = test_for('gobject')"
115 115 def report():
116 116 """Return a string with a summary report of test-related variables."""
117 117
118 out = [ sys_info() ]
118 out = [ sys_info(), '\n']
119 119
120 120 avail = []
121 121 not_avail = []
@@ -1,6 +1,6 b''
1 1 # encoding: utf-8
2 2 """
3 Utilities for getting information about a system.
3 Utilities for getting information about IPython and the system it's running in.
4 4 """
5 5
6 6 #-----------------------------------------------------------------------------
@@ -16,37 +16,122 b' Utilities for getting information about a system.'
16 16
17 17 import os
18 18 import platform
19 import pprint
19 20 import sys
20 21 import subprocess
21 22
23 from ConfigParser import ConfigParser
24
22 25 from IPython.core import release
23 26
24 27 #-----------------------------------------------------------------------------
28 # Globals
29 #-----------------------------------------------------------------------------
30 COMMIT_INFO_FNAME = '.git_commit_info.ini'
31
32 #-----------------------------------------------------------------------------
25 33 # Code
26 34 #-----------------------------------------------------------------------------
27 35
36 def pkg_commit_hash(pkg_path):
37 """Get short form of commit hash given directory `pkg_path`
38
39 There should be a file called 'COMMIT_INFO.txt' in `pkg_path`. This is a
40 file in INI file format, with at least one section: ``commit hash``, and two
41 variables ``archive_subst_hash`` and ``install_hash``. The first has a
42 substitution pattern in it which may have been filled by the execution of
43 ``git archive`` if this is an archive generated that way. The second is
44 filled in by the installation, if the installation is from a git archive.
45
46 We get the commit hash from (in order of preference):
47
48 * A substituted value in ``archive_subst_hash``
49 * A written commit hash value in ``install_hash`
50 * git output, if we are in a git repository
51
52 If all these fail, we return a not-found placeholder tuple
53
54 Parameters
55 ----------
56 pkg_path : str
57 directory containing package
58
59 Returns
60 -------
61 hash_from : str
62 Where we got the hash from - description
63 hash_str : str
64 short form of hash
65 """
66 # Try and get commit from written commit text file
67 pth = os.path.join(pkg_path, COMMIT_INFO_FNAME)
68 if not os.path.isfile(pth):
69 raise IOError('Missing commit info file %s' % pth)
70 cfg_parser = ConfigParser()
71 cfg_parser.read(pth)
72 archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash')
73 if not archive_subst.startswith('$Format'): # it has been substituted
74 return 'archive substitution', archive_subst
75 install_subst = cfg_parser.get('commit hash', 'install_hash')
76 if install_subst != '':
77 return 'installation', install_subst
78 # maybe we are in a repository
79 proc = subprocess.Popen('git rev-parse --short HEAD',
80 stdout=subprocess.PIPE,
81 stderr=subprocess.PIPE,
82 cwd=pkg_path, shell=True)
83 repo_commit, _ = proc.communicate()
84 if repo_commit:
85 return 'repository', repo_commit.strip()
86 return '(none found)', '<not found>'
87
88
89 def pkg_info(pkg_path):
90 """Return dict describing the context of this package
91
92 Parameters
93 ----------
94 pkg_path : str
95 path containing __init__.py for package
96
97 Returns
98 -------
99 context : dict
100 with named parameters of interest
101 """
102 src, hsh = pkg_commit_hash(pkg_path)
103 return dict(
104 ipython_version=release.version,
105 ipython_path=pkg_path,
106 commit_source=src,
107 commit_hash=hsh,
108 sys_version=sys.version,
109 sys_executable=sys.executable,
110 sys_platform=sys.platform,
111 platform=platform.platform(),
112 os_name=os.name,
113 )
114
115
28 116 def sys_info():
29 117 """Return useful information about IPython and the system, as a string.
30 118
31 Examples
32 --------
33 In [1]: print(sys_info())
34 IPython version: 0.11.bzr.r1340 # random
35 BZR revision : 1340
36 Platform info : os.name -> posix, sys.platform -> linux2
37 : Linux-2.6.31-17-generic-i686-with-Ubuntu-9.10-karmic
38 Python info : 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
39 [GCC 4.4.1]
40 """
41 out = []
42 out.append('IPython version: %s' % release.version)
43 out.append('BZR revision : %s' % release.revision)
44 out.append('Platform info : os.name -> %s, sys.platform -> %s' %
45 (os.name,sys.platform) )
46 out.append(' : %s' % platform.platform())
47 out.append('Python info : %s' % sys.version)
48 out.append('') # ensure closing newline
49 return '\n'.join(out)
119 Example
120 -------
121 In [2]: print sys_info()
122 {'commit_hash': '144fdae', # random
123 'commit_source': 'repository',
124 'ipython_path': '/home/fperez/usr/lib/python2.6/site-packages/IPython',
125 'ipython_version': '0.11.dev',
126 'os_name': 'posix',
127 'platform': 'Linux-2.6.35-22-generic-i686-with-Ubuntu-10.10-maverick',
128 'sys_executable': '/usr/bin/python',
129 'sys_platform': 'linux2',
130 'sys_version': '2.6.6 (r266:84292, Sep 15 2010, 15:52:39) \\n[GCC 4.4.5]'}
131 """
132 p = os.path
133 path = p.dirname(p.abspath(p.join(__file__, '..')))
134 return pprint.pformat(pkg_info(path))
50 135
51 136
52 137 def _num_cpus_unix():
@@ -49,28 +49,22 b' it system-wide or having configure anything, by typing at the terminal:'
49 49
50 50 python ipython.py
51 51
52 and similarly, you can execute the built-in test suite with:
53
54 .. code-block:: bash
55
56 python iptest.py
52 In order to run the test suite, you must at least be able to import IPython,
53 even if you haven't fully installed the user-facing scripts yet (common in a
54 development environment). You can then run the tests with:
57 55
56 .. code-block:: bash
58 57
59 This script manages intelligently both nose and trial, choosing the correct
60 test system for each of IPython's components.
58 python -c "import IPython; IPython.test()"
61 59
62 Once you have either installed it or at least configured your system to be
63 able to import IPython, you can run the tests with:
60 Once you have installed IPython either via a full install or using:
64 61
65 62 .. code-block:: bash
66 63
67 python -c "import IPython; IPython.test()"
64 python setup.py develop
68 65
69 This should work as long as IPython can be imported, even if you haven't fully
70 installed the user-facing scripts yet (common in a development environment).
71 Once you have installed IPython, you will have available system-wide a script
72 called :file:`iptest` that does the exact same as the :file:`iptest.py` script
73 in the source directory, so you can then test simply with:
66 you will have available a system-wide script called :file:`iptest` that runs
67 the full test suite. You can then run the suite with:
74 68
75 69 .. code-block:: bash
76 70
@@ -83,26 +77,25 b' Regardless of how you run things, you should eventually see something like:'
83 77
84 78 **********************************************************************
85 79 Test suite completed for system with the following information:
86 IPython version: 0.11.bzr.r1340
87 BZR revision : 1340
88 Platform info : os.name -> posix, sys.platform -> linux2
89 : Linux-2.6.31-17-generic-i686-with-Ubuntu-9.10-karmic
90 Python info : 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
91 [GCC 4.4.1]
92
93 Running from an installed IPython: True
80 {'commit_hash': '144fdae',
81 'commit_source': 'repository',
82 'ipython_path': '/home/fperez/usr/lib/python2.6/site-packages/IPython',
83 'ipython_version': '0.11.dev',
84 'os_name': 'posix',
85 'platform': 'Linux-2.6.35-22-generic-i686-with-Ubuntu-10.10-maverick',
86 'sys_executable': '/usr/bin/python',
87 'sys_platform': 'linux2',
88 'sys_version': '2.6.6 (r266:84292, Sep 15 2010, 15:52:39) \n[GCC 4.4.5]'}
94 89
95 90 Tools and libraries available at test time:
96 91 curses foolscap gobject gtk pexpect twisted wx wx.aui zope.interface
97 92
98 Tools and libraries NOT available at test time:
99 objc
100
101 Ran 11 test groups in 36.244s
93 Ran 9 test groups in 67.213s
102 94
103 95 Status:
104 96 OK
105 97
98
106 99 If not, there will be a message indicating which test group failed and how to
107 100 rerun that group individually. For example, this tests the
108 101 :mod:`IPython.utils` subpackage, the :option:`-v` option shows progress
@@ -110,7 +103,7 b' indicators:'
110 103
111 104 .. code-block:: bash
112 105
113 $ python iptest.py -v IPython.utils
106 $ iptest -v IPython.utils
114 107 ..........................SS..SSS............................S.S...
115 108 .........................................................
116 109 ----------------------------------------------------------------------
@@ -126,7 +119,7 b' example, this lets you run the specific test :func:`test_rehashx` inside the'
126 119
127 120 .. code-block:: bash
128 121
129 $ python iptest.py -vv IPython.core.tests.test_magic:test_rehashx
122 $ iptest -vv IPython.core.tests.test_magic:test_rehashx
130 123 IPython.core.tests.test_magic.test_rehashx(True,) ... ok
131 124 IPython.core.tests.test_magic.test_rehashx(True,) ... ok
132 125
@@ -146,6 +139,16 b' package basis:'
146 139
147 140 trial IPython.kernel
148 141
142 .. note::
143
144 The system information summary printed above is accessible from the top
145 level package. If you encounter a problem with IPython, it's useful to
146 include this information when reporting on the mailing list; use::
147
148 from IPython import sys_info
149 print sys_info()
150
151 and include the resulting information in your query.
149 152
150 153 For developers: writing tests
151 154 =============================
General Comments 0
You need to be logged in to leave comments. Login now