diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index b3b7f5e..e37f605 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -21,7 +21,6 @@ requirements: - python >=3.6 - jupyter_client >=4.2 - jupyter_core - - setuptools - traitlets - psutil 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 0476968..d6356ae 100644 --- a/nb_conda_kernels/install.py +++ b/nb_conda_kernels/install.py @@ -5,7 +5,6 @@ import sys from os.path import join, abspath, exists -from pkg_resources import iter_entry_points from traitlets.config.manager import BaseJSONConfigManager from jupyter_core.paths import jupyter_config_path @@ -20,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'] @@ -80,25 +77,6 @@ def install(enable=False, disable=False, status=None, prefix=None, path=None, ve log.info("{}ing nb_conda_kernels...".format(ENDIS[enable][:-2].capitalize())) log.info("CONDA_PREFIX: {}".format(sys.prefix)) - is_enabled_entry = False - # Disable the entry-point based mechanism. Most if this code will need - # to be removed, because the kernel discovery mechanism was changed - # before jupyter_client 6 was released. For now we're dropping back to - # the jupyter_client 5 model until we leverage the new mechanism. - has_entrypoints = False # int(jc_version.split('.', 1)[0]) >= 6 - log.debug('Entry points:') - for ep in iter_entry_points(group=JCKP): - log.debug(' - {}'.format(ep)) - if str(ep).split('=', 1)[-1].strip() == NCKDCKP: - is_enabled_entry = True - if not is_enabled_entry and has_entrypoints: - log.error(('NOTE: nb_conda_kernels is missing its entry point ' - 'for jupyter_client.kernel_providers, which is needed ' - 'for correct operation this version of Jupyter.')) - if is_enabled_entry and not has_entrypoints: - log.debug(' NOTE: entry points not used in Jupyter {}'.format(jc_version)) - is_enabled_entry = False - all_paths = [abspath(p) for p in jupyter_config_path()] default_path = join(sys.prefix, 'etc', 'jupyter') search_paths = all_paths[::-1] @@ -141,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 @@ -176,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), @@ -202,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/setup.py b/setup.py index 1d538ce..7a3b491 100644 --- a/setup.py +++ b/setup.py @@ -11,10 +11,5 @@ long_description=open('README.md').read(), packages=setuptools.find_packages(), include_package_data=True, - zip_safe=False, - entry_points={ - "jupyter_client.kernel_providers": [ - # The name before the '=' should match the id attribute - 'conda = nb_conda_kernels.discovery:CondaKernelProvider', - ]} + zip_safe=False ) 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: