We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
IOError when getting saved file names in a project
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Opening spyder from Terminal in macOS with '~/anaconda2/bin/spyder $@' causes an Exception and Spyder does not remember last config. In addition, Spyder creates a new project in the current working directory.

### Traceback
```python-traceback
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/projects.py", line 156, in <lambda>
    lambda v: self.editor.setup_open_files())
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/editor.py", line 2702, in setup_open_files
    filenames = self.projects.get_project_filenames()
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/projects.py", line 341, in get_project_filenames
    recent_files = self.current_active_project.get_recent_files()
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/widgets/projects/type/__init__.py", line 79, in get_recent_files
    default=[])
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py", line 377, in get
    self.set(section, option, default)
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py", line 445, in set
    self._save()
  File "/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py", line 120, in _save
    raise(e)
IOError: [Errno 2] No such file or directory: u'sn_0_9996680/.spyproject/workspace.ini'
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'json': {'documentation_url': u'https://developer.github.com/v3', 'message': u'Bad credentials'}, 'code': 401}
```

## Versions

* Spyder version: 3.3.0 
* Python version: 2.7.15
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Darwin 18.0.0

### Dependencies

```
pyflakes >=0.5.0  :  2.0.0 (OK)
pycodestyle >=2.3 :  2.4.0 (OK)
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.7.5 (OK)
rope >=0.9.4      :  0.10.7 (OK)
jedi >=0.9.0      :  0.12.0 (OK)
psutil >=0.3      :  5.4.6 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
pandas >=0.13.1   :  0.23.3 (OK)
numpy >=1.7       :  1.14.5 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.28.3 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0;<6.0:  5.7.0 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
pylint >=0.25     :  1.9.2 (OK)
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `spyder/widgets/projects/type/__init__.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # -----------------------------------------------------------------------------
3 # Copyright © Spyder Project Contributors
4 #
5 # Licensed under the terms of the MIT License
6 # (see spyder/__init__.py for details)
7 # -----------------------------------------------------------------------------
8 """Project types"""
9 
10 import os
11 import os.path as osp
12 from collections import OrderedDict
13 
14 from spyder.config.base import _
15 from spyder.py3compat import to_text_string
16 from spyder.widgets.projects.config import (ProjectConfig, CODESTYLE,
17                                             CODESTYLE_DEFAULTS,
18                                             CODESTYLE_VERSION, WORKSPACE,
19                                             WORKSPACE_DEFAULTS,
20                                             WORKSPACE_VERSION,
21                                             ENCODING, ENCODING_DEFAULTS,
22                                             ENCODING_VERSION,
23                                             VCS, VCS_DEFAULTS, VCS_VERSION)
24 
25 
26 class BaseProject(object):
27     """Spyder base project.
28 
29     This base class must not be used directly, but inherited from. It does not
30     assume that python is specific to this project.
31     """
32     PROJECT_FOLDER = '.spyproject'
33     PROJECT_TYPE_NAME = None
34     IGNORE_FILE = ""
35     CONFIG_SETUP = {WORKSPACE: {'filename': '{0}.ini'.format(WORKSPACE),
36                                 'defaults': WORKSPACE_DEFAULTS,
37                                 'version': WORKSPACE_VERSION},
38                     CODESTYLE: {'filename': '{0}.ini'.format(CODESTYLE),
39                                 'defaults': CODESTYLE_DEFAULTS,
40                                 'version': CODESTYLE_VERSION},
41                     ENCODING: {'filename': '{0}.ini'.format(ENCODING),
42                                'defaults': ENCODING_DEFAULTS,
43                                'version': ENCODING_VERSION},
44                     VCS: {'filename': '{0}.ini'.format(VCS),
45                           'defaults': VCS_DEFAULTS,
46                           'version': VCS_VERSION}
47                     }
48 
49     def __init__(self, root_path):
50         self.name = None
51         self.root_path = root_path
52         self.open_project_files = []
53         self.open_non_project_files = []
54         self.config_files = []
55         self.CONF = {}
56 
57         # Configuration files
58 
59         self.related_projects = []  # storing project path, not project objects
60 #        self.pythonpath = []
61         self.opened = True
62 
63         self.ioerror_flag = False
64         self.create_project_config_files()
65 
66     # --- Helpers
67     # -------------------------------------------------------------------------
68     def set_recent_files(self, recent_files):
69         """Set a list of files opened by the project."""
70         for recent_file in recent_files[:]:
71             if not os.path.isfile(recent_file):
72                 recent_files.remove(recent_file)
73         self.CONF[WORKSPACE].set('main', 'recent_files',
74                                  list(OrderedDict.fromkeys(recent_files)))
75 
76     def get_recent_files(self):
77         """Return a list of files opened by the project."""
78         recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',
79                                                 default=[])
80         for recent_file in recent_files[:]:
81             if not os.path.isfile(recent_file):
82                 recent_files.remove(recent_file)
83         return list(OrderedDict.fromkeys(recent_files))
84 
85     def create_project_config_files(self):
86         """ """
87         dic = self.CONFIG_SETUP
88         for key in dic:
89             name = key
90             filename = dic[key]['filename']
91             defaults = dic[key]['defaults']
92             version = dic[key]['version']
93             self.CONF[key] = ProjectConfig(name, self.root_path, filename,
94                                            defaults=defaults, load=True,
95                                            version=version)
96 
97     def get_conf_files(self):
98         """ """
99         return self.CONF
100 
101     def add_ignore_lines(self, lines):
102         """ """
103         text = self.IGNORE_FILE
104         for line in lines:
105             text += line
106         self.IGNORE_FILE = text
107 
108     def set_root_path(self, root_path):
109         """Set project root path."""
110         if self.name is None:
111             self.name = osp.basename(root_path)
112         self.root_path = to_text_string(root_path)
113         config_path = self.__get_project_config_path()
114         if osp.exists(config_path):
115             self.load()
116         else:
117             if not osp.isdir(self.root_path):
118                 os.mkdir(self.root_path)
119             self.save()
120 
121     def rename(self, new_name):
122         """Rename project and rename its root path accordingly."""
123         old_name = self.name
124         self.name = new_name
125         pypath = self.relative_pythonpath  # ??
126         self.root_path = self.root_path[:-len(old_name)]+new_name
127         self.relative_pythonpath = pypath  # ??
128         self.save()
129 
130     def __get_project_config_folder(self):
131         """Return project configuration folder."""
132         return osp.join(self.root_path, self.PROJECT_FOLDER)
133 
134     def __get_project_config_path(self):
135         """Return project configuration path"""
136         return osp.join(self.root_path, self.CONFIG_NAME)
137 
138     def load(self):
139         """Load project data"""
140 #        fname = self.__get_project_config_path()
141 #        try:
142 #            # Old format (Spyder 2.0-2.1 for Python 2)
143 #            with open(fname, 'U') as fdesc:
144 #                data = pickle.loads(fdesc.read())
145 #        except (pickle.PickleError, TypeError, UnicodeDecodeError,
146 #                AttributeError):
147 #            try:
148 #                # New format (Spyder >=2.2 for Python 2 and Python 3)
149 #                with open(fname, 'rb') as fdesc:
150 #                    data = pickle.loads(fdesc.read())
151 #            except (IOError, OSError, pickle.PickleError):
152 #                self.ioerror_flag = True
153 #                return
154         # Compatibilty with old project explorer file format:
155 #        if 'relative_pythonpath' not in data:
156 #            print("Warning: converting old configuration file "
157 #                  "for project '%s'" % data['name'], file=STDERR)
158 #            self.pythonpath = data['pythonpath']
159 #            data['relative_pythonpath'] = self.relative_pythonpath
160 #        for attr in self.CONFIG_ATTR:
161 #            setattr(self, attr, data[attr])
162 #        self.save()
163 
164     def save(self):
165         """Save project data"""
166 #        data = {}
167 #        for attr in self.PROJECT_ATTR:
168 #            data[attr] = getattr(self, attr)
169 #        try:
170 #            with open(self.__get_project_config_path(), 'wb') as fdesc:
171 #                pickle.dump(data, fdesc, 2)
172 #        except (IOError, OSError):
173 #            self.ioerror_flag = True
174 
175 #    def delete(self):
176 #        """Delete project"""
177 #        os.remove(self.__get_project_config_path())
178 #
179 #    # --- Misc.
180 #    def get_related_projects(self):
181 #        """Return related projects path list"""
182 #        return self.related_projects
183 #
184 #    def set_related_projects(self, related_projects):
185 #        """Set related projects"""
186 #        self.related_projects = related_projects
187 #        self.save()
188 #
189 #    def open(self):
190 #        """Open project"""
191 #        self.opened = True
192 #        self.save()
193 #
194 #    def close(self):
195 #        """Close project"""
196 #        self.opened = False
197 #        self.save()
198 #
199 #    def is_opened(self):
200 #        """Return True if project is opened"""
201 #        return self.opened
202 #
203 #    def is_file_in_project(self, fname):
204 #        """Return True if file *fname* is in one of the project subfolders"""
205 #        fixed_root = fixpath(self.root_path)
206 #        return fixpath(fname) == fixed_root or\
207 #            fixpath(osp.dirname(fname)).startswith(fixed_root)
208 #
209 #    def is_root_path(self, dirname):
210 #        """Return True if dirname is project's root path"""
211 #        return fixpath(dirname) == fixpath(self.root_path)
212 
213 
214 class EmptyProject(BaseProject):
215     """Empty Project"""
216     PROJECT_TYPE_NAME = _('Empty project')
217
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/spyder/widgets/projects/type/__init__.py b/spyder/widgets/projects/type/__init__.py
--- a/spyder/widgets/projects/type/__init__.py
+++ b/spyder/widgets/projects/type/__init__.py
@@ -70,13 +70,20 @@
         for recent_file in recent_files[:]:
             if not os.path.isfile(recent_file):
                 recent_files.remove(recent_file)
-        self.CONF[WORKSPACE].set('main', 'recent_files',
-                                 list(OrderedDict.fromkeys(recent_files)))
+        try:
+            self.CONF[WORKSPACE].set('main', 'recent_files',
+                                     list(OrderedDict.fromkeys(recent_files)))
+        except EnvironmentError:
+            pass
 
     def get_recent_files(self):
         """Return a list of files opened by the project."""
-        recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',
-                                                default=[])
+        try:
+            recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',
+                                                    default=[])
+        except EnvironmentError:
+            return []
+
         for recent_file in recent_files[:]:
             if not os.path.isfile(recent_file):
                 recent_files.remove(recent_file)

{"golden_diff": "diff --git a/spyder/widgets/projects/type/__init__.py b/spyder/widgets/projects/type/__init__.py\n--- a/spyder/widgets/projects/type/__init__.py\n+++ b/spyder/widgets/projects/type/__init__.py\n@@ -70,13 +70,20 @@\n         for recent_file in recent_files[:]:\r\n             if not os.path.isfile(recent_file):\r\n                 recent_files.remove(recent_file)\r\n-        self.CONF[WORKSPACE].set('main', 'recent_files',\r\n-                                 list(OrderedDict.fromkeys(recent_files)))\r\n+        try:\r\n+            self.CONF[WORKSPACE].set('main', 'recent_files',\r\n+                                     list(OrderedDict.fromkeys(recent_files)))\r\n+        except EnvironmentError:\r\n+            pass\r\n \r\n     def get_recent_files(self):\r\n         \"\"\"Return a list of files opened by the project.\"\"\"\r\n-        recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',\r\n-                                                default=[])\r\n+        try:\r\n+            recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',\r\n+                                                    default=[])\r\n+        except EnvironmentError:\r\n+            return []\r\n+\r\n         for recent_file in recent_files[:]:\r\n             if not os.path.isfile(recent_file):\r\n                 recent_files.remove(recent_file)\n", "issue": "IOError when getting saved file names in a project\n## Description\r\n\r\n### What steps will reproduce the problem?\r\n\r\n<!--- You can use Markdown here --->\r\n\r\nOpening spyder from Terminal in macOS with '~/anaconda2/bin/spyder $@' causes an Exception and Spyder does not remember last config. In addition, Spyder creates a new project in the current working directory.\r\n\r\n### Traceback\r\n```python-traceback\r\n  File \"/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/projects.py\", line 156, in <lambda>\r\n    lambda v: self.editor.setup_open_files())\r\n  File \"/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/editor.py\", line 2702, in setup_open_files\r\n    filenames = self.projects.get_project_filenames()\r\n  File \"/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/plugins/projects.py\", line 341, in get_project_filenames\r\n    recent_files = self.current_active_project.get_recent_files()\r\n  File \"/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/widgets/projects/type/__init__.py\", line 79, in get_recent_files\r\n    default=[])\r\n  File \"/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py\", line 377, in get\r\n    self.set(section, option, default)\r\n  File \"/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py\", line 445, in set\r\n    self._save()\r\n  File \"/Users/samschott/anaconda2/lib/python2.7/site-packages/spyder/config/user.py\", line 120, in _save\r\n    raise(e)\r\nIOError: [Errno 2] No such file or directory: u'sn_0_9996680/.spyproject/workspace.ini'\r\nWARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'json': {'documentation_url': u'https://developer.github.com/v3', 'message': u'Bad credentials'}, 'code': 401}\r\n```\r\n\r\n## Versions\r\n\r\n* Spyder version: 3.3.0 \r\n* Python version: 2.7.15\r\n* Qt version: 5.9.6\r\n* PyQt5 version: 5.9.2\r\n* Operating System: Darwin 18.0.0\r\n\r\n### Dependencies\r\n\r\n```\r\npyflakes >=0.5.0  :  2.0.0 (OK)\r\npycodestyle >=2.3 :  2.4.0 (OK)\r\npygments >=2.0    :  2.2.0 (OK)\r\nsphinx >=0.6.6    :  1.7.5 (OK)\r\nrope >=0.9.4      :  0.10.7 (OK)\r\njedi >=0.9.0      :  0.12.0 (OK)\r\npsutil >=0.3      :  5.4.6 (OK)\r\nnbconvert >=4.0   :  5.3.1 (OK)\r\npandas >=0.13.1   :  0.23.3 (OK)\r\nnumpy >=1.7       :  1.14.5 (OK)\r\nsympy >=0.7.3     :  1.1.1 (OK)\r\ncython >=0.21     :  0.28.3 (OK)\r\nqtconsole >=4.2.0 :  4.3.1 (OK)\r\nIPython >=4.0;<6.0:  5.7.0 (OK)\r\nmatplotlib >=2.0.0:  2.2.2 (OK)\r\npylint >=0.25     :  1.9.2 (OK)\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\r\n# -----------------------------------------------------------------------------\r\n# Copyright \u00a9 Spyder Project Contributors\r\n#\r\n# Licensed under the terms of the MIT License\r\n# (see spyder/__init__.py for details)\r\n# -----------------------------------------------------------------------------\r\n\"\"\"Project types\"\"\"\r\n\r\nimport os\r\nimport os.path as osp\r\nfrom collections import OrderedDict\r\n\r\nfrom spyder.config.base import _\r\nfrom spyder.py3compat import to_text_string\r\nfrom spyder.widgets.projects.config import (ProjectConfig, CODESTYLE,\r\n                                            CODESTYLE_DEFAULTS,\r\n                                            CODESTYLE_VERSION, WORKSPACE,\r\n                                            WORKSPACE_DEFAULTS,\r\n                                            WORKSPACE_VERSION,\r\n                                            ENCODING, ENCODING_DEFAULTS,\r\n                                            ENCODING_VERSION,\r\n                                            VCS, VCS_DEFAULTS, VCS_VERSION)\r\n\r\n\r\nclass BaseProject(object):\r\n    \"\"\"Spyder base project.\r\n\r\n    This base class must not be used directly, but inherited from. It does not\r\n    assume that python is specific to this project.\r\n    \"\"\"\r\n    PROJECT_FOLDER = '.spyproject'\r\n    PROJECT_TYPE_NAME = None\r\n    IGNORE_FILE = \"\"\r\n    CONFIG_SETUP = {WORKSPACE: {'filename': '{0}.ini'.format(WORKSPACE),\r\n                                'defaults': WORKSPACE_DEFAULTS,\r\n                                'version': WORKSPACE_VERSION},\r\n                    CODESTYLE: {'filename': '{0}.ini'.format(CODESTYLE),\r\n                                'defaults': CODESTYLE_DEFAULTS,\r\n                                'version': CODESTYLE_VERSION},\r\n                    ENCODING: {'filename': '{0}.ini'.format(ENCODING),\r\n                               'defaults': ENCODING_DEFAULTS,\r\n                               'version': ENCODING_VERSION},\r\n                    VCS: {'filename': '{0}.ini'.format(VCS),\r\n                          'defaults': VCS_DEFAULTS,\r\n                          'version': VCS_VERSION}\r\n                    }\r\n\r\n    def __init__(self, root_path):\r\n        self.name = None\r\n        self.root_path = root_path\r\n        self.open_project_files = []\r\n        self.open_non_project_files = []\r\n        self.config_files = []\r\n        self.CONF = {}\r\n\r\n        # Configuration files\r\n\r\n        self.related_projects = []  # storing project path, not project objects\r\n#        self.pythonpath = []\r\n        self.opened = True\r\n\r\n        self.ioerror_flag = False\r\n        self.create_project_config_files()\r\n\r\n    # --- Helpers\r\n    # -------------------------------------------------------------------------\r\n    def set_recent_files(self, recent_files):\r\n        \"\"\"Set a list of files opened by the project.\"\"\"\r\n        for recent_file in recent_files[:]:\r\n            if not os.path.isfile(recent_file):\r\n                recent_files.remove(recent_file)\r\n        self.CONF[WORKSPACE].set('main', 'recent_files',\r\n                                 list(OrderedDict.fromkeys(recent_files)))\r\n\r\n    def get_recent_files(self):\r\n        \"\"\"Return a list of files opened by the project.\"\"\"\r\n        recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',\r\n                                                default=[])\r\n        for recent_file in recent_files[:]:\r\n            if not os.path.isfile(recent_file):\r\n                recent_files.remove(recent_file)\r\n        return list(OrderedDict.fromkeys(recent_files))\r\n\r\n    def create_project_config_files(self):\r\n        \"\"\" \"\"\"\r\n        dic = self.CONFIG_SETUP\r\n        for key in dic:\r\n            name = key\r\n            filename = dic[key]['filename']\r\n            defaults = dic[key]['defaults']\r\n            version = dic[key]['version']\r\n            self.CONF[key] = ProjectConfig(name, self.root_path, filename,\r\n                                           defaults=defaults, load=True,\r\n                                           version=version)\r\n\r\n    def get_conf_files(self):\r\n        \"\"\" \"\"\"\r\n        return self.CONF\r\n\r\n    def add_ignore_lines(self, lines):\r\n        \"\"\" \"\"\"\r\n        text = self.IGNORE_FILE\r\n        for line in lines:\r\n            text += line\r\n        self.IGNORE_FILE = text\r\n\r\n    def set_root_path(self, root_path):\r\n        \"\"\"Set project root path.\"\"\"\r\n        if self.name is None:\r\n            self.name = osp.basename(root_path)\r\n        self.root_path = to_text_string(root_path)\r\n        config_path = self.__get_project_config_path()\r\n        if osp.exists(config_path):\r\n            self.load()\r\n        else:\r\n            if not osp.isdir(self.root_path):\r\n                os.mkdir(self.root_path)\r\n            self.save()\r\n\r\n    def rename(self, new_name):\r\n        \"\"\"Rename project and rename its root path accordingly.\"\"\"\r\n        old_name = self.name\r\n        self.name = new_name\r\n        pypath = self.relative_pythonpath  # ??\r\n        self.root_path = self.root_path[:-len(old_name)]+new_name\r\n        self.relative_pythonpath = pypath  # ??\r\n        self.save()\r\n\r\n    def __get_project_config_folder(self):\r\n        \"\"\"Return project configuration folder.\"\"\"\r\n        return osp.join(self.root_path, self.PROJECT_FOLDER)\r\n\r\n    def __get_project_config_path(self):\r\n        \"\"\"Return project configuration path\"\"\"\r\n        return osp.join(self.root_path, self.CONFIG_NAME)\r\n\r\n    def load(self):\r\n        \"\"\"Load project data\"\"\"\r\n#        fname = self.__get_project_config_path()\r\n#        try:\r\n#            # Old format (Spyder 2.0-2.1 for Python 2)\r\n#            with open(fname, 'U') as fdesc:\r\n#                data = pickle.loads(fdesc.read())\r\n#        except (pickle.PickleError, TypeError, UnicodeDecodeError,\r\n#                AttributeError):\r\n#            try:\r\n#                # New format (Spyder >=2.2 for Python 2 and Python 3)\r\n#                with open(fname, 'rb') as fdesc:\r\n#                    data = pickle.loads(fdesc.read())\r\n#            except (IOError, OSError, pickle.PickleError):\r\n#                self.ioerror_flag = True\r\n#                return\r\n        # Compatibilty with old project explorer file format:\r\n#        if 'relative_pythonpath' not in data:\r\n#            print(\"Warning: converting old configuration file \"\r\n#                  \"for project '%s'\" % data['name'], file=STDERR)\r\n#            self.pythonpath = data['pythonpath']\r\n#            data['relative_pythonpath'] = self.relative_pythonpath\r\n#        for attr in self.CONFIG_ATTR:\r\n#            setattr(self, attr, data[attr])\r\n#        self.save()\r\n\r\n    def save(self):\r\n        \"\"\"Save project data\"\"\"\r\n#        data = {}\r\n#        for attr in self.PROJECT_ATTR:\r\n#            data[attr] = getattr(self, attr)\r\n#        try:\r\n#            with open(self.__get_project_config_path(), 'wb') as fdesc:\r\n#                pickle.dump(data, fdesc, 2)\r\n#        except (IOError, OSError):\r\n#            self.ioerror_flag = True\r\n\r\n#    def delete(self):\r\n#        \"\"\"Delete project\"\"\"\r\n#        os.remove(self.__get_project_config_path())\r\n#\r\n#    # --- Misc.\r\n#    def get_related_projects(self):\r\n#        \"\"\"Return related projects path list\"\"\"\r\n#        return self.related_projects\r\n#\r\n#    def set_related_projects(self, related_projects):\r\n#        \"\"\"Set related projects\"\"\"\r\n#        self.related_projects = related_projects\r\n#        self.save()\r\n#\r\n#    def open(self):\r\n#        \"\"\"Open project\"\"\"\r\n#        self.opened = True\r\n#        self.save()\r\n#\r\n#    def close(self):\r\n#        \"\"\"Close project\"\"\"\r\n#        self.opened = False\r\n#        self.save()\r\n#\r\n#    def is_opened(self):\r\n#        \"\"\"Return True if project is opened\"\"\"\r\n#        return self.opened\r\n#\r\n#    def is_file_in_project(self, fname):\r\n#        \"\"\"Return True if file *fname* is in one of the project subfolders\"\"\"\r\n#        fixed_root = fixpath(self.root_path)\r\n#        return fixpath(fname) == fixed_root or\\\r\n#            fixpath(osp.dirname(fname)).startswith(fixed_root)\r\n#\r\n#    def is_root_path(self, dirname):\r\n#        \"\"\"Return True if dirname is project's root path\"\"\"\r\n#        return fixpath(dirname) == fixpath(self.root_path)\r\n\r\n\r\nclass EmptyProject(BaseProject):\r\n    \"\"\"Empty Project\"\"\"\r\n    PROJECT_TYPE_NAME = _('Empty project')\r\n", "path": "spyder/widgets/projects/type/__init__.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\r\n# -----------------------------------------------------------------------------\r\n# Copyright \u00a9 Spyder Project Contributors\r\n#\r\n# Licensed under the terms of the MIT License\r\n# (see spyder/__init__.py for details)\r\n# -----------------------------------------------------------------------------\r\n\"\"\"Project types\"\"\"\r\n\r\nimport os\r\nimport os.path as osp\r\nfrom collections import OrderedDict\r\n\r\nfrom spyder.config.base import _\r\nfrom spyder.py3compat import to_text_string\r\nfrom spyder.widgets.projects.config import (ProjectConfig, CODESTYLE,\r\n                                            CODESTYLE_DEFAULTS,\r\n                                            CODESTYLE_VERSION, WORKSPACE,\r\n                                            WORKSPACE_DEFAULTS,\r\n                                            WORKSPACE_VERSION,\r\n                                            ENCODING, ENCODING_DEFAULTS,\r\n                                            ENCODING_VERSION,\r\n                                            VCS, VCS_DEFAULTS, VCS_VERSION)\r\n\r\n\r\nclass BaseProject(object):\r\n    \"\"\"Spyder base project.\r\n\r\n    This base class must not be used directly, but inherited from. It does not\r\n    assume that python is specific to this project.\r\n    \"\"\"\r\n    PROJECT_FOLDER = '.spyproject'\r\n    PROJECT_TYPE_NAME = None\r\n    IGNORE_FILE = \"\"\r\n    CONFIG_SETUP = {WORKSPACE: {'filename': '{0}.ini'.format(WORKSPACE),\r\n                                'defaults': WORKSPACE_DEFAULTS,\r\n                                'version': WORKSPACE_VERSION},\r\n                    CODESTYLE: {'filename': '{0}.ini'.format(CODESTYLE),\r\n                                'defaults': CODESTYLE_DEFAULTS,\r\n                                'version': CODESTYLE_VERSION},\r\n                    ENCODING: {'filename': '{0}.ini'.format(ENCODING),\r\n                               'defaults': ENCODING_DEFAULTS,\r\n                               'version': ENCODING_VERSION},\r\n                    VCS: {'filename': '{0}.ini'.format(VCS),\r\n                          'defaults': VCS_DEFAULTS,\r\n                          'version': VCS_VERSION}\r\n                    }\r\n\r\n    def __init__(self, root_path):\r\n        self.name = None\r\n        self.root_path = root_path\r\n        self.open_project_files = []\r\n        self.open_non_project_files = []\r\n        self.config_files = []\r\n        self.CONF = {}\r\n\r\n        # Configuration files\r\n\r\n        self.related_projects = []  # storing project path, not project objects\r\n#        self.pythonpath = []\r\n        self.opened = True\r\n\r\n        self.ioerror_flag = False\r\n        self.create_project_config_files()\r\n\r\n    # --- Helpers\r\n    # -------------------------------------------------------------------------\r\n    def set_recent_files(self, recent_files):\r\n        \"\"\"Set a list of files opened by the project.\"\"\"\r\n        for recent_file in recent_files[:]:\r\n            if not os.path.isfile(recent_file):\r\n                recent_files.remove(recent_file)\r\n        try:\r\n            self.CONF[WORKSPACE].set('main', 'recent_files',\r\n                                     list(OrderedDict.fromkeys(recent_files)))\r\n        except EnvironmentError:\r\n            pass\r\n\r\n    def get_recent_files(self):\r\n        \"\"\"Return a list of files opened by the project.\"\"\"\r\n        try:\r\n            recent_files = self.CONF[WORKSPACE].get('main', 'recent_files',\r\n                                                    default=[])\r\n        except EnvironmentError:\r\n            return []\r\n\r\n        for recent_file in recent_files[:]:\r\n            if not os.path.isfile(recent_file):\r\n                recent_files.remove(recent_file)\r\n        return list(OrderedDict.fromkeys(recent_files))\r\n\r\n    def create_project_config_files(self):\r\n        \"\"\" \"\"\"\r\n        dic = self.CONFIG_SETUP\r\n        for key in dic:\r\n            name = key\r\n            filename = dic[key]['filename']\r\n            defaults = dic[key]['defaults']\r\n            version = dic[key]['version']\r\n            self.CONF[key] = ProjectConfig(name, self.root_path, filename,\r\n                                           defaults=defaults, load=True,\r\n                                           version=version)\r\n\r\n    def get_conf_files(self):\r\n        \"\"\" \"\"\"\r\n        return self.CONF\r\n\r\n    def add_ignore_lines(self, lines):\r\n        \"\"\" \"\"\"\r\n        text = self.IGNORE_FILE\r\n        for line in lines:\r\n            text += line\r\n        self.IGNORE_FILE = text\r\n\r\n    def set_root_path(self, root_path):\r\n        \"\"\"Set project root path.\"\"\"\r\n        if self.name is None:\r\n            self.name = osp.basename(root_path)\r\n        self.root_path = to_text_string(root_path)\r\n        config_path = self.__get_project_config_path()\r\n        if osp.exists(config_path):\r\n            self.load()\r\n        else:\r\n            if not osp.isdir(self.root_path):\r\n                os.mkdir(self.root_path)\r\n            self.save()\r\n\r\n    def rename(self, new_name):\r\n        \"\"\"Rename project and rename its root path accordingly.\"\"\"\r\n        old_name = self.name\r\n        self.name = new_name\r\n        pypath = self.relative_pythonpath  # ??\r\n        self.root_path = self.root_path[:-len(old_name)]+new_name\r\n        self.relative_pythonpath = pypath  # ??\r\n        self.save()\r\n\r\n    def __get_project_config_folder(self):\r\n        \"\"\"Return project configuration folder.\"\"\"\r\n        return osp.join(self.root_path, self.PROJECT_FOLDER)\r\n\r\n    def __get_project_config_path(self):\r\n        \"\"\"Return project configuration path\"\"\"\r\n        return osp.join(self.root_path, self.CONFIG_NAME)\r\n\r\n    def load(self):\r\n        \"\"\"Load project data\"\"\"\r\n#        fname = self.__get_project_config_path()\r\n#        try:\r\n#            # Old format (Spyder 2.0-2.1 for Python 2)\r\n#            with open(fname, 'U') as fdesc:\r\n#                data = pickle.loads(fdesc.read())\r\n#        except (pickle.PickleError, TypeError, UnicodeDecodeError,\r\n#                AttributeError):\r\n#            try:\r\n#                # New format (Spyder >=2.2 for Python 2 and Python 3)\r\n#                with open(fname, 'rb') as fdesc:\r\n#                    data = pickle.loads(fdesc.read())\r\n#            except (IOError, OSError, pickle.PickleError):\r\n#                self.ioerror_flag = True\r\n#                return\r\n        # Compatibilty with old project explorer file format:\r\n#        if 'relative_pythonpath' not in data:\r\n#            print(\"Warning: converting old configuration file \"\r\n#                  \"for project '%s'\" % data['name'], file=STDERR)\r\n#            self.pythonpath = data['pythonpath']\r\n#            data['relative_pythonpath'] = self.relative_pythonpath\r\n#        for attr in self.CONFIG_ATTR:\r\n#            setattr(self, attr, data[attr])\r\n#        self.save()\r\n\r\n    def save(self):\r\n        \"\"\"Save project data\"\"\"\r\n#        data = {}\r\n#        for attr in self.PROJECT_ATTR:\r\n#            data[attr] = getattr(self, attr)\r\n#        try:\r\n#            with open(self.__get_project_config_path(), 'wb') as fdesc:\r\n#                pickle.dump(data, fdesc, 2)\r\n#        except (IOError, OSError):\r\n#            self.ioerror_flag = True\r\n\r\n#    def delete(self):\r\n#        \"\"\"Delete project\"\"\"\r\n#        os.remove(self.__get_project_config_path())\r\n#\r\n#    # --- Misc.\r\n#    def get_related_projects(self):\r\n#        \"\"\"Return related projects path list\"\"\"\r\n#        return self.related_projects\r\n#\r\n#    def set_related_projects(self, related_projects):\r\n#        \"\"\"Set related projects\"\"\"\r\n#        self.related_projects = related_projects\r\n#        self.save()\r\n#\r\n#    def open(self):\r\n#        \"\"\"Open project\"\"\"\r\n#        self.opened = True\r\n#        self.save()\r\n#\r\n#    def close(self):\r\n#        \"\"\"Close project\"\"\"\r\n#        self.opened = False\r\n#        self.save()\r\n#\r\n#    def is_opened(self):\r\n#        \"\"\"Return True if project is opened\"\"\"\r\n#        return self.opened\r\n#\r\n#    def is_file_in_project(self, fname):\r\n#        \"\"\"Return True if file *fname* is in one of the project subfolders\"\"\"\r\n#        fixed_root = fixpath(self.root_path)\r\n#        return fixpath(fname) == fixed_root or\\\r\n#            fixpath(osp.dirname(fname)).startswith(fixed_root)\r\n#\r\n#    def is_root_path(self, dirname):\r\n#        \"\"\"Return True if dirname is project's root path\"\"\"\r\n#        return fixpath(dirname) == fixpath(self.root_path)\r\n\r\n\r\nclass EmptyProject(BaseProject):\r\n    \"\"\"Empty Project\"\"\"\r\n    PROJECT_TYPE_NAME = _('Empty project')\r\n", "path": "spyder/widgets/projects/type/__init__.py"}]}