diff --git a/nb_conda_kernels/discovery.py b/nb_conda_kernels/discovery.py deleted file mode 100644 index 6363b7b..0000000 --- a/nb_conda_kernels/discovery.py +++ /dev/null @@ -1,28 +0,0 @@ -# Initial support for the kernel provider mechanism -# to be introduced in jupyter_client 6.0; see -# https://jupyter-client.readthedocs.io/en/latest/kernel_providers.html - -try: - from jupyter_client.discovery import KernelProviderBase -except ImportError: - # Silently fail for version of jupyter_client that do not - # yet have the discovery module. This allows us to do some - # simple testing of this code even with jupyter_client<6 - KernelProviderBase = object - -from jupyter_client.manager import KernelManager -from .manager import CondaKernelSpecManager - - -class CondaKernelProvider(KernelProviderBase): - id = 'conda' - - def __init__(self): - self.cksm = CondaKernelSpecManager(conda_only=True) - - def find_kernels(self): - for name, data in self.cksm.get_all_specs().items(): - yield name, data['spec'] - - def make_manager(self, name): - return KernelManager(kernel_spec_manager=self.cksm, kernel_name=name) diff --git a/nb_conda_kernels/install.py b/nb_conda_kernels/install.py index 635a8b3..d6356ae 100644 --- a/nb_conda_kernels/install.py +++ b/nb_conda_kernels/install.py @@ -19,8 +19,6 @@ CKSM = "nb_conda_kernels.CondaKernelSpecManager" JKSM = "jupyter_client.kernelspec.KernelSpecManager" KSMC = "kernel_spec_manager_class" -JCKP = "jupyter_client.kernel_providers" -NCKDCKP = "nb_conda_kernels.discovery:CondaKernelProvider" JC = "jupyter_config" JNC = "jupyter_notebook_config" ENDIS = ['disabled', 'enabled'] @@ -121,7 +119,7 @@ def install(enable=False, disable=False, status=None, prefix=None, path=None, ve if status or path_g != path: # No changes in status mode, or if we're not in the target path expected = spec - elif enable and fbase == JC and key == JA and not is_enabled_entry: + elif enable and fbase == JC and key == JA: # Add the spec if we are enabling, the entry point is not active, # and we're using the new file (jupyter_config.json) and key (JupyterApp) expected = CKSM @@ -156,14 +154,9 @@ def install(enable=False, disable=False, status=None, prefix=None, path=None, ve is_enabled_all = bool(is_enabled_all.get(NBA, is_enabled_all.get(JA))) is_enabled_local = bool(is_enabled_local.get(NBA, is_enabled_local.get(JA))) - if is_enabled_all != is_enabled_local or (is_enabled_entry and disable): + if is_enabled_all != is_enabled_local: sev = 'WARNING' if status else 'ERROR' - if is_enabled_entry and disable: - msg = ['{}: the entrypoint mechanism cannot be disabled'.format(sev), - 'with changes to jupyter_config.json. To disable it,', - 'remove the nb_conda_kernels package.'] - fpaths = [] - elif path not in all_paths: + if path not in all_paths: msg = fpaths = [] elif status: msg = ['{}: the local configuration of nb_conda_kernels'.format(sev), @@ -182,7 +175,6 @@ def install(enable=False, disable=False, status=None, prefix=None, path=None, ve if msg: (log.warning if status else log.error)('\n'.join(msg)) - is_enabled_all = is_enabled_all or is_enabled_entry log.info('Status: {}'.format(ENDIS[is_enabled_all])) return 0 if status or is_enabled_all == is_enabled_local else 1 diff --git a/tests/test_runner.py b/tests/test_runner.py index b70d4c3..4055fdf 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -9,17 +9,21 @@ import time import pytest -from nb_conda_kernels.discovery import CondaKernelProvider -from nb_conda_kernels.manager import RUNNER_COMMAND +from jupyter_client.manager import KernelManager +from nb_conda_kernels.manager import RUNNER_COMMAND, CondaKernelSpecManager START_TIMEOUT = 10 CMD_TIMEOUT = 3 NUM_RETRIES = 10 is_win = sys.platform.startswith('win') -is_py2 = sys.version_info[0] < 3 +CKSM = None -provider = CondaKernelProvider() +def _cksm(): + global CKSM + if CKSM is None: + CKSM = CondaKernelSpecManager(conda_only=True) + return CKSM old_print = print @@ -61,7 +65,7 @@ def find_test_keys(): os.environ['PATH'] = os.pathsep.join(path_list) print('AFTER: {}'.format(os.environ['PATH'])) keys = [] - for key, _ in provider.find_kernels(): + for key in _cksm().get_all_specs(): assert key.startswith('conda-') if key.endswith('-py') or key.endswith('-r'): keys.append(key) @@ -127,7 +131,7 @@ def call_kernel(kernel_manager, **kw): def test_runner(key): if sys.platform.startswith("darwin") and key.endswith('-r'): pytest.xfail("R kernels on macos are failing for now") - kernel_manager = provider.make_manager(key) + kernel_manager = KernelManager(kernel_spec_manager=_cksm(), kernel_name=key) if kernel_manager.kernel_spec.argv[:3] == RUNNER_COMMAND: env_path = kernel_manager.kernel_spec.argv[4] else: