Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: consistently use relative imports. #912

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jupyter_client/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
from typing import Any, Dict, List, Tuple

from jupyter_client import protocol_version_info
from ._version import protocol_version_info


def code_to_line(code: str, cursor_pos: int) -> Tuple[str, int]:
Expand Down
4 changes: 2 additions & 2 deletions jupyter_client/asynchronous/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import zmq.asyncio
from traitlets import Instance, Type

from jupyter_client.channels import AsyncZMQSocketChannel, HBChannel
from jupyter_client.client import KernelClient, reqrep
from ..channels import AsyncZMQSocketChannel, HBChannel
from ..client import KernelClient, reqrep


def wrapped(meth, channel):
Expand Down
5 changes: 2 additions & 3 deletions jupyter_client/blocking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
# Distributed under the terms of the Modified BSD License.
from traitlets import Type

from jupyter_client.channels import HBChannel, ZMQSocketChannel
from jupyter_client.client import KernelClient, reqrep

from ..channels import HBChannel, ZMQSocketChannel
from ..client import KernelClient, reqrep
from ..utils import run_sync


Expand Down
5 changes: 2 additions & 3 deletions jupyter_client/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
from threading import Event, Thread

import zmq.asyncio
from jupyter_core.utils import ensure_async

from jupyter_client import protocol_version_info
from jupyter_client.utils import ensure_async

from ._version import protocol_version_info
from .channelsabc import HBChannelABC
from .session import Session

Expand Down
7 changes: 3 additions & 4 deletions jupyter_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
from queue import Empty

import zmq.asyncio
from jupyter_core.utils import ensure_async
from traitlets import Any, Bool, Instance, Type

from jupyter_client.channels import major_protocol_version
from jupyter_client.utils import ensure_async

from .channels import major_protocol_version
from .channelsabc import ChannelABC, HBChannelABC
from .clientabc import KernelClientABC
from .connect import ConnectionFileMixin
Expand Down Expand Up @@ -496,7 +495,7 @@ async def _async_execute_interactive(
if output_hook is None:
# detect IPython kernel
if "IPython" in sys.modules:
from IPython import get_ipython # type: ignore
from IPython import get_ipython

ip = get_ipython()
in_kernel = getattr(ip, "kernel", False)
Expand Down
2 changes: 1 addition & 1 deletion jupyter_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def ports(self) -> List[int]:
session = Instance("jupyter_client.session.Session")

def _session_default(self):
from jupyter_client.session import Session
from .session import Session

return Session(parent=self)

Expand Down
3 changes: 1 addition & 2 deletions jupyter_client/ioloop/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from traitlets import Instance, Type
from zmq.eventloop.zmqstream import ZMQStream

from jupyter_client.manager import AsyncKernelManager, KernelManager

from ..manager import AsyncKernelManager, KernelManager
from .restarter import AsyncIOLoopKernelRestarter, IOLoopKernelRestarter


Expand Down
2 changes: 1 addition & 1 deletion jupyter_client/ioloop/restarter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from traitlets import Instance

from jupyter_client.restarter import KernelRestarter
from ..restarter import KernelRestarter


class IOLoopKernelRestarter(KernelRestarter):
Expand Down
13 changes: 5 additions & 8 deletions jupyter_client/kernelspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,12 @@ def _kernel_dirs_default(self):
# 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 # type: ignore
except ImportError:
try:
from IPython.utils.path import get_ipython_dir # type: ignore
except ImportError:
# no IPython, no ipython dir
get_ipython_dir = None
if get_ipython_dir is not None:
# this should always be valid on IPython 3+
from IPython.paths import get_ipython_dir

dirs.append(os.path.join(get_ipython_dir(), "kernels"))
except ModuleNotFoundError:
pass
return dirs

def find_kernel_specs(self):
Expand Down
10 changes: 5 additions & 5 deletions jupyter_client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from enum import Enum

import zmq
from jupyter_core.utils import run_sync
from traitlets import (
Any,
Bool,
Expand All @@ -29,15 +30,14 @@
)
from traitlets.utils.importstring import import_item

from jupyter_client import KernelClient, kernelspec
from jupyter_client.asynchronous import AsyncKernelClient
from jupyter_client.blocking import BlockingKernelClient

from . import kernelspec
from .asynchronous import AsyncKernelClient
from .blocking import BlockingKernelClient
from .client import KernelClient
from .connect import ConnectionFileMixin
from .managerabc import KernelManagerABC
from .provisioning import KernelProvisionerBase
from .provisioning import KernelProvisionerFactory as KPF # noqa
from .utils import run_sync


class _ShutdownStatus(Enum):
Expand Down
6 changes: 3 additions & 3 deletions jupyter_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
from zmq.eventloop.ioloop import IOLoop
from zmq.eventloop.zmqstream import ZMQStream

from jupyter_client import protocol_version
from jupyter_client.adapter import adapt
from jupyter_client.jsonutil import extract_dates, json_clean, json_default, squash_dates
from ._version import protocol_version
from .adapter import adapt
from .jsonutil import extract_dates, json_clean, json_default, squash_dates

PICKLE_PROTOCOL = pickle.DEFAULT_PROTOCOL

Expand Down
2 changes: 1 addition & 1 deletion jupyter_client/ssh/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from jupyter_client.ssh.tunnel import * # noqa
from .tunnel import * # noqa
5 changes: 2 additions & 3 deletions jupyter_client/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
from traitlets import Instance, Type
from zmq.eventloop import zmqstream

from jupyter_client import KernelClient
from jupyter_client.channels import HBChannel

from .channels import HBChannel
from .client import KernelClient
from .session import Session

# Local imports
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from unittest import TestCase, mock

import pytest
from IPython.utils.capture import capture_output # type:ignore
from IPython.utils.capture import capture_output
from traitlets import DottedObjectName, Type

from jupyter_client.client import validate_string_dict
Expand Down