Skip to content

make qcodes.__version__ lazy#5931

Open
jenshnielsen wants to merge 1 commit into
microsoft:mainfrom
jenshnielsen:jenshnielsen/lazy_version
Open

make qcodes.__version__ lazy#5931
jenshnielsen wants to merge 1 commit into
microsoft:mainfrom
jenshnielsen:jenshnielsen/lazy_version

Conversation

@jenshnielsen

@jenshnielsen jenshnielsen commented Apr 5, 2024

Copy link
Copy Markdown
Collaborator

This speeds up importing qcodes from an editable install with ~ 0.6-0.7 s assuming that you do not actually make use of the __version__ attribute. By only doing this in a if not TYPE_CHECKING: block we avoid losing static type information about top level attributes

@jenshnielsen
jenshnielsen requested a review from a team as a code owner April 5, 2024 09:31
@jenshnielsen
jenshnielsen marked this pull request as draft April 5, 2024 09:31
@codecov

codecov Bot commented Apr 5, 2024

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.11%. Comparing base (5737689) to head (58ba339).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5931   +/-   ##
=======================================
  Coverage   71.11%   71.11%           
=======================================
  Files         305      305           
  Lines       32004    32004           
=======================================
  Hits        22760    22760           
  Misses       9244     9244           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jenshnielsen jenshnielsen changed the title make qcodes version lazy make qcodes.__version__ lazy Apr 5, 2024
@jenshnielsen
jenshnielsen force-pushed the jenshnielsen/lazy_version branch from 9bd9158 to 27fce61 Compare June 9, 2024 18:00
@jenshnielsen
jenshnielsen force-pushed the jenshnielsen/lazy_version branch 2 times, most recently from 55ea07f to f24d220 Compare May 13, 2026 14:26
@jenshnielsen
jenshnielsen marked this pull request as ready for review May 18, 2026 08:41
@jenshnielsen
jenshnielsen force-pushed the jenshnielsen/lazy_version branch 2 times, most recently from 0028cd1 to 737cb3c Compare May 18, 2026 15:42
Resolving qcodes.__version__ is slow in an editable install because it
shells out to run ``git describe``. Compute it lazily in the module level
``__getattr__`` so it is only evaluated when actually accessed, keeping
``import qcodes`` fast.

Under ``TYPE_CHECKING`` ``__version__`` is defined with a placeholder value
and added to ``__all__`` so static type checkers still know it exists.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 93c35dbe-0d71-45b1-afcb-57ef16eeaa30
@jenshnielsen
jenshnielsen force-pushed the jenshnielsen/lazy_version branch from 737cb3c to 58ba339 Compare July 16, 2026 20:46
@jenshnielsen
jenshnielsen enabled auto-merge July 17, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant