-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Add disambiguation functionality for Editor tabs #3715
Conversation
This is so nice!! I wanted this for a long time! @goanpeca, what do you think about the design? We followed the same one as Sublime :-) |
@dalthviz, I'd like to see this one finished (or at least ready for reviewing) before this Friday :-) |
…c to compress long paths
@dalthviz, you need to merge your PR with master to fix the errors in Travis. |
from itertools import izip | ||
except ImportError: | ||
# Python 3 | ||
izip = zip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this import to py3compat
"""Get tab title without ambiguation.""" | ||
finfo = self.data[index] | ||
fname = osp.basename(finfo.filename) | ||
for findex, file in enumerate(self.data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file
is a reserved word in Python 2, so you need to use a different name here.
differ_path_length = len(differ_path) | ||
if (differ_path_length > 20): | ||
path_components = self.path_components(differ_path) | ||
last_component_index = len(path_components) -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a missing space here after the minus sign:
len(path_components) - 1
break | ||
return fname | ||
|
||
def path_components(self, path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this function to utils/sourcecode.py
and add a test for it. For that you need to move the tests at the end of that file to the tests
folder in utils
, in a file called test_sourcecode.py
.
"""Return the individual components of the given file path | ||
string (for the local operating system). Taked from | ||
http://stackoverflow.com/questions/21498939/how-to-circumvent | ||
-the-fallacy-of-pythons-os-path-commonprefix.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring should be formatted like this
"""
Return the individual components of a given file path
string (for the local operating system).
Taken from http://stackoverflow.com/q/21498939/438386
"""
That link is the short link to the SO question you referenced. You can get those links by pressing the share
links that are placed below every SO question or answer.
components.reverse() # First component first | ||
return components | ||
|
||
def differ_prefix(self, path_components0, path_components1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also move this function to utils/sourcecode.py
and a test for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
differ
is a verb. Did you mean different
here? Or maybe differentiate
?
def differ_prefix(self, path_components0, path_components1): | ||
"""Return the differ prefix of the given two iterables. Based | ||
on longest_prefix in http://stackoverflow.com/questions/21498939/how-to- | ||
circumvent-the-fallacy-of-pythons-os-path-commonprefix.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reformat this docstring as I said above for path_components
.
Some of the tests you introduced are failing on Travis (i.e. Linux). Please review them. |
@@ -63,6 +63,7 @@ | |||
import thread as _thread | |||
import repr as reprlib | |||
import Queue | |||
from itertools import izip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this to
from itertools import izip as zip
@@ -78,6 +79,7 @@ | |||
import _thread | |||
import reprlib | |||
import queue as Queue | |||
izip = zip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my previous suggestion, there's no need for this line now ;-)
@@ -9,7 +9,10 @@ | |||
""" | |||
|
|||
import re | |||
|
|||
import os | |||
from spyder.py3compat import PY2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a blank line before this one, to separate standard library imports from Spyder ones.
|
||
def differentiate_prefix(path_components0, path_components1): | ||
""" | ||
Return the differ prefix of the given two iterables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this to
Return the differentiated prefix ...
common_elmt = elmt0 | ||
longest_prefix.append(elmt0) | ||
file_name_length = len(path_components0[len(path_components0)-1]) | ||
path_0 = os.path.join(*path_components0)[:-file_name_length-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spaces around the minus sign in these two lines, like this
file_name_length = len(path_components0[len(path_components0) - 1])
longest_prefix.append(elmt0) | ||
file_name_length = len(path_components0[len(path_components0)-1]) | ||
path_0 = os.path.join(*path_components0)[:-file_name_length-1] | ||
if(len(longest_prefix)>3): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add spaces around >
path_0 = os.path.join(*path_components0)[:-file_name_length-1] | ||
if(len(longest_prefix)>3): | ||
longest_path_prefix = os.path.join(*longest_prefix) | ||
length_to_delete = len(longest_path_prefix)-len(common_elmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around -
from spyder.utils import sourcecode | ||
|
||
|
||
def test_get_primary_at(tmpdir, qtbot): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these tests seems to require tmpdir
nor qtbot
, so please remove them
def test_get_identifiers(tmpdir, qtbot): | ||
code = 'import functools\nfunctools.partial' | ||
assert set(sourcecode.get_identifiers(code)) == set(['import', 'functools', | ||
'functools.partial']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please align this line like this
.. == set(['import', 'functools',
'functools.partial'])
That's what I was expecting: almost the same information is present in the tab's title and flie switcher's second row of each entry. So we need to remove from the tabs title the disambiguation text when showing it in the file switcher. Please also do that as part of this PR :-) |
…th for the file is his path.
Thanks @dalthviz for keep working on this! There's a simple style fix reported in CircleCI. Also, please don't forget to merge with 3.x to fix the problems we were seeing yesterday in CircleCI :-) |
@@ -965,11 +965,36 @@ def __modified_readonly_title(self, title, is_modified, is_readonly): | |||
title = "(%s)" % title | |||
return title | |||
|
|||
def get_tab_text(self, filename, is_modified=None, is_readonly=None): | |||
def get_tab_text(self, index, is_modified=None, is_readonly=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ccordoba12, CircleCi (pydocstyle) is giving me an error of docstring (D400), however the line that is pointing out (968
in widgets/editor.py
) can't finish in a period (is the signature of a method) . In this case what can I do to fix the code style issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this in the latest 3.x branch. Please merge it here again :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally understood what's this error is all about: you just need to add a dot to the docstring below this line, so that it reads like this
"""Return tab title."""
… Added tests for the new methods.
path_0 = '/' | ||
return path_0 | ||
|
||
def get_file_title(data, index): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python console doesn't have the same structure for tabs as the Editor, so this is not useful.
So you need to make this function to receive a filename instead of data and index, and call it differently in the Editor.
fname = fname + " - " + diff_path | ||
return fname | ||
|
||
def get_same_name_files(data, fname): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also make this function independent of data (or move it to the Editor :-)
shortest_path = path_elmts | ||
return os.path.join(*shortest_path) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these spurious blank lines
…n the tests accordingly.
I left one last comment to fix the error reported by pydocstyle, and then I'll merge :-) |
All green now!! Thanks a lot @dalthviz! This is a great addition :-) |
Fixes #3160
Fixes #2907
Edit: Include reference to related issue about tabs titles