def _ipython_dir_changed(self, name, old, new): if old is not None: str_old = py3compat.cast_bytes_py2(os.path.abspath(old), sys.getfilesystemencoding() ) if str_old in sys.path: sys.path.remove(str_old) str_path = py3compat.cast_bytes_py2(os.path.abspath(new), sys.getfilesystemencoding() ) sys.path.append(str_path) ensure_dir_exists(new) readme = os.path.join(new, 'README') readme_src = os.path.join( get_ipython_package_dir(), u'config', u'profile', 'README') if not os.path.exists(readme) and os.path.exists(readme_src): shutil.copy(readme_src, readme) for d in ('extensions', 'nbextensions'): path = os.path.join(new, d) try: ensure_dir_exists(path) except OSError: # this will not be EEXIST self.log.error("couldn't create path %s: %s", path, e) self.log.debug("IPYTHONDIR set to: %s" % new)
def regen_header(self): ## lazy load asa this might not be use in many transformers import os from IPython.utils import path import io from pygments.formatters import HtmlFormatter header = [] static = os.path.join(path.get_ipython_package_dir(), 'frontend', 'html', 'notebook', 'static', ) here = os.path.split(os.path.realpath(__file__))[0] css = os.path.join(static, 'css') for sheet in [ # do we need jquery and prettify? # os.path.join(static, 'jquery', 'css', 'themes', 'base', # 'jquery-ui.min.css'), # os.path.join(static, 'prettify', 'prettify.css'), os.path.join(css, 'boilerplate.css'), os.path.join(css, 'fbm.css'), os.path.join(css, 'notebook.css'), os.path.join(css, 'renderedhtml.css'), os.path.join(css, 'style.min.css'), ]: try: with io.open(sheet, encoding='utf-8') as f: s = f.read() header.append(s) except IOError: # new version of ipython with style.min.css, pass pass pygments_css = HtmlFormatter().get_style_defs('.highlight') header.append(pygments_css) self.header = header
def _regen_header(self): """ Fills self.header with lines of CSS extracted from IPython and Pygments. """ from pygments.formatters import HtmlFormatter #Clear existing header. header = [] #Construct path to IPy CSS sheet_filename = os.path.join(path.get_ipython_package_dir(), 'html', 'static', 'style', 'style.min.css') #Load style CSS file. with io.open(sheet_filename, encoding='utf-8') as file: file_text = file.read() header.append(file_text) #Add pygments CSS formatter = HtmlFormatter() pygments_css = formatter.get_style_defs(self.highlight_class) header.append(pygments_css) #Set header self.header = header
def _ipython_dir_changed(self, name, old, new): str_old = py3compat.cast_bytes_py2(os.path.abspath(old), sys.getfilesystemencoding() ) if str_old in sys.path: sys.path.remove(str_old) str_path = py3compat.cast_bytes_py2(os.path.abspath(new), sys.getfilesystemencoding() ) sys.path.append(str_path) if not os.path.isdir(new): os.makedirs(new, mode=0o777) readme = os.path.join(new, 'README') readme_src = os.path.join( get_ipython_package_dir(), u'config', u'profile', 'README') if not os.path.exists(readme) and os.path.exists(readme_src): shutil.copy(readme_src, readme) for d in ('extensions', 'nbextensions'): path = os.path.join(new, d) if not os.path.exists(path): try: os.mkdir(path) except OSError as e: if e.errno != errno.EEXIST: self.log.error("couldn't create path %s: %s", path, e) self.log.debug("IPYTHONDIR set to: %s" % new)
def header_body(self): "return the body of the header as a list of strings" from pygments.formatters import HtmlFormatter header = [] static = os.path.join(path.get_ipython_package_dir(), 'frontend', 'html', 'notebook', 'static',) here = os.path.split(os.path.realpath(__file__))[0] css = os.path.join(static, 'css') for sheet in [ # do we need jquery and prettify? # os.path.join(static, 'jquery', 'css', 'themes', 'base', # 'jquery-ui.min.css'), # os.path.join(static, 'prettify', 'prettify.css'), os.path.join(css, 'boilerplate.css'), os.path.join(css, 'style.min.css'), # our overrides: os.path.join(here, '..', 'css', 'reveal_html.css'), ]: header.extend(self._stylesheet(sheet)) # pygments css pygments_css = HtmlFormatter().get_style_defs('.highlight') header.extend(['<meta charset="UTF-8">']) header.extend(self.in_tag('style', pygments_css, dict(type='"text/css"'))) return header
def check_startup_dir(self): if not os.path.isdir(self.startup_dir): os.mkdir(self.startup_dir) readme = os.path.join(self.startup_dir, 'README') src = os.path.join(get_ipython_package_dir(), u'config', u'profile', u'README_STARTUP') if not os.path.exists(readme): shutil.copy(src, readme)
def _regen_header(self): """ Fills self.header with lines of CSS extracted from IPython and Pygments. """ #Clear existing header. header = [] #Construct path to IPy CSS sheet_filename = os.path.join(path.get_ipython_package_dir(), 'html', 'static', 'style', 'style.min.css') #Load style CSS file. try: with io.open(sheet_filename, encoding='utf-8') as file: file_text = file.read() header.append(file_text) except IOError: # New version of IPython with style.min.css, pass pass #Add pygments CSS pygments_css = HtmlFormatter().get_style_defs('.highlight') header.append(pygments_css) #Set header self.header = header
def check_exclusions_exist(): from IPython.utils.path import get_ipython_package_dir from IPython.utils.warn import warn parent = os.path.dirname(get_ipython_package_dir()) for sec in test_sections: for pattern in sec.exclusions: fullpath = pjoin(parent, pattern) if not os.path.exists(fullpath) and not glob.glob(fullpath + '.*'): warn("Excluding nonexistent file: %r" % pattern)
def list_bundled_profiles(): """list profiles that are bundled with IPython.""" path = os.path.join(get_ipython_package_dir(), u'config', u'profile') files = os.listdir(path) profiles = [] for profile in files: full_path = os.path.join(path, profile) if os.path.isdir(full_path) and profile != "__pycache__": profiles.append(profile) return profiles
def list_bundled_profiles(): """list profiles that are bundled with IPython.""" path = os.path.join(get_ipython_package_dir(), u"config", u"profile") files = os.listdir(path) profiles = [] for profile in files: full_path = os.path.join(path, profile) if os.path.isdir(full_path): profiles.append(profile) return profiles
def _list_bundled_profiles(self): """list profiles in a given root directory""" path = os.path.join(get_ipython_package_dir(), u'config', u'profile') files = os.listdir(path) profiles = [] for profile in files: full_path = os.path.join(path, profile) if os.path.isdir(full_path): profiles.append(profile) return profiles
def find_config_file_paths(self): """Set the search paths for resolving the config file. This must set ``self.config_file_paths`` to a sequence of search paths to pass to the config file loader. """ # Include our own profiles directory last, so that users can still find # our shipped copies of builtin profiles even if they don't have them # in their local ipython directory. prof_dir = os.path.join(get_ipython_package_dir(), 'config', 'profile') self.config_file_paths = (os.getcwdu(), self.ipython_dir, prof_dir)
def check_startup_dir(self): self._mkdir(self.startup_dir) readme = os.path.join(self.startup_dir, 'README') src = os.path.join(get_ipython_package_dir(), u'config', u'profile', u'README_STARTUP') if not os.path.exists(src): self.log.warn("Could not copy README_STARTUP to startup dir. Source file %s does not exist.", src) if os.path.exists(src) and not os.path.exists(readme): shutil.copy(src, readme)
def _ipython_dir_changed(self, name, old, new): if old in sys.path: sys.path.remove(old) sys.path.append(os.path.abspath(new)) if not os.path.isdir(new): os.makedirs(new, mode=0777) readme = os.path.join(new, 'README') if not os.path.exists(readme): path = os.path.join(get_ipython_package_dir(), u'config', u'profile') shutil.copy(os.path.join(path, 'README'), readme) self.log.debug("IPYTHON_DIR set to: %s" % new)
def _get_files_path(self): #Get the relative path to this module in the IPython directory. names = self.__module__.split('.')[1:-1] names.append('files') #Build a path using the IPython directory and the relative path we just #found. path = get_ipython_package_dir() for name in names: path = os.path.join(path, name) return path
def copy_config_file(self, config_file, path=None, overwrite=False): """Copy a default config file into the active profile directory. Default configuration files are kept in :mod:`IPython.config.default`. This function moves these from that location to the working profile directory. """ dst = os.path.join(self.location, config_file) if os.path.isfile(dst) and not overwrite: return if path is None: path = os.path.join(get_ipython_package_dir(), 'config', 'profile', 'default') src = os.path.join(path, config_file) shutil.copy(src, dst)
def test_image_filename_defaults(): '''test format constraint, and validity of jpeg and png''' tpath = ipath.get_ipython_package_dir() nt.assert_raises(ValueError, display.Image, filename=os.path.join(tpath, 'testing/tests/badformat.gif'), embed=True) nt.assert_raises(ValueError, display.Image) nt.assert_raises(ValueError, display.Image, data='this is not an image', format='badformat', embed=True) imgfile = os.path.join(tpath, 'frontend/html/notebook/static/base/images/ipynblogo.png') img = display.Image(filename=imgfile) nt.assert_equal('png', img.format) nt.assert_is_not_none(img._repr_png_()) img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False) nt.assert_equal('jpeg', img.format) nt.assert_is_none(img._repr_jpeg_())
def header_body(self): """Return the body of the header as a list of strings.""" from pygments.formatters import HtmlFormatter header = [] static = os.path.join( path.get_ipython_package_dir(), 'frontend', 'html', 'notebook', 'static', ) here = os.path.split(os.path.realpath(__file__))[0] css = os.path.join(static, 'css') for sheet in [ # do we need jquery and prettify? # os.path.join(static, 'jquery', 'css', 'themes', 'base', # 'jquery-ui.min.css'), # os.path.join(static, 'prettify', 'prettify.css'), os.path.join(css, 'boilerplate.css'), os.path.join(css, 'fbm.css'), os.path.join(css, 'notebook.css'), os.path.join(css, 'renderedhtml.css'), # our overrides: os.path.join(here, '..', 'css', 'static_html.css'), ]: header.extend(self._stylesheet(sheet)) # pygments css pygments_css = HtmlFormatter().get_style_defs('.highlight') header.extend(['<meta charset="UTF-8">']) header.extend( self.in_tag('style', pygments_css, dict(type='"text/css"'))) # TODO: this should be allowed to use local mathjax: header.extend( self.in_tag( 'script', '', { 'type': '"text/javascript"', 'src': '"https://c328740.ssl.cf1.rackcdn.com/mathjax/' 'latest/MathJax.js?config=TeX-AMS_HTML"', })) with io.open(os.path.join(here, '..', 'js', 'initmathjax.js'), encoding='utf-8') as f: header.extend( self.in_tag('script', f.read(), {'type': '"text/javascript"'})) return header
def check_startup_dir(self): self._mkdir(self.startup_dir) readme = os.path.join(self.startup_dir, 'README') src = os.path.join(get_ipython_package_dir(), u'config', u'profile', u'README_STARTUP') if not os.path.exists(src): self.log.warn( "Could not copy README_STARTUP to startup dir. Source file %s does not exist.", src) if os.path.exists(src) and not os.path.exists(readme): shutil.copy(src, readme)
def _ipython_dir_changed(self, name, old, new): str_old = py3compat.cast_bytes_py2(os.path.abspath(old), sys.getfilesystemencoding()) if str_old in sys.path: sys.path.remove(str_old) str_path = py3compat.cast_bytes_py2(os.path.abspath(new), sys.getfilesystemencoding()) sys.path.append(str_path) if not os.path.isdir(new): os.makedirs(new, mode=0o777) readme = os.path.join(new, 'README') if not os.path.exists(readme): path = os.path.join(get_ipython_package_dir(), 'config', 'profile') shutil.copy(os.path.join(path, 'README'), readme) self.log.debug("IPYTHONDIR set to: %s" % new)
def copy_config_file(self, config_file, path=None, overwrite=False): """Copy a default config file into the active profile directory. Default configuration files are kept in :mod:`IPython.config.default`. This function moves these from that location to the working profile directory. """ dst = os.path.join(self.location, config_file) if os.path.isfile(dst) and not overwrite: return False if path is None: path = os.path.join(get_ipython_package_dir(), u'config', u'profile', u'default') src = os.path.join(path, config_file) shutil.copy(src, dst) return True
def test_image_filename_defaults(): '''test format constraint, and validity of jpeg and png''' tpath = ipath.get_ipython_package_dir() nt.assert_raises(ValueError, display.Image, filename=os.path.join(tpath, 'testing/tests/badformat.gif'), embed=True) nt.assert_raises(ValueError, display.Image) nt.assert_raises(ValueError, display.Image, data='this is not an image', format='badformat', embed=True) # check boths paths to allow packages to test at build and install time imgfile = os.path.join(tpath, 'core/tests/2x2.png') img = display.Image(filename=imgfile) nt.assert_equal('png', img.format) nt.assert_is_not_none(img._repr_png_()) img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False) nt.assert_equal('jpeg', img.format) nt.assert_is_none(img._repr_jpeg_())
def _ipython_dir_changed(self, name, old, new): str_old = py3compat.cast_bytes_py2(os.path.abspath(old), sys.getfilesystemencoding() ) if str_old in sys.path: sys.path.remove(str_old) str_path = py3compat.cast_bytes_py2(os.path.abspath(new), sys.getfilesystemencoding() ) sys.path.append(str_path) if not os.path.isdir(new): os.makedirs(new, mode=0o777) readme = os.path.join(new, 'README') if not os.path.exists(readme): path = os.path.join(get_ipython_package_dir(), 'config', 'profile') shutil.copy(os.path.join(path, 'README'), readme) self.log.debug("IPYTHONDIR set to: %s" % new)
def test_image_filename_defaults(): '''test format constraint, and validity of jpeg and png''' tpath = ipath.get_ipython_package_dir() nt.assert_raises(ValueError, display.Image, filename=os.path.join(tpath, 'testing/tests/badformat.gif'), embed=True) nt.assert_raises(ValueError, display.Image) nt.assert_raises(ValueError, display.Image, data='this is not an image', format='badformat', embed=True) from IPython.html import DEFAULT_STATIC_FILES_PATH # check boths paths to allow packages to test at build and install time imgfile = os.path.join(tpath, 'html/static/base/images/logo.png') if not os.path.exists(imgfile): imgfile = os.path.join(DEFAULT_STATIC_FILES_PATH, 'base/images/logo.png') img = display.Image(filename=imgfile) nt.assert_equal('png', img.format) nt.assert_is_not_none(img._repr_png_()) img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False) nt.assert_equal('jpeg', img.format) nt.assert_is_none(img._repr_jpeg_())
def header_body(self): """Return the body of the header as a list of strings.""" from pygments.formatters import HtmlFormatter header = [] static = getattr(notebookapp, 'DEFAULT_STATIC_FILES_PATH', None) # ipython < 1.0 if static is None: static = os.path.join(path.get_ipython_package_dir(), 'frontend', 'html', 'notebook', 'static', ) here = os.path.split(os.path.realpath(__file__))[0] css = os.path.join(static, 'css') for sheet in [ # do we need jquery and prettify? # os.path.join(static, 'jquery', 'css', 'themes', 'base', # 'jquery-ui.min.css'), # os.path.join(static, 'prettify', 'prettify.css'), os.path.join(css, 'boilerplate.css'), #os.path.join(css, 'style.min.css'), # our overrides: os.path.join(here, 'css', 'static_html.css'), ]: header.extend(self._stylesheet(sheet)) # pygments css pygments_css = HtmlFormatter().get_style_defs('.highlight') header.extend(['<meta charset="UTF-8">']) header.extend(self.in_tag('style', pygments_css, dict(type='"text/css"'))) # TODO: this should be allowed to use local mathjax: header.extend(self.in_tag('script', '', {'type': '"text/javascript"', 'src': '"https://c328740.ssl.cf1.rackcdn.com/mathjax/' 'latest/MathJax.js?config=TeX-AMS_HTML"', })) with io.open(os.path.join(here, 'js', 'initmathjax.js'), encoding='utf-8') as f: header.extend(self.in_tag('script', f.read(), {'type': '"text/javascript"'})) return header
def _ipython_dir_changed(self, name, old, new): if old in sys.path: sys.path.remove(old) sys.path.append(os.path.abspath(new)) if not os.path.isdir(new): os.makedirs(new, mode=0o777) readme = os.path.join(new, 'README') readme_src = os.path.join(get_ipython_package_dir(), u'config', u'profile', 'README') if not os.path.exists(readme) and os.path.exists(readme_src): shutil.copy(readme_src, readme) for d in ('extensions', 'nbextensions'): path = os.path.join(new, d) if not os.path.exists(path): try: os.mkdir(path) except OSError as e: if e.errno != errno.EEXIST: self.log.error("couldn't create path %s: %s", path, e) self.log.debug("IPYTHONDIR set to: %s" % new)
def header_body(self): """Return the body of the header as a list of strings.""" from pygments.formatters import HtmlFormatter header = [] static = os.path.join(path.get_ipython_package_dir(), "frontend", "html", "notebook", "static") here = os.path.split(os.path.realpath(__file__))[0] css = os.path.join(static, "css") for sheet in [ # do we need jquery and prettify? # os.path.join(static, 'jquery', 'css', 'themes', 'base', 'jquery-ui.min.css'), # os.path.join(static, 'prettify', 'prettify.css'), os.path.join(css, "boilerplate.css"), os.path.join(css, "fbm.css"), os.path.join(css, "notebook.css"), os.path.join(css, "renderedhtml.css"), # our overrides: os.path.join(here, "..", "css", "static_html.css"), ]: header.extend(self._stylesheet(sheet)) # pygments css pygments_css = HtmlFormatter().get_style_defs(".highlight") header.extend(['<meta charset="UTF-8">']) header.extend(self.in_tag("style", pygments_css, dict(type='"text/css"'))) # TODO: this should be allowed to use local mathjax: header.extend( self.in_tag( "script", "", { "type": '"text/javascript"', "src": '"https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"', }, ) ) with io.open(os.path.join(here, "..", "js", "initmathjax.js"), encoding="utf-8") as f: header.extend(self.in_tag("script", f.read(), {"type": '"text/javascript"'})) return header
def regen_header(self): ## lazy load asa this might not be use in many transformers import os from IPython.utils import path import io from pygments.formatters import HtmlFormatter header = [] static = os.path.join( path.get_ipython_package_dir(), 'frontend', 'html', 'notebook', 'static', ) here = os.path.split(os.path.realpath(__file__))[0] css = os.path.join(static, 'css') for sheet in [ # do we need jquery and prettify? # os.path.join(static, 'jquery', 'css', 'themes', 'base', # 'jquery-ui.min.css'), # os.path.join(static, 'prettify', 'prettify.css'), os.path.join(css, 'boilerplate.css'), os.path.join(css, 'fbm.css'), os.path.join(css, 'notebook.css'), os.path.join(css, 'renderedhtml.css'), os.path.join(css, 'style.min.css'), # our overrides: os.path.join(here, '..', 'css', 'static_html.css'), ]: try: with io.open(sheet, encoding='utf-8') as f: s = f.read() header.append(s) except IOError: # new version of ipython with style.min.css, pass pass pygments_css = HtmlFormatter().get_style_defs('.highlight') header.append(pygments_css) self.header = header
def _ipython_dir_changed(self, name, old, new): str_old = py3compat.cast_bytes_py2(os.path.abspath(old), sys.getfilesystemencoding()) if str_old in sys.path: sys.path.remove(str_old) str_path = py3compat.cast_bytes_py2(os.path.abspath(new), sys.getfilesystemencoding()) sys.path.append(str_path) ensure_dir_exists(new) readme = os.path.join(new, 'README') readme_src = os.path.join(get_ipython_package_dir(), u'config', u'profile', 'README') if not os.path.exists(readme) and os.path.exists(readme_src): shutil.copy(readme_src, readme) for d in ('extensions', 'nbextensions'): path = os.path.join(new, d) try: ensure_dir_exists(path) except OSError: # this will not be EEXIST self.log.error("couldn't create path %s: %s", path, e) self.log.debug("IPYTHONDIR set to: %s" % new)
def optional_header(self): from pygments.formatters import HtmlFormatter header = ['<html>', '<head>'] static = os.path.join(path.get_ipython_package_dir(), 'frontend', 'html', 'notebook', 'static', ) here = os.path.split(os.path.abspath(__file__))[0] css = os.path.join(static, 'css') for sheet in [ # do we need jquery and prettify? # os.path.join(static, 'jquery', 'css', 'themes', 'base', 'jquery-ui.min.css'), # os.path.join(static, 'prettify', 'prettify.css'), os.path.join(css, 'boilerplate.css'), os.path.join(css, 'fbm.css'), os.path.join(css, 'notebook.css'), os.path.join(css, 'renderedhtml.css'), # our overrides: os.path.join(here, 'css', 'static_html.css'), ]: header.extend(self._stylesheet(sheet)) # pygments css pygments_css = HtmlFormatter().get_style_defs('.highlight') header.extend(['<meta charset="UTF-8">']) header.extend(self.in_tag('style', pygments_css, dict(type='text/css'))) # TODO: this should be allowed to use local mathjax: header.extend(self.in_tag('script', '', {'type':'text/javascript', 'src': '"https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"', })) with io.open(os.path.join(here, 'js', 'initmathjax.js'), encoding='utf-8') as f: header.extend(self.in_tag('script', f.read(), {'type': 'text/javascript'})) header.extend(['</head>', '<body>']) return header
def test_image_filename_defaults(): '''test format constraint, and validity of jpeg and png''' tpath = ipath.get_ipython_package_dir() nt.assert_raises(ValueError, display.Image, filename=os.path.join(tpath, 'testing/tests/badformat.gif'), embed=True) nt.assert_raises(ValueError, display.Image) nt.assert_raises(ValueError, display.Image, data='this is not an image', format='badformat', embed=True) imgfile = os.path.join(tpath, 'frontend/html/notebook/static/ipynblogo.png') img = display.Image(filename=imgfile) nt.assert_equal('png', img.format) nt.assert_is_not_none(img._repr_png_()) img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False) nt.assert_equal('jpeg', img.format) nt.assert_is_none(img._repr_jpeg_())
def __init__(self, config=None, **kw): super(CSSHtmlHeaderTransformer, self).__init__(config=config, **kw) if self.enabled : self.regen_header() def regen_header(self): import os from IPython.utils import path import io from pygments.formatters import HtmlFormatter header = [] static = os.path.join(path.get_ipython_package_dir(), 'frontend', 'html', 'notebook', 'static', ) here = os.path.split(os.path.realpath(__file__))[0] css = os.path.join(static, 'css') for sheet in [ os.path.join(css, 'boilerplate.css'), os.path.join(css, 'fbm.css'), os.path.join(css, 'notebook.css'), os.path.join(css, 'renderedhtml.css'), os.path.join(css, 'style.min.css'), os.path.join(here, '..', 'css', 'static_html.css'), ]: try: with io.open(sheet, encoding='utf-8') as f: s = f.read() header.append(s) except IOError: pass pygments_css = HtmlFormatter().get_style_defs('.highlight') header.append(pygments_css) self.header = header
def _profile_changed(self, name, old, new): self.builtin_profile_dir = os.path.join( get_ipython_package_dir(), u'config', u'profile', new )
def is_package(): """Is a package manager responsible for the static files path?""" from IPython.utils.path import get_ipython_package_dir from IPython.frontend.html.notebook import DEFAULT_STATIC_FILES_PATH return not DEFAULT_STATIC_FILES_PATH.startswith(get_ipython_package_dir())
def find_config_file_paths(self): # Set the search path to to the cluster directory. We should NOT # include IPython.config.default here as the default config files # are ALWAYS automatically moved to the cluster directory. conf_dir = os.path.join(get_ipython_package_dir(), 'config', 'default') self.config_file_paths = (self.cluster_dir,)
def test_get_ipython_package_dir(): ipdir = path.get_ipython_package_dir() nt.assert_true(os.path.isdir(ipdir))
def make_exclude(): """Make patterns of modules and packages to exclude from testing. For the IPythonDoctest plugin, we need to exclude certain patterns that cause testing problems. We should strive to minimize the number of skipped modules, since this means untested code. These modules and packages will NOT get scanned by nose at all for tests. """ # Simple utility to make IPython paths more readably, we need a lot of # these below ipjoin = lambda *paths: pjoin('IPython', *paths) exclusions = [ipjoin('external'), ipjoin('quarantine'), ipjoin('deathrow'), # This guy is probably attic material ipjoin('testing', 'mkdoctests'), # Testing inputhook will need a lot of thought, to figure out # how to have tests that don't lock up with the gui event # loops in the picture ipjoin('lib', 'inputhook'), # Config files aren't really importable stand-alone ipjoin('config', 'profile'), ] if not have['sqlite3']: exclusions.append(ipjoin('core', 'tests', 'test_history')) exclusions.append(ipjoin('core', 'history')) if not have['wx']: exclusions.append(ipjoin('lib', 'inputhookwx')) # We do this unconditionally, so that the test suite doesn't import # gtk, changing the default encoding and masking some unicode bugs. exclusions.append(ipjoin('lib', 'inputhookgtk')) exclusions.append(ipjoin('zmq', 'gui', 'gtkembed')) # These have to be skipped on win32 because the use echo, rm, cd, etc. # See ticket https://github.com/ipython/ipython/issues/87 if sys.platform == 'win32': exclusions.append(ipjoin('testing', 'plugin', 'test_exampleip')) exclusions.append(ipjoin('testing', 'plugin', 'dtexample')) if not have['pexpect']: exclusions.extend([ipjoin('scripts', 'irunner'), ipjoin('lib', 'irunner'), ipjoin('lib', 'tests', 'test_irunner'), ipjoin('frontend', 'terminal', 'console'), ]) if not have['zmq']: exclusions.append(ipjoin('zmq')) exclusions.append(ipjoin('frontend', 'qt')) exclusions.append(ipjoin('frontend', 'html')) exclusions.append(ipjoin('frontend', 'consoleapp.py')) exclusions.append(ipjoin('frontend', 'terminal', 'console')) exclusions.append(ipjoin('parallel')) elif not have['qt'] or not have['pygments']: exclusions.append(ipjoin('frontend', 'qt')) if not have['pymongo']: exclusions.append(ipjoin('parallel', 'controller', 'mongodb')) exclusions.append(ipjoin('parallel', 'tests', 'test_mongodb')) if not have['matplotlib']: exclusions.extend([ipjoin('core', 'pylabtools'), ipjoin('core', 'tests', 'test_pylabtools'), ipjoin('zmq', 'pylab'), ]) if not have['cython']: exclusions.extend([ipjoin('extensions', 'cythonmagic')]) exclusions.extend([ipjoin('extensions', 'tests', 'test_cythonmagic')]) if not have['tornado']: exclusions.append(ipjoin('frontend', 'html')) if not have['rpy2'] or not have['numpy']: exclusions.append(ipjoin('extensions', 'rmagic')) exclusions.append(ipjoin('extensions', 'tests', 'test_rmagic')) # This is needed for the reg-exp to match on win32 in the ipdoctest plugin. if sys.platform == 'win32': exclusions = [s.replace('\\','\\\\') for s in exclusions] # check for any exclusions that don't seem to exist: parent, _ = os.path.split(get_ipython_package_dir()) for exclusion in exclusions: fullpath = pjoin(parent, exclusion) if not os.path.exists(fullpath) and not os.path.exists(fullpath + '.py'): warn("Excluding nonexistent file: %r\n" % exclusion) return exclusions
def ipython_parent(): """return IPython's parent (i.e. root if run from git)""" from IPython.utils.path import get_ipython_package_dir return os.path.abspath(os.path.dirname(get_ipython_package_dir()))
def make_exclude(): """Make patterns of modules and packages to exclude from testing. For the IPythonDoctest plugin, we need to exclude certain patterns that cause testing problems. We should strive to minimize the number of skipped modules, since this means untested code. These modules and packages will NOT get scanned by nose at all for tests. """ # Simple utility to make IPython paths more readably, we need a lot of # these below ipjoin = lambda *paths: pjoin("IPython", *paths) exclusions = [ ipjoin("external"), ipjoin("quarantine"), ipjoin("deathrow"), # This guy is probably attic material ipjoin("testing", "mkdoctests"), # Testing inputhook will need a lot of thought, to figure out # how to have tests that don't lock up with the gui event # loops in the picture ipjoin("lib", "inputhook"), # Config files aren't really importable stand-alone ipjoin("config", "profile"), # The notebook 'static' directory contains JS, css and other # files for web serving. Occasionally projects may put a .py # file in there (MathJax ships a conf.py), so we might as # well play it safe and skip the whole thing. ipjoin("html", "static"), ipjoin("html", "fabfile"), ] if not have["sqlite3"]: exclusions.append(ipjoin("core", "tests", "test_history")) exclusions.append(ipjoin("core", "history")) if not have["wx"]: exclusions.append(ipjoin("lib", "inputhookwx")) if "IPython.kernel.inprocess" not in sys.argv: exclusions.append(ipjoin("kernel", "inprocess")) # FIXME: temporarily disable autoreload tests, as they can produce # spurious failures in subsequent tests (cythonmagic). exclusions.append(ipjoin("extensions", "autoreload")) exclusions.append(ipjoin("extensions", "tests", "test_autoreload")) # We do this unconditionally, so that the test suite doesn't import # gtk, changing the default encoding and masking some unicode bugs. exclusions.append(ipjoin("lib", "inputhookgtk")) exclusions.append(ipjoin("kernel", "zmq", "gui", "gtkembed")) # Also done unconditionally, exclude nbconvert directories containing # config files used to test. Executing the config files with iptest would # cause an exception. exclusions.append(ipjoin("nbconvert", "tests", "files")) exclusions.append(ipjoin("nbconvert", "exporters", "tests", "files")) # These have to be skipped on win32 because the use echo, rm, cd, etc. # See ticket https://github.com/ipython/ipython/issues/87 if sys.platform == "win32": exclusions.append(ipjoin("testing", "plugin", "test_exampleip")) exclusions.append(ipjoin("testing", "plugin", "dtexample")) if not have["pexpect"]: exclusions.extend( [ipjoin("lib", "irunner"), ipjoin("lib", "tests", "test_irunner"), ipjoin("terminal", "console")] ) if not have["zmq"]: exclusions.append(ipjoin("lib", "kernel")) exclusions.append(ipjoin("kernel")) exclusions.append(ipjoin("qt")) exclusions.append(ipjoin("html")) exclusions.append(ipjoin("consoleapp.py")) exclusions.append(ipjoin("terminal", "console")) exclusions.append(ipjoin("parallel")) elif not have["qt"] or not have["pygments"]: exclusions.append(ipjoin("qt")) if not have["pymongo"]: exclusions.append(ipjoin("parallel", "controller", "mongodb")) exclusions.append(ipjoin("parallel", "tests", "test_mongodb")) if not have["matplotlib"]: exclusions.extend( [ipjoin("core", "pylabtools"), ipjoin("core", "tests", "test_pylabtools"), ipjoin("kernel", "zmq", "pylab")] ) if not have["cython"]: exclusions.extend([ipjoin("extensions", "cythonmagic")]) exclusions.extend([ipjoin("extensions", "tests", "test_cythonmagic")]) if not have["oct2py"]: exclusions.extend([ipjoin("extensions", "octavemagic")]) exclusions.extend([ipjoin("extensions", "tests", "test_octavemagic")]) if not have["tornado"]: exclusions.append(ipjoin("html")) if not have["jinja2"]: exclusions.append(ipjoin("html", "notebookapp")) if not have["rpy2"] or not have["numpy"]: exclusions.append(ipjoin("extensions", "rmagic")) exclusions.append(ipjoin("extensions", "tests", "test_rmagic")) if not have["azure"]: exclusions.append(ipjoin("html", "services", "notebooks", "azurenbmanager")) if not all((have["pygments"], have["jinja2"], have["sphinx"])): exclusions.append(ipjoin("nbconvert")) # This is needed for the reg-exp to match on win32 in the ipdoctest plugin. if sys.platform == "win32": exclusions = [s.replace("\\", "\\\\") for s in exclusions] # check for any exclusions that don't seem to exist: parent, _ = os.path.split(get_ipython_package_dir()) for exclusion in exclusions: if exclusion.endswith(("deathrow", "quarantine")): # ignore deathrow/quarantine, which exist in dev, but not install continue fullpath = pjoin(parent, exclusion) if not os.path.exists(fullpath) and not glob.glob(fullpath + ".*"): warn("Excluding nonexistent file: %r" % exclusion) return exclusions
def _profile_changed(self, name, old, new): self.builtin_profile_dir = os.path.join(get_ipython_package_dir(), u'config', u'profile', new)
def make_exclude(): """Make patterns of modules and packages to exclude from testing. For the IPythonDoctest plugin, we need to exclude certain patterns that cause testing problems. We should strive to minimize the number of skipped modules, since this means untested code. These modules and packages will NOT get scanned by nose at all for tests. """ # Simple utility to make IPython paths more readably, we need a lot of # these below ipjoin = lambda *paths: pjoin('IPython', *paths) exclusions = [ ipjoin('external'), ipjoin('quarantine'), ipjoin('deathrow'), # This guy is probably attic material ipjoin('testing', 'mkdoctests'), # Testing inputhook will need a lot of thought, to figure out # how to have tests that don't lock up with the gui event # loops in the picture ipjoin('lib', 'inputhook'), # Config files aren't really importable stand-alone ipjoin('config', 'profile'), # The notebook 'static' directory contains JS, css and other # files for web serving. Occasionally projects may put a .py # file in there (MathJax ships a conf.py), so we might as # well play it safe and skip the whole thing. ipjoin('frontend', 'html', 'notebook', 'static'), ipjoin('frontend', 'html', 'notebook', 'fabfile'), ] if not have['sqlite3']: exclusions.append(ipjoin('core', 'tests', 'test_history')) exclusions.append(ipjoin('core', 'history')) if not have['wx']: exclusions.append(ipjoin('lib', 'inputhookwx')) if 'IPython.kernel.inprocess' not in sys.argv: exclusions.append(ipjoin('kernel', 'inprocess')) # FIXME: temporarily disable autoreload tests, as they can produce # spurious failures in subsequent tests (cythonmagic). exclusions.append(ipjoin('extensions', 'autoreload')) exclusions.append(ipjoin('extensions', 'tests', 'test_autoreload')) # We do this unconditionally, so that the test suite doesn't import # gtk, changing the default encoding and masking some unicode bugs. exclusions.append(ipjoin('lib', 'inputhookgtk')) exclusions.append(ipjoin('kernel', 'zmq', 'gui', 'gtkembed')) # These have to be skipped on win32 because the use echo, rm, cd, etc. # See ticket https://github.com/ipython/ipython/issues/87 if sys.platform == 'win32': exclusions.append(ipjoin('testing', 'plugin', 'test_exampleip')) exclusions.append(ipjoin('testing', 'plugin', 'dtexample')) if not have['pexpect']: exclusions.extend([ ipjoin('lib', 'irunner'), ipjoin('lib', 'tests', 'test_irunner'), ipjoin('frontend', 'terminal', 'console'), ]) if not have['zmq']: exclusions.append(ipjoin('kernel')) exclusions.append(ipjoin('frontend', 'qt')) exclusions.append(ipjoin('frontend', 'html')) exclusions.append(ipjoin('frontend', 'consoleapp.py')) exclusions.append(ipjoin('frontend', 'terminal', 'console')) exclusions.append(ipjoin('parallel')) elif not have['qt'] or not have['pygments']: exclusions.append(ipjoin('frontend', 'qt')) if not have['pymongo']: exclusions.append(ipjoin('parallel', 'controller', 'mongodb')) exclusions.append(ipjoin('parallel', 'tests', 'test_mongodb')) if not have['matplotlib']: exclusions.extend([ ipjoin('core', 'pylabtools'), ipjoin('core', 'tests', 'test_pylabtools'), ipjoin('kernel', 'zmq', 'pylab'), ]) if not have['cython']: exclusions.extend([ipjoin('extensions', 'cythonmagic')]) exclusions.extend([ipjoin('extensions', 'tests', 'test_cythonmagic')]) if not have['oct2py']: exclusions.extend([ipjoin('extensions', 'octavemagic')]) exclusions.extend([ipjoin('extensions', 'tests', 'test_octavemagic')]) if not have['tornado']: exclusions.append(ipjoin('frontend', 'html')) if not have['jinja2']: exclusions.append(ipjoin('frontend', 'html', 'notebook', 'notebookapp')) if not have['rpy2'] or not have['numpy']: exclusions.append(ipjoin('extensions', 'rmagic')) exclusions.append(ipjoin('extensions', 'tests', 'test_rmagic')) if not have['azure']: exclusions.append( ipjoin('frontend', 'html', 'notebook', 'services', 'notebooks', 'azurenbmanager')) # This is needed for the reg-exp to match on win32 in the ipdoctest plugin. if sys.platform == 'win32': exclusions = [s.replace('\\', '\\\\') for s in exclusions] # check for any exclusions that don't seem to exist: parent, _ = os.path.split(get_ipython_package_dir()) for exclusion in exclusions: if exclusion.endswith(('deathrow', 'quarantine')): # ignore deathrow/quarantine, which exist in dev, but not install continue fullpath = pjoin(parent, exclusion) if not os.path.exists(fullpath) and not glob.glob(fullpath + '.*'): warn("Excluding nonexistent file: %r" % exclusion) return exclusions
def find_config_file_paths(self): # Set the search path to to the cluster directory. We should NOT # include IPython.config.default here as the default config files # are ALWAYS automatically moved to the cluster directory. conf_dir = os.path.join(get_ipython_package_dir(), 'config', 'default') self.config_file_paths = (self.cluster_dir, )
def make_exclude(): """Make patterns of modules and packages to exclude from testing. For the IPythonDoctest plugin, we need to exclude certain patterns that cause testing problems. We should strive to minimize the number of skipped modules, since this means untested code. These modules and packages will NOT get scanned by nose at all for tests. """ # Simple utility to make IPython paths more readably, we need a lot of # these below ipjoin = lambda *paths: pjoin('IPython', *paths) exclusions = [ ipjoin('external'), ipjoin('quarantine'), ipjoin('deathrow'), # This guy is probably attic material ipjoin('testing', 'mkdoctests'), # Testing inputhook will need a lot of thought, to figure out # how to have tests that don't lock up with the gui event # loops in the picture ipjoin('lib', 'inputhook'), # Config files aren't really importable stand-alone ipjoin('config', 'profile'), ] if not have['sqlite3']: exclusions.append(ipjoin('core', 'tests', 'test_history')) exclusions.append(ipjoin('core', 'history')) if not have['wx']: exclusions.append(ipjoin('lib', 'inputhookwx')) # We do this unconditionally, so that the test suite doesn't import # gtk, changing the default encoding and masking some unicode bugs. exclusions.append(ipjoin('lib', 'inputhookgtk')) exclusions.append(ipjoin('zmq', 'gui', 'gtkembed')) # These have to be skipped on win32 because the use echo, rm, cd, etc. # See ticket https://github.com/ipython/ipython/issues/87 if sys.platform == 'win32': exclusions.append(ipjoin('testing', 'plugin', 'test_exampleip')) exclusions.append(ipjoin('testing', 'plugin', 'dtexample')) if not have['pexpect']: exclusions.extend([ ipjoin('scripts', 'irunner'), ipjoin('lib', 'irunner'), ipjoin('lib', 'tests', 'test_irunner'), ipjoin('frontend', 'terminal', 'console'), ]) if not have['zmq']: exclusions.append(ipjoin('zmq')) exclusions.append(ipjoin('frontend', 'qt')) exclusions.append(ipjoin('frontend', 'html')) exclusions.append(ipjoin('frontend', 'consoleapp.py')) exclusions.append(ipjoin('frontend', 'terminal', 'console')) exclusions.append(ipjoin('parallel')) elif not have['qt'] or not have['pygments']: exclusions.append(ipjoin('frontend', 'qt')) if not have['pymongo']: exclusions.append(ipjoin('parallel', 'controller', 'mongodb')) exclusions.append(ipjoin('parallel', 'tests', 'test_mongodb')) if not have['matplotlib']: exclusions.extend([ ipjoin('core', 'pylabtools'), ipjoin('core', 'tests', 'test_pylabtools'), ipjoin('zmq', 'pylab'), ]) if not have['cython']: exclusions.extend([ipjoin('extensions', 'cythonmagic')]) exclusions.extend([ipjoin('extensions', 'tests', 'test_cythonmagic')]) if not have['tornado']: exclusions.append(ipjoin('frontend', 'html')) if not have['rpy2'] or not have['numpy']: exclusions.append(ipjoin('extensions', 'rmagic')) exclusions.append(ipjoin('extensions', 'tests', 'test_rmagic')) # This is needed for the reg-exp to match on win32 in the ipdoctest plugin. if sys.platform == 'win32': exclusions = [s.replace('\\', '\\\\') for s in exclusions] # check for any exclusions that don't seem to exist: parent, _ = os.path.split(get_ipython_package_dir()) for exclusion in exclusions: fullpath = pjoin(parent, exclusion) if not os.path.exists(fullpath) and not os.path.exists(fullpath + '.py'): warn("Excluding nonexistent file: %r\n" % exclusion) return exclusions
class BaseIPythonApplication(Application): name = Unicode(u'ipython') description = Unicode(u'IPython: an enhanced interactive Python shell.') version = Unicode(release.version) aliases = Dict(base_aliases) flags = Dict(base_flags) classes = List([ProfileDir]) # Track whether the config_file has changed, # because some logic happens only if we aren't using the default. config_file_specified = Bool(False) config_file_name = Unicode(u'ipython_config.py') def _config_file_name_default(self): return self.name.replace('-', '_') + u'_config.py' def _config_file_name_changed(self, name, old, new): if new != old: self.config_file_specified = True # The directory that contains IPython's builtin profiles. builtin_profile_dir = Unicode( os.path.join(get_ipython_package_dir(), u'config', u'profile', u'default')) config_file_paths = List(Unicode) def _config_file_paths_default(self): return [os.getcwdu()] profile = Unicode(u'default', config=True, help="""The IPython profile to use.""") def _profile_changed(self, name, old, new): self.builtin_profile_dir = os.path.join(get_ipython_package_dir(), u'config', u'profile', new) ipython_dir = Unicode(get_ipython_dir(), config=True, help=""" The name of the IPython directory. This directory is used for logging configuration (through profiles), history storage, etc. The default is usually $HOME/.ipython. This options can also be specified through the environment variable IPYTHON_DIR. """) overwrite = Bool( False, config=True, help="""Whether to overwrite existing config files when copying""") auto_create = Bool( False, config=True, help="""Whether to create profile dir if it doesn't exist""") config_files = List(Unicode) def _config_files_default(self): return [u'ipython_config.py'] copy_config_files = Bool( False, config=True, help="""Whether to install the default config files into the profile dir. If a new profile is being created, and IPython contains config files for that profile, then they will be staged into the new directory. Otherwise, default config files will be automatically generated. """) # The class to use as the crash handler. crash_handler_class = Type(crashhandler.CrashHandler) def __init__(self, **kwargs): super(BaseIPythonApplication, self).__init__(**kwargs) # ensure even default IPYTHON_DIR exists if not os.path.exists(self.ipython_dir): self._ipython_dir_changed('ipython_dir', self.ipython_dir, self.ipython_dir) #------------------------------------------------------------------------- # Various stages of Application creation #------------------------------------------------------------------------- def init_crash_handler(self): """Create a crash handler, typically setting sys.excepthook to it.""" self.crash_handler = self.crash_handler_class(self) sys.excepthook = self.crash_handler def _ipython_dir_changed(self, name, old, new): if old in sys.path: sys.path.remove(old) sys.path.append(os.path.abspath(new)) if not os.path.isdir(new): os.makedirs(new, mode=0777) readme = os.path.join(new, 'README') if not os.path.exists(readme): path = os.path.join(get_ipython_package_dir(), u'config', u'profile') shutil.copy(os.path.join(path, 'README'), readme) self.log.debug("IPYTHON_DIR set to: %s" % new) def load_config_file(self, suppress_errors=True): """Load the config file. By default, errors in loading config are handled, and a warning printed on screen. For testing, the suppress_errors option is set to False, so errors will make tests fail. """ base_config = 'ipython_config.py' self.log.debug("Attempting to load config file: %s" % base_config) try: Application.load_config_file(self, base_config, path=self.config_file_paths) except IOError: # ignore errors loading parent pass if self.config_file_name == base_config: # don't load secondary config return self.log.debug("Attempting to load config file: %s" % self.config_file_name) try: Application.load_config_file(self, self.config_file_name, path=self.config_file_paths) except IOError: # Only warn if the default config file was NOT being used. if self.config_file_specified: self.log.warn("Config file not found, skipping: %s" % self.config_file_name) except: # For testing purposes. if not suppress_errors: raise self.log.warn("Error loading config file: %s" % self.config_file_name, exc_info=True) def init_profile_dir(self): """initialize the profile dir""" try: # location explicitly specified: location = self.config.ProfileDir.location except AttributeError: # location not specified, find by profile name try: p = ProfileDir.find_profile_dir_by_name( self.ipython_dir, self.profile, self.config) except ProfileDirError: # not found, maybe create it (always create default profile) if self.auto_create or self.profile == 'default': try: p = ProfileDir.create_profile_dir_by_name( self.ipython_dir, self.profile, self.config) except ProfileDirError: self.log.fatal("Could not create profile: %r" % self.profile) self.exit(1) else: self.log.info("Created profile dir: %r" % p.location) else: self.log.fatal("Profile %r not found." % self.profile) self.exit(1) else: self.log.info("Using existing profile dir: %r" % p.location) else: # location is fully specified try: p = ProfileDir.find_profile_dir(location, self.config) except ProfileDirError: # not found, maybe create it if self.auto_create: try: p = ProfileDir.create_profile_dir( location, self.config) except ProfileDirError: self.log.fatal( "Could not create profile directory: %r" % location) self.exit(1) else: self.log.info("Creating new profile dir: %r" % location) else: self.log.fatal("Profile directory %r not found." % location) self.exit(1) else: self.log.info("Using existing profile dir: %r" % location) self.profile_dir = p self.config_file_paths.append(p.location) def init_config_files(self): """[optionally] copy default config files into profile dir.""" # copy config files path = self.builtin_profile_dir if self.copy_config_files: src = self.profile cfg = self.config_file_name if path and os.path.exists(os.path.join(path, cfg)): self.log.warn( "Staging %r from %s into %r [overwrite=%s]" % (cfg, src, self.profile_dir.location, self.overwrite)) self.profile_dir.copy_config_file(cfg, path=path, overwrite=self.overwrite) else: self.stage_default_config_file() else: # Still stage *bundled* config files, but not generated ones # This is necessary for `ipython profile=sympy` to load the profile # on the first go files = glob.glob(os.path.join(path, '*.py')) for fullpath in files: cfg = os.path.basename(fullpath) if self.profile_dir.copy_config_file(cfg, path=path, overwrite=False): # file was copied self.log.warn( "Staging bundled %s from %s into %r" % (cfg, self.profile, self.profile_dir.location)) def stage_default_config_file(self): """auto generate default config file, and stage it into the profile.""" s = self.generate_config_file() fname = os.path.join(self.profile_dir.location, self.config_file_name) if self.overwrite or not os.path.exists(fname): self.log.warn("Generating default config file: %r" % (fname)) with open(fname, 'w') as f: f.write(s) def initialize(self, argv=None): # don't hook up crash handler before parsing command-line self.parse_command_line(argv) self.init_crash_handler() if self.subapp is not None: # stop here if subapp is taking over return cl_config = self.config self.init_profile_dir() self.init_config_files() self.load_config_file() # enforce cl-opts override configfile opts: self.update_config(cl_config)
def make_exclude(): """Make patterns of modules and packages to exclude from testing. For the IPythonDoctest plugin, we need to exclude certain patterns that cause testing problems. We should strive to minimize the number of skipped modules, since this means untested code. These modules and packages will NOT get scanned by nose at all for tests. """ # Simple utility to make IPython paths more readably, we need a lot of # these below ipjoin = lambda *paths: pjoin('IPython', *paths) exclusions = [ipjoin('external'), ipjoin('quarantine'), ipjoin('deathrow'), # This guy is probably attic material ipjoin('testing', 'mkdoctests'), # Testing inputhook will need a lot of thought, to figure out # how to have tests that don't lock up with the gui event # loops in the picture ipjoin('lib', 'inputhook'), # Config files aren't really importable stand-alone ipjoin('config', 'profile'), # The notebook 'static' directory contains JS, css and other # files for web serving. Occasionally projects may put a .py # file in there (MathJax ships a conf.py), so we might as # well play it safe and skip the whole thing. ipjoin('html', 'static'), ipjoin('html', 'fabfile'), ] if not have['sqlite3']: exclusions.append(ipjoin('core', 'tests', 'test_history')) exclusions.append(ipjoin('core', 'history')) if not have['wx']: exclusions.append(ipjoin('lib', 'inputhookwx')) if 'IPython.kernel.inprocess' not in sys.argv: exclusions.append(ipjoin('kernel', 'inprocess')) # FIXME: temporarily disable autoreload tests, as they can produce # spurious failures in subsequent tests (cythonmagic). exclusions.append(ipjoin('extensions', 'autoreload')) exclusions.append(ipjoin('extensions', 'tests', 'test_autoreload')) # We do this unconditionally, so that the test suite doesn't import # gtk, changing the default encoding and masking some unicode bugs. exclusions.append(ipjoin('lib', 'inputhookgtk')) exclusions.append(ipjoin('kernel', 'zmq', 'gui', 'gtkembed')) #Also done unconditionally, exclude nbconvert directories containing #config files used to test. Executing the config files with iptest would #cause an exception. exclusions.append(ipjoin('nbconvert', 'tests', 'files')) exclusions.append(ipjoin('nbconvert', 'exporters', 'tests', 'files')) # These have to be skipped on win32 because the use echo, rm, cd, etc. # See ticket https://github.com/ipython/ipython/issues/87 if sys.platform == 'win32': exclusions.append(ipjoin('testing', 'plugin', 'test_exampleip')) exclusions.append(ipjoin('testing', 'plugin', 'dtexample')) if not have['pexpect']: exclusions.extend([ipjoin('lib', 'irunner'), ipjoin('lib', 'tests', 'test_irunner'), ipjoin('terminal', 'console'), ]) if not have['zmq']: exclusions.append(ipjoin('lib', 'kernel')) exclusions.append(ipjoin('kernel')) exclusions.append(ipjoin('qt')) exclusions.append(ipjoin('html')) exclusions.append(ipjoin('consoleapp.py')) exclusions.append(ipjoin('terminal', 'console')) exclusions.append(ipjoin('parallel')) elif not have['qt'] or not have['pygments']: exclusions.append(ipjoin('qt')) if not have['pymongo']: exclusions.append(ipjoin('parallel', 'controller', 'mongodb')) exclusions.append(ipjoin('parallel', 'tests', 'test_mongodb')) if not have['matplotlib']: exclusions.extend([ipjoin('core', 'pylabtools'), ipjoin('core', 'tests', 'test_pylabtools'), ipjoin('kernel', 'zmq', 'pylab'), ]) if not have['cython']: exclusions.extend([ipjoin('extensions', 'cythonmagic')]) exclusions.extend([ipjoin('extensions', 'tests', 'test_cythonmagic')]) if not have['oct2py']: exclusions.extend([ipjoin('extensions', 'octavemagic')]) exclusions.extend([ipjoin('extensions', 'tests', 'test_octavemagic')]) if not have['tornado']: exclusions.append(ipjoin('html')) exclusions.append(ipjoin('nbconvert', 'post_processors', 'serve')) exclusions.append(ipjoin('nbconvert', 'post_processors', 'tests', 'test_serve')) if not have['jinja2']: exclusions.append(ipjoin('html', 'notebookapp')) if not have['rpy2'] or not have['numpy']: exclusions.append(ipjoin('extensions', 'rmagic')) exclusions.append(ipjoin('extensions', 'tests', 'test_rmagic')) if not have['azure']: exclusions.append(ipjoin('html', 'services', 'notebooks', 'azurenbmanager')) if not all((have['pygments'], have['jinja2'], have['sphinx'])): exclusions.append(ipjoin('nbconvert')) # This is needed for the reg-exp to match on win32 in the ipdoctest plugin. if sys.platform == 'win32': exclusions = [s.replace('\\','\\\\') for s in exclusions] # check for any exclusions that don't seem to exist: parent, _ = os.path.split(get_ipython_package_dir()) for exclusion in exclusions: if exclusion.endswith(('deathrow', 'quarantine')): # ignore deathrow/quarantine, which exist in dev, but not install continue fullpath = pjoin(parent, exclusion) if not os.path.exists(fullpath) and not glob.glob(fullpath + '.*'): warn("Excluding nonexistent file: %r" % exclusion) return exclusions
class BaseIPythonApplication(Application): name = Unicode(u'ipython') description = Unicode(u'IPython: an enhanced interactive Python shell.') version = Unicode(release.version) aliases = Dict(base_aliases) flags = Dict(base_flags) classes = List([ProfileDir]) # Track whether the config_file has changed, # because some logic happens only if we aren't using the default. config_file_specified = Set() config_file_name = Unicode() def _config_file_name_default(self): return self.name.replace('-', '_') + u'_config.py' def _config_file_name_changed(self, name, old, new): if new != old: self.config_file_specified.add(new) # The directory that contains IPython's builtin profiles. builtin_profile_dir = Unicode( os.path.join(get_ipython_package_dir(), u'config', u'profile', u'default')) config_file_paths = List(Unicode) def _config_file_paths_default(self): return [py3compat.getcwd()] extra_config_file = Unicode(config=True, help="""Path to an extra config file to load. If specified, load this config file in addition to any other IPython config. """) def _extra_config_file_changed(self, name, old, new): try: self.config_files.remove(old) except ValueError: pass self.config_file_specified.add(new) self.config_files.append(new) profile = Unicode(u'default', config=True, help="""The IPython profile to use.""") def _profile_changed(self, name, old, new): self.builtin_profile_dir = os.path.join(get_ipython_package_dir(), u'config', u'profile', new) ipython_dir = Unicode(config=True, help=""" The name of the IPython directory. This directory is used for logging configuration (through profiles), history storage, etc. The default is usually $HOME/.ipython. This options can also be specified through the environment variable IPYTHONDIR. """) def _ipython_dir_default(self): d = get_ipython_dir() self._ipython_dir_changed('ipython_dir', d, d) return d _in_init_profile_dir = False profile_dir = Instance(ProfileDir) def _profile_dir_default(self): # avoid recursion if self._in_init_profile_dir: return # profile_dir requested early, force initialization self.init_profile_dir() return self.profile_dir overwrite = Bool( False, config=True, help="""Whether to overwrite existing config files when copying""") auto_create = Bool( False, config=True, help="""Whether to create profile dir if it doesn't exist""") config_files = List(Unicode) def _config_files_default(self): return [self.config_file_name] copy_config_files = Bool( False, config=True, help="""Whether to install the default config files into the profile dir. If a new profile is being created, and IPython contains config files for that profile, then they will be staged into the new directory. Otherwise, default config files will be automatically generated. """) verbose_crash = Bool( False, config=True, help= """Create a massive crash report when IPython encounters what may be an internal error. The default is to append a short message to the usual traceback""") # The class to use as the crash handler. crash_handler_class = Type(crashhandler.CrashHandler) @catch_config_error def __init__(self, **kwargs): super(BaseIPythonApplication, self).__init__(**kwargs) # ensure current working directory exists try: directory = py3compat.getcwd() except: # raise exception self.log.error("Current working directory doesn't exist.") raise #------------------------------------------------------------------------- # Various stages of Application creation #------------------------------------------------------------------------- def init_crash_handler(self): """Create a crash handler, typically setting sys.excepthook to it.""" self.crash_handler = self.crash_handler_class(self) sys.excepthook = self.excepthook def unset_crashhandler(): sys.excepthook = sys.__excepthook__ atexit.register(unset_crashhandler) def excepthook(self, etype, evalue, tb): """this is sys.excepthook after init_crashhandler set self.verbose_crash=True to use our full crashhandler, instead of a regular traceback with a short message (crash_handler_lite) """ if self.verbose_crash: return self.crash_handler(etype, evalue, tb) else: return crashhandler.crash_handler_lite(etype, evalue, tb) def _ipython_dir_changed(self, name, old, new): if old in sys.path: sys.path.remove(old) sys.path.append(os.path.abspath(new)) if not os.path.isdir(new): os.makedirs(new, mode=0o777) readme = os.path.join(new, 'README') readme_src = os.path.join(get_ipython_package_dir(), u'config', u'profile', 'README') if not os.path.exists(readme) and os.path.exists(readme_src): shutil.copy(readme_src, readme) for d in ('extensions', 'nbextensions'): path = os.path.join(new, d) if not os.path.exists(path): try: os.mkdir(path) except OSError as e: if e.errno != errno.EEXIST: self.log.error("couldn't create path %s: %s", path, e) self.log.debug("IPYTHONDIR set to: %s" % new) def load_config_file(self, suppress_errors=True): """Load the config file. By default, errors in loading config are handled, and a warning printed on screen. For testing, the suppress_errors option is set to False, so errors will make tests fail. """ self.log.debug("Searching path %s for config files", self.config_file_paths) base_config = 'ipython_config.py' self.log.debug("Attempting to load config file: %s" % base_config) try: Application.load_config_file(self, base_config, path=self.config_file_paths) except ConfigFileNotFound: # ignore errors loading parent self.log.debug("Config file %s not found", base_config) pass for config_file_name in self.config_files: if not config_file_name or config_file_name == base_config: continue self.log.debug("Attempting to load config file: %s" % self.config_file_name) try: Application.load_config_file(self, config_file_name, path=self.config_file_paths) except ConfigFileNotFound: # Only warn if the default config file was NOT being used. if config_file_name in self.config_file_specified: msg = self.log.warn else: msg = self.log.debug msg("Config file not found, skipping: %s", config_file_name) except: # For testing purposes. if not suppress_errors: raise self.log.warn("Error loading config file: %s" % self.config_file_name, exc_info=True) def init_profile_dir(self): """initialize the profile dir""" self._in_init_profile_dir = True if self.profile_dir is not None: # already ran return if 'ProfileDir.location' not in self.config: # location not specified, find by profile name try: p = ProfileDir.find_profile_dir_by_name( self.ipython_dir, self.profile, self.config) except ProfileDirError: # not found, maybe create it (always create default profile) if self.auto_create or self.profile == 'default': try: p = ProfileDir.create_profile_dir_by_name( self.ipython_dir, self.profile, self.config) except ProfileDirError: self.log.fatal("Could not create profile: %r" % self.profile) self.exit(1) else: self.log.info("Created profile dir: %r" % p.location) else: self.log.fatal("Profile %r not found." % self.profile) self.exit(1) else: self.log.info("Using existing profile dir: %r" % p.location) else: location = self.config.ProfileDir.location # location is fully specified try: p = ProfileDir.find_profile_dir(location, self.config) except ProfileDirError: # not found, maybe create it if self.auto_create: try: p = ProfileDir.create_profile_dir( location, self.config) except ProfileDirError: self.log.fatal( "Could not create profile directory: %r" % location) self.exit(1) else: self.log.info("Creating new profile dir: %r" % location) else: self.log.fatal("Profile directory %r not found." % location) self.exit(1) else: self.log.info("Using existing profile dir: %r" % location) self.profile_dir = p self.config_file_paths.append(p.location) self._in_init_profile_dir = False def init_config_files(self): """[optionally] copy default config files into profile dir.""" # copy config files path = self.builtin_profile_dir if self.copy_config_files: src = self.profile cfg = self.config_file_name if path and os.path.exists(os.path.join(path, cfg)): self.log.warn( "Staging %r from %s into %r [overwrite=%s]" % (cfg, src, self.profile_dir.location, self.overwrite)) self.profile_dir.copy_config_file(cfg, path=path, overwrite=self.overwrite) else: self.stage_default_config_file() else: # Still stage *bundled* config files, but not generated ones # This is necessary for `ipython profile=sympy` to load the profile # on the first go files = glob.glob(os.path.join(path, '*.py')) for fullpath in files: cfg = os.path.basename(fullpath) if self.profile_dir.copy_config_file(cfg, path=path, overwrite=False): # file was copied self.log.warn( "Staging bundled %s from %s into %r" % (cfg, self.profile, self.profile_dir.location)) def stage_default_config_file(self): """auto generate default config file, and stage it into the profile.""" s = self.generate_config_file() fname = os.path.join(self.profile_dir.location, self.config_file_name) if self.overwrite or not os.path.exists(fname): self.log.warn("Generating default config file: %r" % (fname)) with open(fname, 'w') as f: f.write(s) @catch_config_error def initialize(self, argv=None): # don't hook up crash handler before parsing command-line self.parse_command_line(argv) self.init_crash_handler() if self.subapp is not None: # stop here if subapp is taking over return cl_config = self.config self.init_profile_dir() self.init_config_files() self.load_config_file() # enforce cl-opts override configfile opts: self.update_config(cl_config)