Skip to content

Commit 8947abd

Browse files
committed
lazily get dask version information
this uses "importlib.metadata:version" - for __version__ which is much faster than git
1 parent 9a266a0 commit 8947abd

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

distributed/__init__.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from . import config # isort:skip; load distributed configuration first
22
from . import widgets # isort:skip; load distributed widgets second
3+
4+
35
import dask
46
from dask.config import config # type: ignore
57

68
from ._version import get_versions
7-
from .actor import Actor, BaseActorFuture
9+
from .actor import Actor, ActorFuture, BaseActorFuture
810
from .client import (
911
Client,
1012
CompatibleExecutor,
@@ -46,7 +48,20 @@
4648
from .worker import Reschedule, Worker, get_client, get_worker, print, secede, warn
4749
from .worker_client import local_client, worker_client
4850

49-
versions = get_versions()
50-
__version__ = versions["version"]
51-
__git_revision__ = versions["full-revisionid"]
52-
del get_versions, versions
51+
52+
def __getattr__(name):
53+
global __version__, __git_revision__
54+
55+
if name == "__version__":
56+
from importlib.metadata import version
57+
58+
__version__ = version("distributed")
59+
return __version__
60+
61+
if name == "__git_revision__":
62+
from ._version import get_versions
63+
64+
__git_revision__ = get_versions()["full-revisionid"]
65+
return __git_revision__
66+
67+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

distributed/tests/test_init.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from __future__ import annotations
2+
3+
import importlib.metadata
4+
5+
import distributed
6+
7+
8+
def test_version() -> None:
9+
assert distributed.__version__ == importlib.metadata.version("distributed")
10+
11+
12+
def test_git_revision() -> None:
13+
assert isinstance(distributed.__git_revision__, str)

0 commit comments

Comments
 (0)