Skip to content
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

Merged
merged 25 commits into from
Dec 17, 2016

Conversation

dalthviz
Copy link
Member

@dalthviz dalthviz commented Nov 20, 2016

Fixes #3160
Fixes #2907

Edit: Include reference to related issue about tabs titles

@dalthviz
Copy link
Member Author

Now the editor tabs show a title that disambiguates files with the same name:

image

@ccordoba12 ccordoba12 added this to the v3.1 milestone Nov 20, 2016
@ccordoba12
Copy link
Member

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 :-)

@ccordoba12
Copy link
Member

@dalthviz, I'd like to see this one finished (or at least ready for reviewing) before this Friday :-)

@ccordoba12
Copy link
Member

@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
Copy link
Member

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):
Copy link
Member

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
Copy link
Member

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):
Copy link
Member

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."""
Copy link
Member

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):
Copy link
Member

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.

Copy link
Member

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."""
Copy link
Member

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.

@ccordoba12
Copy link
Member

ccordoba12 commented Nov 29, 2016

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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]
Copy link
Member

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):
Copy link
Member

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)
Copy link
Member

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):
Copy link
Member

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'])
Copy link
Member

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'])

@ccordoba12
Copy link
Member

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 :-)

@dalthviz
Copy link
Member Author

dalthviz commented Dec 5, 2016

This is the way the file switcher and titles in tabs will be shown:

fileswitcher2

@dalthviz
Copy link
Member Author

A preview in Windows:

win

A preview in Linux:

linux

@ccordoba12
Copy link
Member

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):
Copy link
Member Author

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?

Copy link
Member

@ccordoba12 ccordoba12 Dec 14, 2016

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 :-)

Copy link
Member

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."""

path_0 = '/'
return path_0

def get_file_title(data, index):
Copy link
Member

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):
Copy link
Member

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)


Copy link
Member

@ccordoba12 ccordoba12 Dec 14, 2016

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

@ccordoba12
Copy link
Member

This is great!! The use case we talked about is working now the same as in Sublime

seleccion_002

But there's some work to do for this one:

seleccion_001

In this case, your algorithm is not detecting carlos as the parent of widgets/editor.py and plugins/editor.py.

Please fix it :-)

@ccordoba12 ccordoba12 changed the title PR: Added disambiguation functionality for Editor tabs PR: Add disambiguation functionality for Editor tabs Dec 17, 2016
@ccordoba12
Copy link
Member

ccordoba12 commented Dec 17, 2016

I left one last comment to fix the error reported by pydocstyle, and then I'll merge :-)

@ccordoba12
Copy link
Member

All green now!! Thanks a lot @dalthviz!

This is a great addition :-)

@ccordoba12 ccordoba12 merged commit 1432024 into spyder-ide:3.x Dec 17, 2016
ccordoba12 added a commit that referenced this pull request Dec 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants