Repository: spyder-ide/spyder

Issue:
Status bar displays incorrect interpreter on Windows
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
The status bar indicates the incorrect conda environment for the interpreter


### What steps reproduce the problem?

1. Change interpreter settings in preferences and apply
2. Restart Spyder to update status bar interpreter (See issue #11006)
3. The status bar indicates the interpreter as "envs"

### What is the expected output? What do you see instead?
Status bar should list the conda environment of the current selected interpreter


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

None

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.0.0
* Python version: 3.7.5
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: Windows 10 Enterprise, version 1809, OS build 17763.864

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.5.2 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
sphinx >=0.6.6               :  2.2.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
psutil >=0.3                 :  5.6.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.4 (OK)
cython >=0.21                :  0.29.14 (OK)
IPython >=4.0                :  7.10.1 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
numpy >=1.7                  :  1.16.5 (OK)
scipy >=0.17.0               :  1.3.2 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.2 (OK)
rtree >=0.8.3                :  0.8.3 (OK)




Discussion:

Resolving patch:
diff --git a/spyder/preferences/maininterpreter.py b/spyder/preferences/maininterpreter.py
--- a/spyder/preferences/maininterpreter.py
+++ b/spyder/preferences/maininterpreter.py
@@ -261,6 +261,6 @@ def apply_settings(self, options):
                 self.set_option('custom_interpreter', executable)
         if not self.pyexec_edit.text():
             self.set_option('custom_interpreter', '')
-
         if 'default' in options or 'custom' in options:
             self.main.sig_main_interpreter_changed.emit()
+        self.main.apply_settings()
diff --git a/spyder/widgets/status.py b/spyder/widgets/status.py
--- a/spyder/widgets/status.py
+++ b/spyder/widgets/status.py
@@ -256,7 +256,10 @@ def _process_conda_env_info(self):
 
         envs_folder = os.path.sep + 'envs' + os.path.sep
         if envs_folder in self._interpreter:
-            env = os.path.dirname(os.path.dirname(self._interpreter))
+            if os.name == 'nt':
+                env = os.path.dirname(self._interpreter)
+            else:
+                env = os.path.dirname(os.path.dirname(self._interpreter))
             env = os.path.basename(env)
         else:
             env = 'base'


Test patch:
diff --git a/spyder/widgets/tests/test_status.py b/spyder/widgets/tests/test_status.py
--- a/spyder/widgets/tests/test_status.py
+++ b/spyder/widgets/tests/test_status.py
@@ -75,7 +75,10 @@ def test_status_bar_conda_status(status_bar, qtbot, mocker):
         # We patch the method that calls for info to return values to test
         mocker.patch.object(w, '_get_conda_env_info', return_value=(out, err))
 
-        interpreter = os.sep.join(['miniconda', 'bin', 'python'])
+        if os.name == 'nt':
+            interpreter = os.sep.join(['miniconda', 'python'])
+        else:
+            interpreter = os.sep.join(['miniconda', 'bin', 'python'])
         w.update_interpreter(interpreter)
         assert w.get_tooltip() == interpreter
         text = w._process_conda_env_info()
@@ -83,7 +86,10 @@ def test_status_bar_conda_status(status_bar, qtbot, mocker):
         assert mock_py_ver in text
 
         # We patch the method that calls for info to return values to test
-        interpreter = os.sep.join(['miniconda', 'envs', 'foo', 'bin', 'python'])
+        if os.name == 'nt':
+            interpreter = os.sep.join(['miniconda', 'envs', 'foo', 'python'])
+        else:
+            interpreter = os.sep.join(['miniconda', 'envs', 'foo', 'bin', 'python'])
         w.update_interpreter(interpreter)
         assert w.get_tooltip() == interpreter
         text = w._process_conda_env_info()