def migrate(): """Migrate IPython configuration to Jupyter""" env = { 'jupyter_data': jupyter_data_dir(), 'jupyter_config': jupyter_config_dir(), 'ipython_dir': get_ipython_dir(), 'profile': os.path.join(get_ipython_dir(), 'profile_default'), } migrated = False for src_t, dst_t in migrations.items(): src = src_t.format(**env) dst = dst_t.format(**env) if os.path.exists(src): if migrate_one(src, dst): migrated = True for name in config_migrations: if migrate_config(name, env): migrated = True custom_src = custom_src_t.format(**env) custom_dst = custom_dst_t.format(**env) if os.path.exists(custom_src): if migrate_static_custom(custom_src, custom_dst): migrated = True # write a marker to avoid re-running migration checks ensure_dir_exists(env['jupyter_config']) with open(os.path.join(env['jupyter_config'], 'migrated'), 'w') as f: f.write(datetime.utcnow().isoformat()) return migrated
def _create_base_ipython_dirs(): """Create default user directories to prevent potential race conditions downstream. """ utils.safe_makedir(get_ipython_dir()) ProfileDir.create_profile_dir_by_name(get_ipython_dir()) utils.safe_makedir(os.path.join(get_ipython_dir(), "db")) utils.safe_makedir(os.path.join(locate_profile(), "db"))
def _all_profile_dirs(): """List all IPython profile directories""" profile_dirs = [] if not os.path.isdir(get_ipython_dir()): return profile_dirs with os.scandir(get_ipython_dir()) as paths: for path in paths: if path.is_dir() and path.name.startswith('profile_'): profile_dirs.append(path.path) return profile_dirs
def get_config(profile="default"): profile_dir = profiledir.ProfileDir() try: profile = profile_dir.find_profile_dir_by_name(paths.get_ipython_dir(), profile) except profiledir.ProfileDirError: os.makedirs(paths.get_ipython_dir(), exist_ok=True) profile = profile_dir.create_profile_dir_by_name( paths.get_ipython_dir(), profile) return Path(profile.location, "ipython_config.json")
def find_connection_file(filename='kernel-*.json', profile=None): """find a connection file, and return its absolute path. The current working directory and the profile's security directory will be searched for the file if it is not given by absolute path. If profile is unspecified, then the current running application's profile will be used, or 'default', if not run from IPython. If the argument does not match an existing file, it will be interpreted as a fileglob, and the matching file in the profile's security dir with the latest access time will be used. Parameters ---------- filename : str The connection file or fileglob to search for. profile : str [optional] The name of the profile to use when searching for the connection file, if different from the current IPython session or 'default'. Returns ------- str : The absolute path of the connection file. """ from IPython.core.application import BaseIPythonApplication as IPApp try: # quick check for absolute path, before going through logic return filefind(filename) except IOError: pass if profile is None: # profile unspecified, check if running from an IPython app if IPApp.initialized(): app = IPApp.instance() profile_dir = app.profile_dir else: # not running in IPython, use default profile profile_dir = ProfileDir.find_profile_dir_by_name( get_ipython_dir(), 'default') else: # find profiledir by profile name: profile_dir = ProfileDir.find_profile_dir_by_name( get_ipython_dir(), profile) security_dir = profile_dir.security_dir return jupyter_client.find_connection_file(filename, path=['.', security_dir])
def nbextensions_path(self): """The path to look for Javascript notebook extensions""" return self.extra_nbextensions_path + [ os.path.join(self.data_dir, 'nbextensions'), # FIXME: remove IPython nbextensions path once migration is setup os.path.join(get_ipython_dir(), 'nbextensions'), ] + SYSTEM_NBEXTENSIONS_DIRS
def update_profiles(self): """List all profiles in the ipython_dir and cwd. """ try: from IPython.paths import get_ipython_dir from IPython.core.profileapp import list_profiles_in except ImportError as e: self.log.info("IPython not available: %s", e) return stale = set(self.profiles) for path in [get_ipython_dir(), py3compat.getcwd()]: for profile in list_profiles_in(path): if profile in stale: stale.remove(profile) pd = self.get_profile_dir(profile, path) if profile not in self.profiles: self.log.debug("Adding cluster profile '%s'", profile) self.profiles[profile] = { 'profile': profile, 'profile_dir': pd, 'status': 'stopped' } for profile in stale: # remove profiles that no longer exist self.log.debug("Profile '%s' no longer exists", profile) self.profiles.pop(profile)
def _locate_profiles(profiles=None): """Locate one or more IPython profiles by name""" ipython_dir = get_ipython_dir() return [ ProfileDir.find_profile_dir_by_name(ipython_dir, name=profile).location for profile in profiles ]
def setup(): # show tracebacks for RemoteErrors class RemoteErrorWithTB(error.RemoteError): def __str__(self): s = super(RemoteErrorWithTB, self).__str__() return '\n'.join([s, self.traceback or '']) error.RemoteError = RemoteErrorWithTB cluster_dir = os.path.join(get_ipython_dir(), 'profile_iptest') engine_json = os.path.join(cluster_dir, 'security', 'ipcontroller-engine.json') client_json = os.path.join(cluster_dir, 'security', 'ipcontroller-client.json') for json in (engine_json, client_json): if os.path.exists(json): os.remove(json) cp = TestProcessLauncher() cp.cmd_and_args = ipcontroller_cmd_argv + \ ['--profile=iptest', '--log-level=20', '--ping=250', '--dictdb'] cp.start() launchers.append(cp) tic = time.time() while not os.path.exists(engine_json) or not os.path.exists(client_json): if cp.poll() is not None: raise RuntimeError("The test controller exited with status %s" % cp.poll()) elif time.time() - tic > 15: raise RuntimeError( "Timeout waiting for the test controller to start.") time.sleep(0.1) add_engines(1)
def setup(): error.RemoteError = RemoteErrorWithTB cluster_dir = os.path.join(get_ipython_dir(), 'profile_iptest') engine_json = os.path.join(cluster_dir, 'security', 'ipcontroller-engine.json') client_json = os.path.join(cluster_dir, 'security', 'ipcontroller-client.json') for json in (engine_json, client_json): if os.path.exists(json): os.remove(json) cp = TestProcessLauncher() cp.cmd_and_args = ipcontroller_cmd_argv + [ '--profile=iptest', '--log-level=10', '--ping=250', '--dictdb', ] if os.environ.get("IPP_CONTROLLER_IP"): cp.cmd_and_args.append(f"--ip={os.environ['IPP_CONTROLLER_IP']}") cp.start() launchers.append(cp) tic = time.time() while not os.path.exists(engine_json) or not os.path.exists(client_json): if cp.poll() is not None: raise RuntimeError("The test controller exited with status %s" % cp.poll()) elif time.time() - tic > 15: raise RuntimeError( "Timeout waiting for the test controller to start.") time.sleep(0.1) add_engines(1)
def test_get_ipython_dir_7(): """test_get_ipython_dir_7, test home directory expansion on IPYTHONDIR""" home_dir = os.path.normpath(os.path.expanduser('~')) with modified_env({'IPYTHONDIR': os.path.join('~', 'somewhere')}), \ patch.object(paths, '_writable_dir', return_value=True): ipdir = paths.get_ipython_dir() nt.assert_equal(ipdir, os.path.join(home_dir, 'somewhere'))
def test_get_ipython_dir_7(): """test_get_ipython_dir_7, test home directory expansion on IPYTHONDIR""" paths._writable_dir = lambda path: True home_dir = os.path.normpath(os.path.expanduser('~')) env['IPYTHONDIR'] = os.path.join('~', 'somewhere') ipdir = paths.get_ipython_dir() nt.assert_equal(ipdir, os.path.join(home_dir, 'somewhere'))
class ProfileList(Application): name = u'ipython-profile' description = list_help examples = _list_examples aliases = Dict({ 'ipython-dir': 'ProfileList.ipython_dir', 'log-level': 'Application.log_level', }) flags = Dict( dict(debug=({ 'Application': { 'log_level': 0 } }, "Set Application.log_level to 0, maximizing log output."))) ipython_dir = Unicode(get_ipython_dir(), 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. """).tag(config=True) def _print_profiles(self, profiles): """print list of profiles, indented.""" for profile in profiles: print(' %s' % profile) def list_profile_dirs(self): profiles = list_bundled_profiles() if profiles: print() print("Available profiles in IPython:") self._print_profiles(profiles) print() print(" The first request for a bundled profile will copy it") print(" into your IPython directory (%s)," % self.ipython_dir) print(" where you can customize it.") profiles = list_profiles_in(self.ipython_dir) if profiles: print() print("Available profiles in %s:" % self.ipython_dir) self._print_profiles(profiles) profiles = list_profiles_in(os.getcwd()) if profiles: print() print("Available profiles in current directory (%s):" % os.getcwd()) self._print_profiles(profiles) print() print("To use any of the above profiles, start IPython with:") print(" ipython --profile=<name>") print() def start(self): self.list_profile_dirs()
def update_profiles(self): """List all profiles in the ipython_dir and cwd. """ try: from IPython.paths import get_ipython_dir from IPython.core.profileapp import list_profiles_in except ImportError as e: self.log.info("IPython not available: %s", e) return stale = set(self.profiles) for path in [get_ipython_dir(), py3compat.getcwd()]: if not os.path.isdir(path): continue for profile in list_profiles_in(path): if profile in stale: stale.remove(profile) pd = self.get_profile_dir(profile, path) if profile not in self.profiles: self.log.debug("Adding cluster profile '%s'", profile) self.profiles[profile] = { 'profile': profile, 'profile_dir': pd, 'status': 'stopped' } for profile in stale: # remove profiles that no longer exist self.log.debug("Profile '%s' no longer exists", profile) self.profiles.pop(profile)
def test_get_ipython_dir_1(): """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions.""" env_ipdir = os.path.join("someplace", ".ipython") paths._writable_dir = lambda path: True env['IPYTHONDIR'] = env_ipdir ipdir = paths.get_ipython_dir() nt.assert_equal(ipdir, env_ipdir)
def setUpModule(): cluster_dir = os.path.join(get_ipython_dir(), 'profile_default') engine_json = os.path.join(cluster_dir, 'security', 'ipcontroller-engine.json') client_json = os.path.join(cluster_dir, 'security', 'ipcontroller-client.json') for json in (engine_json, client_json): if os.path.exists(json): os.remove(json) cp = TestProcessLauncher() cp.cmd_and_args = ipcontroller_cmd_argv + \ ['--profile=default', '--log-level=20'] cp.start() launchers.append(cp) tic = time.time() while not os.path.exists(engine_json) or not os.path.exists(client_json): if cp.poll() is not None: raise RuntimeError("The test controller exited with status %s" % cp.poll()) elif time.time() - tic > 15: raise RuntimeError( "Timeout waiting for the test controller to start.") time.sleep(0.1) add_engines(2, profile='default', total=True)
def setup(): # show tracebacks for RemoteErrors class RemoteErrorWithTB(error.RemoteError): def __str__(self): s = super(RemoteErrorWithTB, self).__str__() return '\n'.join([s, self.traceback or '']) error.RemoteError = RemoteErrorWithTB cluster_dir = os.path.join(get_ipython_dir(), 'profile_iptest') engine_json = os.path.join(cluster_dir, 'security', 'ipcontroller-engine.json') client_json = os.path.join(cluster_dir, 'security', 'ipcontroller-client.json') for json in (engine_json, client_json): if os.path.exists(json): os.remove(json) cp = TestProcessLauncher() cp.cmd_and_args = ipcontroller_cmd_argv + \ ['--profile=iptest', '--log-level=20', '--ping=250', '--dictdb'] cp.start() launchers.append(cp) tic = time.time() while not os.path.exists(engine_json) or not os.path.exists(client_json): if cp.poll() is not None: raise RuntimeError("The test controller exited with status %s" % cp.poll()) elif time.time()-tic > 15: raise RuntimeError("Timeout waiting for the test controller to start.") time.sleep(0.1) add_engines(1)
def get_ipython_dir(): warn( "get_ipython_dir has moved to the IPython.paths module since IPython 4.0.", DeprecationWarning, stacklevel=2) from IPython.paths import get_ipython_dir return get_ipython_dir()
def find_connection_file(filename='kernel-*.json', profile=None): """DEPRECATED: find a connection file, and return its absolute path. THIS FUNCTION IS DEPRECATED. Use juptyer_client.find_connection_file instead. Parameters ---------- filename : str The connection file or fileglob to search for. profile : str [optional] The name of the profile to use when searching for the connection file, if different from the current IPython session or 'default'. Returns ------- str : The absolute path of the connection file. """ import warnings warnings.warn( """ipykernel.find_connection_file is deprecated, use jupyter_client.find_connection_file""", DeprecationWarning, stacklevel=2) from IPython.core.application import BaseIPythonApplication as IPApp try: # quick check for absolute path, before going through logic return filefind(filename) except IOError: pass if profile is None: # profile unspecified, check if running from an IPython app if IPApp.initialized(): app = IPApp.instance() profile_dir = app.profile_dir else: # not running in IPython, use default profile profile_dir = ProfileDir.find_profile_dir_by_name( get_ipython_dir(), 'default') else: # find profiledir by profile name: profile_dir = ProfileDir.find_profile_dir_by_name( get_ipython_dir(), profile) security_dir = profile_dir.security_dir return jupyter_client.find_connection_file(filename, path=['.', security_dir])
def find_connection_file(filename='kernel-*.json', profile=None): """find a connection file, and return its absolute path. The current working directory and the profile's security directory will be searched for the file if it is not given by absolute path. If profile is unspecified, then the current running application's profile will be used, or 'default', if not run from IPython. If the argument does not match an existing file, it will be interpreted as a fileglob, and the matching file in the profile's security dir with the latest access time will be used. Parameters ---------- filename : str The connection file or fileglob to search for. profile : str [optional] The name of the profile to use when searching for the connection file, if different from the current IPython session or 'default'. Returns ------- str : The absolute path of the connection file. """ from IPython.core.application import BaseIPythonApplication as IPApp try: # quick check for absolute path, before going through logic return filefind(filename) except IOError: pass if profile is None: # profile unspecified, check if running from an IPython app if IPApp.initialized(): app = IPApp.instance() profile_dir = app.profile_dir else: # not running in IPython, use default profile profile_dir = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), 'default') else: # find profiledir by profile name: profile_dir = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), profile) security_dir = profile_dir.security_dir return jupyter_client.find_connection_file(filename, path=['.', security_dir])
def _ipython_dir_default(self): d = get_ipython_dir() self._ipython_dir_changed({ 'name': 'ipython_dir', 'old': d, 'new': d, }) return d
def test_get_ipython_dir_1(): """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions.""" env_ipdir = os.path.join("someplace", ".ipython") with patch.object(paths, '_writable_dir', return_value=True), \ modified_env({'IPYTHONDIR': env_ipdir}): ipdir = paths.get_ipython_dir() nt.assert_equal(ipdir, env_ipdir)
def get_ipython_dir(): warn( "get_ipython_dir has moved to the IPython.paths module since IPython 4.0.", stacklevel=2, ) from IPython.paths import get_ipython_dir return get_ipython_dir()
def _static_custom_path_default(self): return [ os.path.join(d, 'custom') for d in ( self.config_dir, # FIXME: serve IPython profile while we don't have `jupyter migrate` os.path.join(get_ipython_dir(), 'profile_default', 'static'), DEFAULT_STATIC_FILES_PATH) ]
def load_subconfig(self, fname, path=None, profile=None): if profile is not None: try: profile_dir = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), profile) except ProfileDirError: return path = profile_dir.location return super(ProfileAwareConfigLoader, self).load_subconfig(fname, path=path)
def abbreviate_profile_dir(profile_dir): """Abbreviate IPython profile directory if in $IPYTHONDIR""" profile_prefix = os.path.join(get_ipython_dir(), "profile_") if profile_dir.startswith(profile_prefix): # use just the profile name if it's in $IPYTHONDIR return profile_dir[len(profile_prefix) :] else: return profile_dir
def test_get_ipython_dir_7(): """test_get_ipython_dir_7, test home directory expansion on IPYTHONDIR""" home_dir = os.path.normpath(os.path.expanduser("~")) with modified_env({"IPYTHONDIR": os.path.join("~", "somewhere") }), patch.object(paths, "_writable_dir", return_value=True): ipdir = paths.get_ipython_dir() nt.assert_equal(ipdir, os.path.join(home_dir, "somewhere"))
def load_subconfig(self, fname, path=None, profile=None): if profile is not None: try: profile_dir = ProfileDir.find_profile_dir_by_name( get_ipython_dir(), profile ) except ProfileDirError: return path = profile_dir.location return super(ProfileAwareConfigLoader, self).load_subconfig(fname, path=path)
def list_profiles(self): try: from IPython.paths import get_ipython_dir from IPython.core.profileapp import list_profiles_in except ImportError as e: self.log.info("IPython not available: %s", e) return [ 'default', ] return list_profiles_in(get_ipython_dir())
def get_local_magics_dir(): """ Ensures that there is a ~/.ipython/metakernel/magics directory, and returns the path to it. """ base = get_ipython_dir() dname = os.path.join(base, 'metakernel', 'magics') if not os.path.exists(dname): os.makedirs(dname) return dname
def _kernel_dirs_default(self): dirs = SYSTEM_KERNEL_DIRS[:] if self.env_kernel_dir not in dirs: dirs.append(self.env_kernel_dir) # FIXME: pending migration, include kernelspecs in .ipython: from IPython.paths import get_ipython_dir dirs.append(os.path.join(get_ipython_dir(), 'kernels')) dirs.append(self.user_kernel_dir) return dirs
def test_get_ipython_dir_8(): """test_get_ipython_dir_8, test / home directory""" with patch.object(paths, '_writable_dir', lambda path: bool(path)), \ patch.object(paths, 'get_xdg_dir', return_value=None), \ modified_env({ 'IPYTHON_DIR': None, 'IPYTHONDIR': None, 'HOME': '/', }): nt.assert_equal(paths.get_ipython_dir(), '/.ipython')
def find_connection_file(filename='kernel-*.json', profile=None): """DEPRECATED: find a connection file, and return its absolute path. THIS FUNCION IS DEPRECATED. Use juptyer_client.find_connection_file instead. Parameters ---------- filename : str The connection file or fileglob to search for. profile : str [optional] The name of the profile to use when searching for the connection file, if different from the current IPython session or 'default'. Returns ------- str : The absolute path of the connection file. """ import warnings warnings.warn("""ipykernel.find_connection_file is deprecated, use jupyter_client.find_connection_file""", DeprecationWarning, stacklevel=2) from IPython.core.application import BaseIPythonApplication as IPApp try: # quick check for absolute path, before going through logic return filefind(filename) except IOError: pass if profile is None: # profile unspecified, check if running from an IPython app if IPApp.initialized(): app = IPApp.instance() profile_dir = app.profile_dir else: # not running in IPython, use default profile profile_dir = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), 'default') else: # find profiledir by profile name: profile_dir = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), profile) security_dir = profile_dir.security_dir return jupyter_client.find_connection_file(filename, path=['.', security_dir])
def get_ipython_profiles(path=None): """list profiles in a given root directory""" if path is None: path = get_ipython_dir() files = os.listdir(path) profiles = [] for f in files: full_path = os.path.join(path, f) if os.path.isdir(full_path) and f.startswith('profile_'): profiles.append(f.split('_', 1)[-1]) return profiles
def is_installed(ipydir=None, profile='tango'): ipython_dir = ipydir or get_ipython_dir() try: p_dir = ProfileDir.find_profile_dir_by_name(ipython_dir, profile) except ProfileDirError: return False abs_config_file_name = os.path.join(p_dir.location, _CONFIG_FILE_NAME) if not os.path.isfile(abs_config_file_name): return False with open(abs_config_file_name) as f: return __PROTECTED_BLOCK in f.read()
def nbextensions_path(self): """The path to look for Javascript notebook extensions""" path = self.extra_nbextensions_path + jupyter_path('nbextensions') # FIXME: remove IPython nbextensions path after a migration period try: from IPython.paths import get_ipython_dir except ImportError: pass else: path.append(os.path.join(get_ipython_dir(), 'nbextensions')) return path
def test_get_ipython_dir_2(): """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.""" with patch_get_home_dir('someplace'): paths.get_xdg_dir = lambda : None paths._writable_dir = lambda path: True os.name = "posix" env.pop('IPYTHON_DIR', None) env.pop('IPYTHONDIR', None) env.pop('XDG_CONFIG_HOME', None) ipdir = paths.get_ipython_dir() nt.assert_equal(ipdir, os.path.join("someplace", ".ipython"))
def test_get_ipython_dir_8(): """test_get_ipython_dir_8, test / home directory""" with patch.object(paths, "_writable_dir", lambda path: bool(path)), patch.object( paths, "get_xdg_dir", return_value=None), modified_env({ "IPYTHON_DIR": None, "IPYTHONDIR": None, "HOME": "/" }): nt.assert_equal(paths.get_ipython_dir(), "/.ipython")
def config_ipw(ipw): """Apply and then modify default settings of IPython Qt widget""" ipython_dir = get_ipython_dir() profile_dir = os.path.join(ipython_dir, 'profile_default') cl = PyFileConfigLoader('ipython_qtconsole_config.py', profile_dir) config = cl.load_config() ipw.config = config ipw.set_default_style(colors='Linux') ipw.font = QtGui.QFont('Lucida Console', 11) # 3rd arg can be e.g. QFont.Bold ipw.font.setFixedPitch(True)
def config_ipw(ipw): """Apply and then modify default settings of IPython Qt widget""" ipython_dir = get_ipython_dir() profile_dir = os.path.join(ipython_dir, 'profile_default') cl = PyFileConfigLoader('ipython_config.py', profile_dir) config = cl.load_config() ipw.config = config ipw.set_default_style(colors='Linux') ipw.font = QtGui.QFont('Lucida Console', 11) # 3rd arg can be e.g. QFont.Bold ipw.font.setFixedPitch(True) ipw.buffer_size = 100000 # number of scrollback lines to keep before truncation
def test_get_ipython_dir_8(): """test_get_ipython_dir_8, test / home directory""" old = paths._writable_dir, paths.get_xdg_dir try: paths._writable_dir = lambda path: bool(path) paths.get_xdg_dir = lambda: None env.pop('IPYTHON_DIR', None) env.pop('IPYTHONDIR', None) env['HOME'] = '/' nt.assert_equal(paths.get_ipython_dir(), '/.ipython') finally: paths._writable_dir, paths.get_xdg_dir = old
def test_get_ipython_dir_2(): """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.""" with patch_get_home_dir('someplace'), \ patch.object(paths, 'get_xdg_dir', return_value=None), \ patch.object(paths, '_writable_dir', return_value=True), \ patch('os.name', "posix"), \ modified_env({'IPYTHON_DIR': None, 'IPYTHONDIR': None, 'XDG_CONFIG_HOME': None }): ipdir = paths.get_ipython_dir() nt.assert_equal(ipdir, os.path.join("someplace", ".ipython"))
def load_default_config(ipython_dir=None): """Load the default config file from the default ipython_dir. This is useful for embedded shells. """ if ipython_dir is None: ipython_dir = get_ipython_dir() profile_dir = os.path.join(ipython_dir, 'profile_default') app = TerminalIPythonApp() app.config_file_paths.append(profile_dir) app.load_config_file() return app.config
def test_get_ipython_dir_5(): """test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist.""" with patch_get_home_dir(HOME_TEST_DIR): os.name = "posix" env.pop('IPYTHON_DIR', None) env.pop('IPYTHONDIR', None) env['XDG_CONFIG_HOME'] = XDG_TEST_DIR try: os.rmdir(os.path.join(XDG_TEST_DIR, 'ipython')) except OSError as e: if e.errno != errno.ENOENT: raise ipdir = paths.get_ipython_dir() nt.assert_equal(ipdir, IP_TEST_DIR)
def __init__(self): """ Utility to manage Sage kernels EXAMPLES:: sage: from sage.repl.ipython_kernel.install import SageKernelSpec sage: spec = SageKernelSpec() sage: spec._display_name # random output 'Sage 6.6.beta2' """ self._display_name = 'Sage {0}'.format(SAGE_VERSION) self._ipython_dir = get_ipython_dir() self._mkdirs()
def load_default_config(ipython_dir=None): """Load the default config file from the default ipython_dir. This is useful for embedded shells. """ if ipython_dir is None: ipython_dir = get_ipython_dir() profile_dir = os.path.join(ipython_dir, 'profile_default') config = Config() for cf in Application._load_config_files("ipython_config", path=profile_dir): config.update(cf) return config
def _kernel_dirs_default(self): dirs = jupyter_path("kernels") # At some point, we should stop adding .ipython/kernels to the path, # but the cost to keeping it is very small. try: from IPython.paths import get_ipython_dir except ImportError: try: from IPython.utils.path import get_ipython_dir except ImportError: # no IPython, no ipython dir get_ipython_dir = None if get_ipython_dir is not None: dirs.append(os.path.join(get_ipython_dir(), "kernels")) return dirs