Repository: spyder-ide/spyder

Issue:
Fix path manager synchronize on windows
After https://github.com/spyder-ide/spyder/pull/10623/, the sync was disabled. Need to reenable and make sure tests are correctly passing.


Discussion:
@goanpeca If you need help with that, I can provide some. I'm familiar with this feature and I'm developing on windows, so this is "easy" for me to test or contribute. Just let me know.
@jnsebgosselin I am having some issues with Spyder master on my Windows VM.

Is Spyder working ok for you on master? I start it and after the ipython console loads, it just shuts down, no error trace or segfault message.
Yes, it is working fine on latest master.
Hmm ok, :-p trying out some things. I will work on this @jnsebgosselin no worries ;-) 


> I will work on this @jnsebgosselin no worries ;-)

Excellent, thank you very much! I was afraid to see this feature go.

Updating the python paths through the `Windows Environment Variables` manager is a pain. It was significantly improved in Windows 10 compared to 7, but it is still way more easy to do it with Spyder.
>Updating the python paths through the Windows Environment Variables manager is a pain. It was significantly improved in Windows 10 compared to 7, but it is still way more easy to do it with Spyder.

It was just a temporary disable ;-), no worries

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -3010,10 +3010,8 @@ def show_path_manager(self):
         """Show path manager dialog."""
         from spyder.widgets.pathmanager import PathManager
         read_only_path = tuple(self.projects.get_pythonpath())
-
-        # TODO: update sync on windows
         dialog = PathManager(self, self.path, read_only_path,
-                             self.not_active_path, sync=False)
+                             self.not_active_path, sync=True)
         self._path_manager = dialog
         dialog.sig_path_changed.connect(self.update_python_path)
         dialog.redirect_stdio.connect(self.redirect_internalshell_stdio)
diff --git a/spyder/widgets/pathmanager.py b/spyder/widgets/pathmanager.py
--- a/spyder/widgets/pathmanager.py
+++ b/spyder/widgets/pathmanager.py
@@ -231,20 +231,20 @@ def synchronize(self):
         env = get_user_env()
 
         # Includes read only paths
-        active_path = tuple(k for k, v in self.get_path_dict().items() if v)
+        active_path = tuple(k for k, v in self.get_path_dict(True).items()
+                            if v)
 
         if remove:
             ppath = active_path
         else:
             ppath = env.get('PYTHONPATH', [])
-
             if not isinstance(ppath, list):
                 ppath = [ppath]
 
             ppath = tuple(p for p in ppath if p not in active_path)
             ppath = ppath + active_path
 
-        env['PYTHONPATH'] = ppath
+        env['PYTHONPATH'] = list(ppath)
         set_user_env(listdict2envdict(env), parent=self)
 
     def get_path_dict(self, read_only=False):


Test patch:
diff --git a/spyder/widgets/tests/test_pathmanager.py b/spyder/widgets/tests/test_pathmanager.py
--- a/spyder/widgets/tests/test_pathmanager.py
+++ b/spyder/widgets/tests/test_pathmanager.py
@@ -57,12 +57,11 @@ def test_check_uncheck_path(pathmanager):
         assert pathmanager.listwidget.item(row).checkState() == Qt.Checked
 
 
-# @pytest.mark.skipif(os.name != 'nt' or not is_module_installed('win32con'),
-@pytest.mark.skipif(True,
+@pytest.mark.skipif(os.name != 'nt' or not is_module_installed('win32con'),
                     reason=("This feature is not applicable for Unix "
                             "systems and pywin32 is needed"))
 @pytest.mark.parametrize('pathmanager',
-                         [(['path1', 'path2', 'path3'], ['path4', 'path5', 'path6'])],
+                         [(['p1', 'p2', 'p3'], ['p4', 'p5', 'p6'], [])],
                          indirect=True)
 def test_synchronize_with_PYTHONPATH(pathmanager, mocker):
     # Import here to prevent an ImportError when testing on unix systems
@@ -80,7 +79,7 @@ def test_synchronize_with_PYTHONPATH(pathmanager, mocker):
 
     # Assert that PYTHONPATH is synchronized correctly with Spyder's path list
     pathmanager.synchronize()
-    expected_pathlist = ['path1', 'path2', 'path3', 'path4', 'path5', 'path6']
+    expected_pathlist = ['p1', 'p2', 'p3', 'p4', 'p5', 'p6']
     env = get_user_env()
     assert env['PYTHONPATH'] == expected_pathlist
 
@@ -88,7 +87,7 @@ def test_synchronize_with_PYTHONPATH(pathmanager, mocker):
     # is synchronized with Spyder's path list
     pathmanager.listwidget.item(1).setCheckState(Qt.Unchecked)
     pathmanager.synchronize()
-    expected_pathlist = ['path1', 'path3', 'path4', 'path5', 'path6']
+    expected_pathlist = ['p1', 'p3', 'p4', 'p5', 'p6']
     env = get_user_env()
     assert env['PYTHONPATH'] == expected_pathlist
 
@@ -101,7 +100,7 @@ def test_synchronize_with_PYTHONPATH(pathmanager, mocker):
     # is synchronized with Spyder's path list
     pathmanager.listwidget.item(2).setCheckState(Qt.Unchecked)
     pathmanager.synchronize()
-    expected_pathlist = ['path3', 'path1', 'path4', 'path5', 'path6']
+    expected_pathlist = ['p3', 'p1', 'p4', 'p5', 'p6']
     env = get_user_env()
     assert env['PYTHONPATH'] == expected_pathlist