Skip to content
1 change: 1 addition & 0 deletions distributed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import config # isort:skip; load distributed configuration first
from . import widgets # isort:skip; load distributed widgets second
import dask
from dask.config import config
from dask.utils import import_required
Expand Down
4 changes: 2 additions & 2 deletions distributed/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
funcname,
parse_timedelta,
stringify,
typename,
)
from dask.widgets import get_template

try:
from dask.delayed import single_key
Expand Down Expand Up @@ -85,7 +87,6 @@
no_default,
sync,
thread_state,
typename,
)
from .utils_comm import (
WrappedKey,
Expand All @@ -95,7 +96,6 @@
scatter_to_workers,
unpack_remotedata,
)
from .widgets import get_template
from .worker import get_client, get_worker, secede

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion distributed/deploy/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

import dask.config
from dask.utils import _deprecated, format_bytes, parse_timedelta
from dask.widgets import get_template

from ..core import Status
from ..objects import SchedulerInfo
from ..utils import Log, Logs, format_dashboard_link, log_errors, sync, thread_state
from ..widgets import get_template
from .adaptive import Adaptive

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion distributed/deploy/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import toolz

from dask.system import CPU_COUNT
from dask.widgets import get_template

from ..nanny import Nanny
from ..scheduler import Scheduler
from ..security import Security
from ..widgets import get_template
from ..worker import Worker, parse_memory_limit
from .spec import SpecCluster
from .utils import nprocesses_nthreads
Expand Down
3 changes: 2 additions & 1 deletion distributed/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
These are mostly regular objects with more useful _repr_ and _repr_html_ methods."""
from urllib.parse import urlparse

from dask.widgets import get_environment, get_template

from distributed.utils import format_dashboard_link
from distributed.widgets import get_environment, get_template


class HasWhat(dict):
Expand Down
3 changes: 2 additions & 1 deletion distributed/protocol/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import dask
from dask.base import normalize_token
from dask.utils import typename

from ..utils import ensure_bytes, has_keyword, typename
from ..utils import ensure_bytes, has_keyword
from . import pickle
from .compression import decompress, maybe_compress
from .utils import frame_split_size, msgpack_opts, pack_frames_prelude, unpack_frames
Expand Down
2 changes: 1 addition & 1 deletion distributed/protocol/tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def test_serialize_lists(serializers):
)
def test_deser_memoryview(data_in):
header, frames = serialize(data_in)
assert header["type"] == "builtins.memoryview"
assert header["type"] == "memoryview"
assert frames[0] is data_in
data_out = deserialize(header, frames)
assert data_in == data_out
Expand Down
2 changes: 1 addition & 1 deletion distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import dask
from dask.highlevelgraph import HighLevelGraph
from dask.utils import format_bytes, format_time, parse_bytes, parse_timedelta
from dask.widgets import get_template

from . import preloading, profile
from . import versions as version_module
Expand Down Expand Up @@ -81,7 +82,6 @@
from .utils_comm import gather_from_workers, retry_operation, scatter_to_workers
from .utils_perf import disable_gc_diagnosis, enable_gc_diagnosis
from .variable import VariableExtension
from .widgets import get_template

try:
from cython import compiled
Expand Down
4 changes: 2 additions & 2 deletions distributed/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import dask
from dask import delayed
from dask.utils import apply, parse_timedelta, stringify
from dask.utils import apply, parse_timedelta, stringify, typename

from distributed import Client, Nanny, Worker, fire_and_forget, wait
from distributed.comm import Comm
Expand All @@ -27,7 +27,7 @@
from distributed.metrics import time
from distributed.protocol.pickle import dumps
from distributed.scheduler import MemoryState, Scheduler
from distributed.utils import TimeoutError, tmpfile, typename
from distributed.utils import TimeoutError, tmpfile
from distributed.utils_test import (
captured_logger,
cluster,
Expand Down
16 changes: 6 additions & 10 deletions distributed/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
sync,
thread_state,
truncate_exception,
typename,
warn_on_duration,
)
from distributed.utils_test import (
Expand Down Expand Up @@ -596,15 +595,12 @@ def test_parse_timedelta_deprecated():
assert parse_timedelta is dask.utils.parse_timedelta


def test_typename_deprecated():
with pytest.warns(FutureWarning, match="typename is deprecated"):
from distributed.utils import typename
assert typename is dask.utils.typename


def test_iscoroutinefunction_unhashable_input():
# Ensure iscoroutinefunction can handle unhashable callables
assert not iscoroutinefunction(_UnhashableCallable())


class MyType:
pass


def test_typename_on_instances():
instance = MyType()
assert typename(instance) == typename(MyType)
25 changes: 4 additions & 21 deletions distributed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import dask
from dask import istask
from dask.utils import parse_timedelta as _parse_timedelta
from dask.widgets import get_template

try:
from tornado.ioloop import PollIOLoop
Expand Down Expand Up @@ -1151,23 +1152,6 @@ def warn_on_duration(duration, msg):
warnings.warn(msg, stacklevel=2)


def typename(typ):
"""Return name of type
Examples
--------
>>> from distributed import Scheduler
>>> typename(Scheduler)
'distributed.scheduler.Scheduler'
"""
if not isinstance(typ, type):
return typename(type(typ))
try:
return typ.__module__ + "." + typ.__name__
except AttributeError:
return str(typ)


def format_dashboard_link(host, port):
template = dask.config.get("distributed.dashboard.link")
if dask.config.get("distributed.scheduler.dashboard.tls.cert"):
Expand Down Expand Up @@ -1244,17 +1228,13 @@ class Log(str):
"""A container for newline-delimited string of log entries"""

def _repr_html_(self):
from .widgets import get_template # Avoiding circular import

return get_template("log.html.j2").render(log=self)


class Logs(dict):
"""A container for a dict mapping names to strings of log entries"""

def _repr_html_(self):
from .widgets import get_template # Avoiding circular import

return get_template("logs.html.j2").render(logs=self)


Expand Down Expand Up @@ -1285,6 +1265,8 @@ def cli_keywords(d: dict, cls=None, cmd=None):
...
ValueError: Class distributed.worker.Worker does not support keyword x
"""
from dask.utils import typename

if cls or cmd:
for k in d:
if not has_keyword(cls, k) and not command_has_keyword(cmd, k):
Expand Down Expand Up @@ -1440,6 +1422,7 @@ def clean_dashboard_address(addrs: AnyType, default_listen_ip: str = "") -> List
"funcname": "dask.utils.funcname",
"parse_bytes": "dask.utils.parse_bytes",
"parse_timedelta": "dask.utils.parse_timedelta",
"typename": "dask.utils.typename",
}


Expand Down
11 changes: 10 additions & 1 deletion distributed/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
from .utils import get_environment, get_template
import os.path

from dask.widgets import FILTERS, TEMPLATE_PATHS

from ..utils import key_split

TEMPLATE_PATHS.append(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
)
FILTERS["key_split"] = key_split
2 changes: 1 addition & 1 deletion distributed/widgets/templates/client.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<td style="text-align: left;"></td>
{% elif cluster %}
<td style="text-align: left;"><strong>Connection method:</strong> Cluster object</td>
<td style="text-align: left;"><strong>Cluster type:</strong> {{ cluster | type }}</td>
<td style="text-align: left;"><strong>Cluster type:</strong> {{ cluster | type | typename(short=True) }}</td>
{% elif scheduler_file %}
<td style="text-align: left;"><strong>Connection method:</strong> Scheduler file</td>
<td style="text-align: left;"><strong>Scheduler file:</strong> {{ scheduler_file }}</td>
Expand Down
2 changes: 1 addition & 1 deletion distributed/widgets/templates/computation.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<summary style="margin-bottom": 20px><h4 style="display:inline">Task Groups</h4></summary>
<ul>
{% for gr in groups %}
<li> {{ gr._repr_html_() }} </li>
<li> {{ gr.__repr__() | html_escape }} </li>
{% endfor %}
</ul>
</details>
28 changes: 0 additions & 28 deletions distributed/widgets/utils.py

This file was deleted.

10 changes: 8 additions & 2 deletions distributed/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
import dask
from dask.core import istask
from dask.system import CPU_COUNT
from dask.utils import apply, format_bytes, funcname, parse_bytes, parse_timedelta
from dask.utils import (
apply,
format_bytes,
funcname,
parse_bytes,
parse_timedelta,
typename,
)

from . import comm, preloading, profile, system, utils
from .batched import BatchedSend
Expand Down Expand Up @@ -67,7 +74,6 @@
parse_ports,
silence_logging,
thread_state,
typename,
warn_on_duration,
)
from .utils_comm import gather_from_workers, pack_data, retry_operation
Expand Down