Skip to content

Commit

Permalink
Merge pull request #3781 from ccordoba12/sci-startup
Browse files Browse the repository at this point in the history
Backport PR #3574 - Improve style of scientific startup script
  • Loading branch information
ccordoba12 authored Dec 3, 2016
2 parents 2005cd2 + 9126580 commit 89e0601
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions spyder/scientific_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Need a temporary print function that is Python version agnostic.
import sys
import os

def exec_print(string="", end_space=False):
if sys.version[0] == '2':
Expand All @@ -25,9 +26,6 @@ def exec_print(string="", end_space=False):
else:
exec("print('" + string + "')")

__has_numpy = True
__has_scipy = True
__has_matplotlib = True

#==============================================================================
# Pollute the namespace but also provide MATLAB-like experience
Expand All @@ -42,46 +40,52 @@ def exec_print(string="", end_space=False):
# Import modules following official guidelines:
try:
import numpy as np
__has_numpy = True
except ImportError:
__has_numpy = False

try:
import scipy as sp
__has_scipy = True
except ImportError:
__has_scipy = False

try:
import matplotlib as mpl
import matplotlib.pyplot as plt #analysis:ignore
__has_matplotlib = True
except ImportError:
__has_matplotlib = False

__has_guiqwt = False
if os.environ.get('QT_API') != 'pyside':
try:
import guiqwt
import guiqwt.pyplot as plt_
import guidata
plt_.ion()
__has_guiqwt = True
except (ImportError, AssertionError):
pass

#==============================================================================
# Print what modules have been imported
#==============================================================================
__imports = ""
__imports = []
if __has_numpy:
__imports += "Imported NumPy %s" % np.__version__
__imports.append("NumPy {}".format(np.__version__))
if __has_scipy:
__imports += ", SciPy %s" % sp.__version__
__imports.append("SciPy {}".format(sp.__version__))
if __has_matplotlib:
__imports += ", Matplotlib %s" % mpl.__version__
__imports.append("Matplotlib {}".format(mpl.__version__))
if __has_guiqwt:
__imports.append("guidata {}".format(guidata.__version__))
__imports.append("guiqwt {}".format(guiqwt.__version__))

exec_print("")
exec_print()
if __imports:
exec_print(__imports)

import os
if os.environ.get('QT_API') != 'pyside':
try:
import guiqwt
import guiqwt.pyplot as plt_
import guidata
plt_.ion()
exec_print("+ guidata %s, guiqwt %s" % (guidata.__version__,
guiqwt.__version__))
except (ImportError, AssertionError):
exec_print()
exec_print("Imported " + ", ".join(__imports))
exec_print()

#==============================================================================
# Add help about the "scientific" command
Expand All @@ -108,18 +112,15 @@ def setscientific():
>>> from pylab import * # Matplotlib's pylab interface
>>> ion() # Turned on Matplotlib's interactive mode"""

try:
import guiqwt #analysis:ignore
if __has_guiqwt:
infos += """
>>> import guidata # GUI generation for easy dataset editing and display
>>> import guiqwt # Efficient 2D data-plotting features
>>> import guiqwt.pyplot as plt_ # guiqwt's pyplot: MATLAB-like syntax
>>> plt_.ion() # Turned on guiqwt's interactive mode"""
except ImportError:
pass

if __has_numpy:
if __imports:
infos += "\n"

infos += """
Expand Down Expand Up @@ -150,4 +151,4 @@ def setscientific():
#==============================================================================
# Delete temp vars
#==============================================================================
del setscientific, __has_numpy, __has_scipy, __has_matplotlib, __imports, exec_print
del setscientific, __has_numpy, __has_scipy, __has_matplotlib, __has_guiqwt, __imports, exec_print

0 comments on commit 89e0601

Please sign in to comment.