From 66aeb3fc55c8ac04242e566172af5de5cc6fe71e 2022-07-18 15:03:32 From: Clemens Brunner Date: 2022-07-18 15:03:32 Subject: [PATCH] Add setting to disable venv warning (#13706) * Add setting to disable venv warning * Fix style * Add what's new entry * Improve help text * Use double quotes Co-authored-by: Blazej Michalik <6691643+MrMino@users.noreply.github.com> * Add missing comma Co-authored-by: Blazej Michalik <6691643+MrMino@users.noreply.github.com> --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 7587a1d..0691264 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -479,6 +479,11 @@ class InteractiveShell(SingletonConfigurable): """ ).tag(config=True) + warn_venv = Bool( + True, + help="Warn if running in a virtual environment with no IPython installed (so IPython from the global environment is used).", + ).tag(config=True) + # TODO: this part of prompt management should be moved to the frontends. # Use custom TraitTypes that convert '0'->'' and '\\n'->'\n' separate_in = SeparateUnicode('\n').tag(config=True) @@ -847,11 +852,11 @@ class InteractiveShell(SingletonConfigurable): p_ver = re_m.groups() virtual_env = str(virtual_env_path).format(*p_ver) - - warn( - "Attempting to work in a virtualenv. If you encounter problems, " - "please install IPython inside the virtualenv." - ) + if self.warn_venv: + warn( + "Attempting to work in a virtualenv. If you encounter problems, " + "please install IPython inside the virtualenv." + ) import site sys.path.insert(0, virtual_env) site.addsitedir(virtual_env) diff --git a/docs/source/whatsnew/pr/silence-running-in-venv-warning.rst b/docs/source/whatsnew/pr/silence-running-in-venv-warning.rst new file mode 100644 index 0000000..ed245bd --- /dev/null +++ b/docs/source/whatsnew/pr/silence-running-in-venv-warning.rst @@ -0,0 +1,8 @@ +New setting to silence warning if working inside a virtual environment +====================================================================== + +Previously, when starting IPython in a virtual environment without IPython installed (so IPython from the global environment is used), the following warning was printed: + + Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv. + +This warning can be permanently silenced by setting ``c.InteractiveShell.warn_venv`` to ``False`` (the default is ``True``).