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

make qcodes.__version__ lazy #5931

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 18 additions & 4 deletions src/qcodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@

from typing_extensions import deprecated

import qcodes._version
import qcodes.configuration as qcconfig
from qcodes.logger.logger import conditionally_start_all_logging
from qcodes.utils import QCoDeSDeprecationWarning
from qcodes.utils.spyder_utils import add_to_spyder_UMR_excludelist

__version__ = qcodes._version.__version__


config: qcconfig.Config = qcconfig.Config()

conditionally_start_all_logging()
Expand Down Expand Up @@ -107,3 +103,21 @@ def test(**kwargs: Any) -> int:
del deprecated

test.__test__ = False # type: ignore[attr-defined] # Don't try to run this method as a test


__version__: str

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.

TODO this means that unknown attributes are typed as Any rather than an error
Using Literal["__version__"] as the input type does not seem to result in other attributes being rejected
"""
if name == "__version__":
import qcodes._version

__version__ = qcodes._version.__version__
return __version__
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Loading