Skip to content

Commit

Permalink
make qcodes version lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Apr 5, 2024
1 parent d522c68 commit 9bd9158
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 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,23 @@ def test(**kwargs: Any) -> int:
del deprecated

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


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 the type of __version__ is Any, which is not ideal.
__version__ is also not listed by dir(qcodes) that could be fixed by overwrting __dir__.
see https://peps.python.org/pep-0562/
"""
if name == "__version__":
import qcodes._version

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


__all__ = ["__version___", "config"]

Check warning on line 125 in src/qcodes/__init__.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.10, false)

"__version___" is specified in __all__ but is not present in module (reportUnsupportedDunderAll)

Check warning on line 125 in src/qcodes/__init__.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.11, false)

"__version___" is specified in __all__ but is not present in module (reportUnsupportedDunderAll)

Check warning on line 125 in src/qcodes/__init__.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)

"__version___" is specified in __all__ but is not present in module (reportUnsupportedDunderAll)

Check warning on line 125 in src/qcodes/__init__.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.9, false)

"__version___" is specified in __all__ but is not present in module (reportUnsupportedDunderAll)

Check warning on line 125 in src/qcodes/__init__.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.10, false)

"__version___" is specified in __all__ but is not present in module (reportUnsupportedDunderAll)

0 comments on commit 9bd9158

Please sign in to comment.