diff --git a/docs/changes/newsfragments/3764.breaking b/docs/changes/newsfragments/3764.breaking new file mode 100644 index 00000000000..dd8ab3d66d0 --- /dev/null +++ b/docs/changes/newsfragments/3764.breaking @@ -0,0 +1,3 @@ +IPython measurement magic (Special command staring with % for use in IPython) using the legacy +loop is no longer enabled by default. +To enable it set the corresponding config value (`core.register_magic`) in your ``qcodesrc.json`` config file to true. diff --git a/qcodes/__init__.py b/qcodes/__init__.py index f30a96346eb..f2ac021c21b 100644 --- a/qcodes/__init__.py +++ b/qcodes/__init__.py @@ -102,13 +102,17 @@ from qcodes.utils import validators try: - # Check if we are in iPython - get_ipython() # type: ignore[name-defined] - from qcodes.utils.magic import register_magic_class _register_magic = config.core.get('register_magic', False) if _register_magic is not False: - register_magic_class(magic_commands=_register_magic) -except NameError: + from IPython import get_ipython + + # Check if we are in IPython + ip = get_ipython() + if ip is not None: + from qcodes.utils.magic import register_magic_class + + register_magic_class(magic_commands=_register_magic) +except ImportError: pass except RuntimeError as e: print(e) diff --git a/qcodes/configuration/qcodesrc.json b/qcodes/configuration/qcodesrc.json index 2d54d21a5d2..9c72f627f82 100644 --- a/qcodes/configuration/qcodesrc.json +++ b/qcodes/configuration/qcodesrc.json @@ -1,7 +1,7 @@ { "core":{ "default_fmt": "data/{date}/#{counter}_{name}_{time}", - "register_magic": true, + "register_magic": false, "import_legacy_api": false, "db_location": "~/experiments.db", "db_debug": false, diff --git a/qcodes/configuration/qcodesrc_schema.json b/qcodes/configuration/qcodesrc_schema.json index 52365d29ced..32299449889 100644 --- a/qcodes/configuration/qcodesrc_schema.json +++ b/qcodes/configuration/qcodesrc_schema.json @@ -43,7 +43,7 @@ {"type": "boolean"}, {"type": "array"} ], - "default": true + "default": false }, "import_legacy_api" : { "description": "Import the legacy api in main qcodes namespace", diff --git a/qcodes/utils/magic.py b/qcodes/utils/magic.py index 0b6be5fc721..bb1ec68e8ff 100644 --- a/qcodes/utils/magic.py +++ b/qcodes/utils/magic.py @@ -1,4 +1,6 @@ -from IPython.core.magic import Magics, magics_class, line_cell_magic +from IPython import get_ipython +from IPython.core.magic import Magics, line_cell_magic, magics_class + @magics_class class QCoDeSMagic(Magics): @@ -153,7 +155,7 @@ def register_magic_class(cls=QCoDeSMagic, magic_commands=True): ip = get_ipython() if ip is None: - raise RuntimeError('No iPython shell found') + raise RuntimeError("No IPython shell found") else: if magic_commands is not True: # filter out any magic commands that are not in magic_commands