Repository: spyder-ide/spyder

Issue:
Error trying to open renamed project
## Description

**What steps will reproduce the problem?**

1. Rename existing project in Spyder
2. click 'OK' in dialogue about closing open file from renamed project
3. Try to open renamed project

**What is the expected output? What do you see instead?**
Got this error

**Please provide any additional information below**

  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/config/user.py", line 114, in _save
    _write_file(fname)
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/config/user.py", line 110, in _write_file
    with open(fname, 'w', encoding='utf-8') as configfile:
FileNotFoundError: [Errno 2] No such file or directory: '/home/ilion/Projects/machine-learning/voice/Read FLAC/.spyproject/workspace.ini'

Traceback (most recent call last):
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/plugins/projects.py", line 94, in <lambda>
    triggered=lambda v: self.open_project())
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/plugins/projects.py", line 261, in open_project
    self.set_project_filenames(self.editor.get_open_filenames())
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/plugins/projects.py", line 325, in set_project_filenames
    self.current_active_project.set_recent_files(recent_files)
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/widgets/projects/type/__init__.py", line 74, in set_recent_files
    list(OrderedDict.fromkeys(recent_files)))
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/config/user.py", line 448, in set
    self._save()
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/config/user.py", line 124, in _save
    raise(e)
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/config/user.py", line 120, in _save
    _write_file(fname)
  File "/home/ilion/anaconda3/lib/python3.6/site-packages/spyder/config/user.py", line 110, in _write_file
    with open(fname, 'w', encoding='utf-8') as configfile:
FileNotFoundError: [Errno 2] No such file or directory: '/home/ilion/Projects/machine-learning/voice/Read FLAC/.spyproject/workspace.ini'


## Version and main components

* Spyder Version: 3.2.4 
* Python Version: 3.6.3
* Qt Versions: 5.6.2, PyQt5 5.6 on Linux

## Dependencies
```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.21.1 (OK)
numpy >=1.7      :  1.13.3 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
rope >=0.9.4     :  0.10.7 (OK)
jedi >=0.9.0     :  0.11.0 (OK)
psutil >=0.3     :  5.4.1 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.27.3 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.2.1 (OK)
pylint >=0.25    :  1.7.4 (OK)

```



Discussion:
Thanks for reporting. We'll fix this problem in our next release.
@dalthviz, please take a look at this one.

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -638,7 +638,7 @@ def create_edit_action(text, tr_text, icon):
 
         # Projects menu
         self.projects_menu = self.menuBar().addMenu(_("&Projects"))
-
+        self.projects_menu.aboutToShow.connect(self.valid_project)
         # Tools menu
         self.tools_menu = self.menuBar().addMenu(_("&Tools"))
 
@@ -1955,6 +1955,20 @@ def show_toolbars(self):
         self._update_show_toolbars_action()
 
     # --- Other
+    def valid_project(self):
+        """Handle an invalid active project."""
+        if bool(self.projects.get_active_project_path()):
+            path = self.projects.get_active_project_path()
+            if not self.projects.is_valid_project(path):
+                if path:
+                    QMessageBox.critical(
+                        self,
+                        _('Error'),
+                        _("<b>{}</b> is no longer a valid Spyder project! "
+                          "Since it is the current active project, it will "
+                          "be closed automatically.").format(path))
+                self.projects.close_project()
+
     def free_memory(self):
         """Free memory after event."""
         gc.collect()
diff --git a/spyder/plugins/projects.py b/spyder/plugins/projects.py
--- a/spyder/plugins/projects.py
+++ b/spyder/plugins/projects.py
@@ -345,7 +345,9 @@ def get_project_filenames(self):
 
     def set_project_filenames(self, recent_files):
         """Set the list of open file names in a project"""
-        if self.current_active_project:
+        if (self.current_active_project
+                and self.is_valid_project(
+                        self.current_active_project.root_path)):
             self.current_active_project.set_recent_files(recent_files)
 
     def get_active_project_path(self):


Test patch: