示例#1
0
def ipython_info():
    """Get IPython info dict"""
    from IPython.utils import sysinfo
    try:
        return sysinfo.get_sys_info()
    except AttributeError:
        # IPython < 2.0
        return eval(sysinfo.sys_info())
示例#2
0
def ipython_info():
    """Get IPython info dict"""
    from IPython.utils import sysinfo
    try:
        return sysinfo.get_sys_info()
    except AttributeError:
        # IPython < 2.0
        return eval(sysinfo.sys_info())
def report():
    """Return a string with a summary report of test-related variables."""
    inf = get_sys_info()
    out = []

    def _add(name, value):
        out.append((name, value))

    _add('IPython version', inf['ipython_version'])
    _add('IPython commit', "{} ({})".format(inf['commit_hash'],
                                            inf['commit_source']))
    _add('IPython package', compress_user(inf['ipython_path']))
    _add('Python version', inf['sys_version'].replace('\n', ''))
    _add('sys.executable', compress_user(inf['sys_executable']))
    _add('Platform', inf['platform'])

    width = max(len(n) for (n, v) in out)
    out = ["{:<{width}}: {}\n".format(n, v, width=width) for (n, v) in out]

    avail = []
    not_avail = []

    for k, is_avail in have.items():
        if is_avail:
            avail.append(k)
        else:
            not_avail.append(k)

    if avail:
        out.append('\nTools and libraries available at test time:\n')
        avail.sort()
        out.append('   ' + ' '.join(avail) + '\n')

    if not_avail:
        out.append('\nTools and libraries NOT available at test time:\n')
        not_avail.sort()
        out.append('   ' + ' '.join(not_avail) + '\n')

    return ''.join(out)
def report():
    """Return a string with a summary report of test-related variables."""
    inf = get_sys_info()
    out = []

    def _add(name, value):
        out.append((name, value))

    _add('IPython version', inf['ipython_version'])
    _add('IPython commit', "{} ({})".format(
        inf['commit_hash'], inf['commit_source']))
    _add('IPython package', compress_user(inf['ipython_path']))
    _add('Python version', inf['sys_version'].replace('\n', ''))
    _add('sys.executable', compress_user(inf['sys_executable']))
    _add('Platform', inf['platform'])

    width = max(len(n) for (n, v) in out)
    out = ["{:<{width}}: {}\n".format(n, v, width=width) for (n, v) in out]

    avail = []
    not_avail = []

    for k, is_avail in have.items():
        if is_avail:
            avail.append(k)
        else:
            not_avail.append(k)

    if avail:
        out.append('\nTools and libraries available at test time:\n')
        avail.sort()
        out.append('   ' + ' '.join(avail) + '\n')

    if not_avail:
        out.append('\nTools and libraries NOT available at test time:\n')
        not_avail.sort()
        out.append('   ' + ' '.join(not_avail) + '\n')

    return ''.join(out)
示例#5
0
def report():
    """Return a string with a summary report of test-related variables."""
    inf = get_sys_info()
    out = []

    def _add(name, value):
        out.append((name, value))

    _add("IPython version", inf["ipython_version"])
    _add("IPython commit", "{} ({})".format(inf["commit_hash"], inf["commit_source"]))
    _add("IPython package", compress_user(inf["ipython_path"]))
    _add("Python version", inf["sys_version"].replace("\n", ""))
    _add("sys.executable", compress_user(inf["sys_executable"]))
    _add("Platform", inf["platform"])

    width = max(len(n) for (n, v) in out)
    out = ["{:<{width}}: {}\n".format(n, v, width=width) for (n, v) in out]

    avail = []
    not_avail = []

    for k, is_avail in have.items():
        if is_avail:
            avail.append(k)
        else:
            not_avail.append(k)

    if avail:
        out.append("\nTools and libraries available at test time:\n")
        avail.sort()
        out.append("   " + " ".join(avail) + "\n")

    if not_avail:
        out.append("\nTools and libraries NOT available at test time:\n")
        not_avail.sort()
        out.append("   " + " ".join(not_avail) + "\n")

    return "".join(out)
示例#6
0
    def init_settings(self, ipython_app, kernel_manager, contents_manager,
                      cluster_manager, session_manager, kernel_spec_manager,
                      config_manager,
                      log, base_url, default_url, settings_overrides,
                      jinja_env_options=None):

        _template_path = settings_overrides.get(
            "template_path",
            ipython_app.template_file_path,
        )
        if isinstance(_template_path, str):
            _template_path = (_template_path,)
        template_path = [os.path.expanduser(path) for path in _template_path]

        jenv_opt = jinja_env_options if jinja_env_options else {}
        env = Environment(loader=FileSystemLoader(template_path), **jenv_opt)
        
        sys_info = get_sys_info()
        if sys_info['commit_source'] == 'repository':
            # don't cache (rely on 304) when working from master
            version_hash = ''
        else:
            # reset the cache on server restart
            version_hash = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

        settings = dict(
            # basics
            log_function=log_request,
            base_url=base_url,
            default_url=default_url,
            template_path=template_path,
            static_path=ipython_app.static_file_path,
            static_handler_class = FileFindHandler,
            static_url_prefix = url_path_join(base_url,'/static/'),
            static_handler_args = {
                # don't cache custom.js
                'no_cache_paths': [url_path_join(base_url, 'static', 'custom')],
            },
            version_hash=version_hash,
            
            # authentication
            cookie_secret=ipython_app.cookie_secret,
            login_url=url_path_join(base_url,'/login'),
            login_handler_class=ipython_app.login_handler_class,
            logout_handler_class=ipython_app.logout_handler_class,
            password=ipython_app.password,

            # managers
            kernel_manager=kernel_manager,
            contents_manager=contents_manager,
            cluster_manager=cluster_manager,
            session_manager=session_manager,
            kernel_spec_manager=kernel_spec_manager,
            config_manager=config_manager,

            # IPython stuff
            nbextensions_path=ipython_app.nbextensions_path,
            websocket_url=ipython_app.websocket_url,
            mathjax_url=ipython_app.mathjax_url,
            config=ipython_app.config,
            jinja2_env=env,
            terminals_available=False,  # Set later if terminals are available
        )

        # allow custom overrides for the tornado web app.
        settings.update(settings_overrides)
        return settings
示例#7
0
文件: handlers.py 项目: Kiiwi/Syssel
import IPython
from IPython.utils.sysinfo import get_sys_info

from IPython.config import Application
from IPython.utils.path import filefind
from IPython.utils.py3compat import string_types
from IPython.html.utils import is_hidden, url_path_join, url_escape

from IPython.html.services.security import csp_report_uri

#-----------------------------------------------------------------------------
# Top-level handlers
#-----------------------------------------------------------------------------
non_alphanum = re.compile(r'[^A-Za-z0-9]')

sys_info = json.dumps(get_sys_info())

class AuthenticatedHandler(web.RequestHandler):
    """A RequestHandler with an authenticated user."""
    
    @property
    def content_security_policy(self):
        """The default Content-Security-Policy header
        
        Can be overridden by defining Content-Security-Policy in settings['headers']
        """
        return '; '.join([
            "frame-ancestors 'self'",
            # Make sure the report-uri is relative to the base_url
            "report-uri " + url_path_join(self.base_url, csp_report_uri),
        ])
示例#8
0
import IPython
from IPython.utils.sysinfo import get_sys_info

from IPython.config import Application
from IPython.utils.path import filefind
from IPython.utils.py3compat import string_types
from IPython.html.utils import is_hidden, url_path_join, url_escape

from IPython.html.services.security import csp_report_uri

#-----------------------------------------------------------------------------
# Top-level handlers
#-----------------------------------------------------------------------------
non_alphanum = re.compile(r'[^A-Za-z0-9]')

sys_info = json.dumps(get_sys_info())

class AuthenticatedHandler(web.RequestHandler):
    """A RequestHandler with an authenticated user."""

    def set_default_headers(self):
        headers = self.settings.get('headers', {})

        if "Content-Security-Policy" not in headers:
            headers["Content-Security-Policy"] = (
                    "frame-ancestors 'self'; "
                    # Make sure the report-uri is relative to the base_url
                    "report-uri " + url_path_join(self.base_url, csp_report_uri) + ";"
            )

        # Allow for overriding headers
def test_json_getsysinfo():
    """
    test that it is easily jsonable and don't return bytes somewhere.
    """
    json.dumps(sysinfo.get_sys_info())
示例#10
0
# change the default.
# c.TerminalInteractiveShell.screen_length = 0

# Set the editor used by IPython (default to $EDITOR/vi/notepad).
# c.TerminalInteractiveShell.editor = 'mate -w'

# Deprecated, use PromptManager.justify
# c.TerminalInteractiveShell.prompts_pad_left = True

# The part of the banner to be printed before the profile
import sys
import IPython
from IPython.utils import sysinfo

try:
    info = sysinfo.get_sys_info()
except AttributeError:
    # IPython < 2.0
    info = {'commit_hash': 'old'}

c.InteractiveShell.banner1 = '\n'.join([
    "Python %s (%s)" % (sys.version.split()[0], sys.executable),
    "IPython %s@%s" % (IPython.__version__, info['commit_hash']),
    ""
])
c.ZMQTerminalInteractiveShell.banner1 = '\n'.join([
    "IPython console %s@%s" % (IPython.__version__, info['commit_hash']),
    ""
])
# c.TerminalInteractiveShell.banner1 = 'Python 2.7.2 (default, Jun 16 2012, 12:38:40) \nType "copyright", "credits" or "license" for more information.\n\nIPython 1.0.dev -- An enhanced Interactive Python.\n?         -> Introduction and overview of IPython\'s features.\n%quickref -> Quick reference.\nhelp      -> Python\'s own help system.\nobject?   -> Details about \'object\', use \'object??\' for extra details.\n'
示例#11
0
def test_json_getsysinfo():
    """
    test that it is easily jsonable and don't return bytes somewhere. 
    """
    json.dumps(sysinfo.get_sys_info())