Repository: spyder-ide/spyder

Issue:
Relative paths in workspace.ini to make projects moveable
## Description of your problem

**What steps will reproduce the problem?**

1. Add a new project `Projects > New project...`
2. Open some files.
3. Close Spyder.
4. Copy the whole project's directory to another computer to a different path (or have it synced with other means to different directories, e.g. `/home/mm/Software/Project` and `/home/MickeyMouse/Work/Software/Project` for your home and work computers).
5. Open the project on the other computer.

**What is the expected output? What do you see instead?**

I would like to see the same files opened automatically on both computers when opening the project, but the `.spyproject/workspace.ini` file stores the full paths in `[main]recent_files`. If the paths were stored relative to `.spyproject/..` (the project's base directory), it would be possible to move the project to a different location.

**Please provide any additional information below**

There seems to be two related bugs: #1133 and #1343. Maybe more?

## Versions and main components

* Spyder Version: 3.2.3
* Python Version: 3.5.2 64bits
* Qt Version: 5.5.1
* PyQt Version: 5.5.1
* Operating system: Linux Mint 18.2 Cinnamon 64-bit


## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:

IPython >=4.0    :  6.1.0 (OK)
cython >=0.21    :  None (NOK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.12.0 (OK)
pandas >=0.13.1  :  0.19.2 (OK)
psutil >=0.3     :  5.3.1 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.7.2 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
sympy >=0.7.3    :  1.0 (OK)



Discussion:
This is a really nice suggestion and we'll try to implement it in Spyder 4. Unfortunately we can't do it in Spyder 3 because no new features are added to that version now.

Resolving patch:
diff --git a/spyder/plugins/projects/api.py b/spyder/plugins/projects/api.py
--- a/spyder/plugins/projects/api.py
+++ b/spyder/plugins/projects/api.py
@@ -70,6 +70,8 @@ def set_recent_files(self, recent_files):
         for recent_file in recent_files[:]:
             if not os.path.isfile(recent_file):
                 recent_files.remove(recent_file)
+        recent_files = [os.path.relpath(recent_file, self.root_path)
+                        for recent_file in recent_files]
         try:
             self.CONF[WORKSPACE].set('main', 'recent_files',
                                      list(OrderedDict.fromkeys(recent_files)))
@@ -84,6 +86,9 @@ def get_recent_files(self):
         except EnvironmentError:
             return []
 
+        recent_files = [recent_file if os.path.isabs(recent_file)
+                        else os.path.join(self.root_path, recent_file)
+                        for recent_file in recent_files]
         for recent_file in recent_files[:]:
             if not os.path.isfile(recent_file):
                 recent_files.remove(recent_file)


Test patch:
diff --git a/spyder/plugins/projects/tests/test_plugin.py b/spyder/plugins/projects/tests/test_plugin.py
--- a/spyder/plugins/projects/tests/test_plugin.py
+++ b/spyder/plugins/projects/tests/test_plugin.py
@@ -188,8 +188,9 @@ def test_set_get_project_filenames_when_closing(create_projects, tmpdir):
 
     Regression test for Issue #8375
     """
-    opened_files = ['file1', 'file2', 'file3']
     path = to_text_string(tmpdir.mkdir('project1'))
+    opened_files = [os.path.join(path, file)
+                    for file in ['file1', 'file2', 'file3']]
 
     # Create the projects plugin.
     projects = create_projects(path, opened_files)
@@ -206,9 +207,10 @@ def test_set_get_project_filenames_when_switching(create_projects, tmpdir):
     Test that files in the Editor are loaded and saved correctly when
     switching projects.
     """
-    opened_files = ['file1', 'file2', 'file3']
     path1 = to_text_string(tmpdir.mkdir('project1'))
     path2 = to_text_string(tmpdir.mkdir('project2'))
+    opened_files = [os.path.join(path1, file)
+                    for file in ['file1', 'file2', 'file3']]
 
     # Create the projects plugin.
     projects = create_projects(path1, opened_files)