microsoft/Qcodes

`import_legacy_api` config option doesn't work

loganbvh opened this issue · 1 comments

import_legacy_api config option doesn't work

Steps to reproduce

  1. Install qcodes
  2. Set "import_legacy_api": true in qcodesrc.json
  3. import qcodes

Expected behaviour

The legacy API to be imported into the qcodes namespace: https://github.com/QCoDeS/Qcodes/blob/29646a80d63da3b1f1c54503e031ef5fcab59b5a/qcodes/__init__.py#L24-L50

Actual behaviour

qcodes not imported due to circular import in type annotations:

(scanning-squid-test) DN0a22c3aa:Documents LoganBVH$ grep "import_legacy_api" /Users/LoganBVH/opt/anaconda3/envs/scanning-squid-test/lib/python3.8/site-packages/qcodes/configuration/qcodesrc.json
        "import_legacy_api": true,
(scanning-squid-test) DN0a22c3aa:Documents LoganBVH$ python -c "import qcodes"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/LoganBVH/opt/anaconda3/envs/scanning-squid-test/lib/python3.8/site-packages/qcodes/__init__.py", line 41, in <module>
    from qcodes.loops import Loop, active_loop, active_data_set
  File "/Users/LoganBVH/opt/anaconda3/envs/scanning-squid-test/lib/python3.8/site-packages/qcodes/loops.py", line 55, in <module>
    from .actions import (
  File "/Users/LoganBVH/opt/anaconda3/envs/scanning-squid-test/lib/python3.8/site-packages/qcodes/actions.py", line 5, in <module>
    from qcodes.utils.threading import thread_map
  File "/Users/LoganBVH/opt/anaconda3/envs/scanning-squid-test/lib/python3.8/site-packages/qcodes/utils/threading.py", line 29, in <module>
    from qcodes.dataset.measurements import res_type
  File "/Users/LoganBVH/opt/anaconda3/envs/scanning-squid-test/lib/python3.8/site-packages/qcodes/dataset/__init__.py", line 23, in <module>
    from .measurements import Measurement
  File "/Users/LoganBVH/opt/anaconda3/envs/scanning-squid-test/lib/python3.8/site-packages/qcodes/dataset/measurements.py", line 679, in <module>
    class Measurement:
  File "/Users/LoganBVH/opt/anaconda3/envs/scanning-squid-test/lib/python3.8/site-packages/qcodes/dataset/measurements.py", line 696, in Measurement
    station: Optional[qc.Station] = None,
AttributeError: partially initialized module 'qcodes' has no attribute 'Station' (most likely due to a circular import)

I realize I can just import the legacy modules directly, but this config option should probably either be fixed or removed.

System

It would be helpful to provide such information:

operating system
MacOS Monterey 12.1

If you are using a released version of qcodes (recommended):
qcodes version: 0.31.0

@loganbvh thanks for the bug report this should be fixed by #3781 (But that will also deprecate this option going forward so I would recommend updating the imports to not use this option)