Skip to content

Commit

Permalink
Merge branch 'master' into latency
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg1969 authored Mar 6, 2024
2 parents bc4ad90 + 5cb0e15 commit 529f97d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 72 deletions.
1 change: 0 additions & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ requirements:
- python >=3.6
- jupyter_client >=4.2
- jupyter_core
- setuptools
- traitlets
- psutil

Expand Down
28 changes: 0 additions & 28 deletions nb_conda_kernels/discovery.py

This file was deleted.

34 changes: 3 additions & 31 deletions nb_conda_kernels/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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

Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
16 changes: 10 additions & 6 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 529f97d

Please sign in to comment.