diff --git a/src/qcodes/__init__.py b/src/qcodes/__init__.py index e6f0b8d4674..5e3d0c15b93 100644 --- a/src/qcodes/__init__.py +++ b/src/qcodes/__init__.py @@ -8,16 +8,12 @@ # config import warnings -from typing import Any +from typing import TYPE_CHECKING, Any -import qcodes._version import qcodes.configuration as qcconfig from qcodes.logger.logger import conditionally_start_all_logging from qcodes.utils import QCoDeSDeprecationWarning -__version__ = qcodes._version.__version__ - - config: qcconfig.Config = qcconfig.Config() conditionally_start_all_logging() @@ -81,3 +77,25 @@ "Please avoid setting this in your `qcodesrc.json` config file.", QCoDeSDeprecationWarning, ) + +if not TYPE_CHECKING: + + def __getattr__(name: str) -> Any: + """ + Getting __version__ is slow in an editable install since we have shell out to run git describe. + Here we only do it lazily if required. + + """ + if name == "__version__": + import qcodes._version # noqa: PLC0415 # lazy import since getting version is slow in editable install. + + __version__ = qcodes._version.__version__ + return __version__ + raise AttributeError(f"module {__name__} has no attribute {name}") +else: + __version__ = "not_set" + +__all__ = [ + "__version__", + "config", +]