##// END OF EJS Templates
Merge pull request #13661 from Carreau/wn83...
Merge pull request #13661 from Carreau/wn83 whats new 8.3

File last commit:

r27046:fc34990c
r27653:d20dabd2 merge
Show More
sysinfo.py
142 lines | 4.2 KiB | text/x-python | PythonLexer
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 # encoding: utf-8
"""
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 Utilities for getting information about IPython and the system it's running in.
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 """
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import platform
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 import pprint
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 import sys
import subprocess
from IPython.core import release
Matthias Bussonnier
remove some py3compat usage
r24265 from IPython.utils import _sysinfo, encoding
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204
#-----------------------------------------------------------------------------
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 # Code
#-----------------------------------------------------------------------------
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 def pkg_commit_hash(pkg_path):
"""Get short form of commit hash given directory `pkg_path`
We get the commit hash from (in order of preference):
MinRK
store git commit hash in utils._sysinfo instead of hidden git_commit_info.ini data file.
r6315 * IPython.utils._sysinfo.commit
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 * git output, if we are in a git repository
MinRK
store git commit hash in utils._sysinfo instead of hidden git_commit_info.ini data file.
r6315 If these fail, we return a not-found placeholder tuple
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204
Parameters
----------
pkg_path : str
Matthias Bussonnier
reformat docstring in IPython utils
r26419 directory containing package
only used for getting commit from active repo
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204
Returns
-------
hash_from : str
Matthias Bussonnier
reformat docstring in IPython utils
r26419 Where we got the hash from - description
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 hash_str : str
Matthias Bussonnier
reformat docstring in IPython utils
r26419 short form of hash
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 """
# Try and get commit from written commit text file
MinRK
store git commit hash in utils._sysinfo instead of hidden git_commit_info.ini data file.
r6315 if _sysinfo.commit:
return "installation", _sysinfo.commit
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 # maybe we are in a repository
Matthias Bussonnier
Remove one unnecessary shell=True option in subprocess....
r25339 proc = subprocess.Popen('git rev-parse --short HEAD'.split(' '),
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Matthias Bussonnier
Remove one unnecessary shell=True option in subprocess....
r25339 cwd=pkg_path)
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 repo_commit, _ = proc.communicate()
if repo_commit:
Matthias Bussonnier
cast unicode to allow json dump
r18039 return 'repository', repo_commit.strip().decode('ascii')
Srinivas Reddy Thatiparthy
remove unicode specifier
r23213 return '(none found)', '<not found>'
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204
def pkg_info(pkg_path):
"""Return dict describing the context of this package
Parameters
----------
pkg_path : str
Matthias Bussonnier
reformat docstring in IPython utils
r26419 path containing __init__.py for package
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204
Returns
-------
context : dict
Matthias Bussonnier
reformat docstring in IPython utils
r26419 with named parameters of interest
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 """
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,
MinRK
add encoding to sys_info
r7649 default_encoding=encoding.DEFAULT_ENCODING,
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 )
Thomas Kluyver
Clean up formatting sys info for test report
r13173 def get_sys_info():
"""Return useful information about IPython and the system, as a dict."""
p = os.path
Thomas Kluyver
Calculate real path for symlinked IPython package in sysinfo...
r16457 path = p.realpath(p.dirname(p.abspath(p.join(__file__, '..'))))
Thomas Kluyver
Clean up formatting sys info for test report
r13173 return pkg_info(path)
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 def sys_info():
"""Return useful information about IPython and the system, as a string.
Thomas Kluyver
Improvements to docs formatting.
r12553 Examples
--------
::
Matthias Bussonnier
remove some py3compat usage
r24265 In [2]: print(sys_info())
Thomas Kluyver
Improvements to docs formatting.
r12553 {'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]'}
Thomas Kluyver
More concise test summary info
r12971 """
Thomas Kluyver
Clean up formatting sys info for test report
r13173 return pprint.pformat(get_sys_info())
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
def num_cpus():
Nikita Kniazev
Deprecate `utils.sysinfo.num_cpus`...
r27046 """DEPRECATED
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Nikita Kniazev
Deprecate `utils.sysinfo.num_cpus`...
r27046 Return the effective number of CPUs in the system as an integer.
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Nikita Kniazev
Deprecate `utils.sysinfo.num_cpus`...
r27046 This cross-platform function makes an attempt at finding the total number of
available CPUs in the system, as returned by various underlying system and
python calls.
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Nikita Kniazev
Deprecate `utils.sysinfo.num_cpus`...
r27046 If it can't find a sensible answer, it returns 1 (though an error *may* make
it return a large positive number that's actually incorrect).
"""
import warnings
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Nikita Kniazev
Deprecate `utils.sysinfo.num_cpus`...
r27046 warnings.warn(
"`num_cpus` is deprecated since IPython 8.0. Use `os.cpu_count` instead.",
DeprecationWarning,
stacklevel=2,
)
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Nikita Kniazev
Deprecate `utils.sysinfo.num_cpus`...
r27046 return os.cpu_count() or 1