-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Improve autocompletion function on file name completion. #4842
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
Conversation
397c4e3
to
0453412
Compare
Hi @skx19952! Thanks for this PR. Could you add a description to the PR to describe what issue this PR fixes? Further, could you add some relevant content to the news file? |
Previous autocomplete function cannot autocomplete file names after options which have file, dir or path as metavar. For example, when typed |
0453412
to
3b1cda0
Compare
3b1cda0
to
e0f4c2b
Compare
Aha! That's an awesome improvement! I don't have the time right now to review this. I'll definitely come around to this soon (feel free to ping me if you want :P) |
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 like this change.
There's a comment about normalisation of paths, one comment about a 2
and a whole bunch of ✨ things I'd like to see. :)
(I'm a little picky when it comes to how things look. 🎨 ones -- you can skip if you want.)
src/pip/_internal/__init__.py
Outdated
:param opts: The available options to check | ||
:return: path completion type(``file``, ``dir``, ``path`` or None) | ||
""" | ||
if cword >= 2 and cwords[cword - 2].startswith('-'): |
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.
A comment here explaining why 2
would be nice.
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.
if cword < 2 or not cwords[cword - 2].startswith('-'):
return
...
It would reduce one level of indentation.
src/pip/_internal/__init__.py
Outdated
:param completion_type: path completion type(`file`, `path` or `dir`)i | ||
:return: A generator of regular files and/or directories | ||
""" | ||
# split ``current`` into two parts(directory and name) |
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.
In general, the single line comments that are present in this function aren't helpful.
tests/functional/test_completion.py
Outdated
(e.g. ``pip install -r``) | ||
""" | ||
res, env = setup_completion( | ||
script, ('pip install -r r'), |
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.
It would be nice if you could pass the arguments as keyword arguments -- it'll be easier to follow what's happening without having open up the definition of the function.
For all the following tests as well...
tests/functional/test_completion.py
Outdated
res, env = setup_completion( | ||
script, ('pip install -r r'), | ||
'3', | ||
data.complete_paths |
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.
🎨 final comma
For all the following tests as well...
tests/lib/__init__.py
Outdated
@@ -112,6 +112,10 @@ def indexes(self): | |||
def reqfiles(self): | |||
return self.root.join("reqfiles") | |||
|
|||
@property | |||
def complete_paths(self): | |||
return self.root.join("completepaths") |
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.
Maybe rename this folder and property to completion_paths
?
@@ -113,14 +114,97 @@ def test_completion_for_default_parameters(script): | |||
|
|||
def test_completion_option_for_command(script): | |||
""" | |||
Test getting completion for ``--`` in command (eg. pip search --) | |||
Test getting completion for ``--`` in command (e.g. ``pip search --``) |
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 change is good but unrelated? But I mean, it doesn't add much noise so it's fine. :P
tests/functional/test_completion.py
Outdated
'3', | ||
data.complete_paths | ||
) | ||
assert 'requirements.txt' in res.stdout,\ |
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.
Using parenthesis around the string allow skipping the trailing \
, which looks nicer. :)
assert 'requirements.txt' in res.stdout, (
"autocomplete function could not complete <file>"
"after options in command"
)
For all the following tests as well...
src/pip/_internal/__init__.py
Outdated
@@ -114,6 +114,14 @@ def autocomplete(): | |||
options = [(x, v) for (x, v) in options if x not in prev_opts] | |||
# filter options by current input | |||
options = [(k, v) for k, v in options if k.startswith(current)] | |||
# get completion type given cwords and available subcommand options | |||
completion_type = get_path_completion_type( | |||
cwords, cword, subcommand.parser.option_list_all) |
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.
🎨 move the )
to the next line with 1 level less indent and add a trailing comma.
tests/functional/test_completion.py
Outdated
('pip install -e ' + os.path.join(data.complete_paths, 'R')), | ||
'3' | ||
) | ||
assert os.path.join(data.complete_paths, 'README.txt') in res.stdout,\ |
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.
Also, assert requirements.txt
shows up, when normalisation of case may allow?
tests/functional/test_completion.py
Outdated
'2', | ||
data.complete_paths | ||
) | ||
assert 'requirements.txt' not in res.stdout,\ |
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.
Also, assert that README.txt
doesn't show up, when normalisation of case might allow?
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've requested changes above -- specifically about normalisation of path and some cleanups.
4fc2297
to
3c0c0e0
Compare
3c0c0e0
to
9b68237
Compare
I have made some changes. :) |
pip uninstall no longer aborts if a package is not installed; instead it prints a warning that the package is not installed and it is skipping the uninstallation of it for this reason.
- Wheel doesn't have a public API - Reword warning about installing into a running interpreter
* Add a global option to disable colors This is a fix for issue pypa#2449 All it does is simply add a global option --no-color Internally it switches ColorizedStreamHandler to StreamHandler if this flag is detected. * Fix lint errors * not sure it makes the code more readable though ... * Fix typo * Choose logging class before assigning * As requested per review * Make the code shorter and easier to follow * Be polite to followers, add commas * Add functional test for the --no-color output * Better detection of windows * Fix fragile tests - can't trust script --quiet * The version found in Travis-CI does not respect this flag It added a prefix line and suffix line found if one does not add the flag --quiet (script from util-linux 2.26.2). As such the out put is: Script started on Fri 27 Oct 2017 07:17:30 AM CEST \x1b[31mCannot uninstall requirement noSuchPackage, not installed\x1b[0m\n Script done on Fri 27 Oct 2017 07:17:31 AM CEST With this change, the test should pass, and is hopefully more stable. * Simplify testing for color or no-color
@kianasun Why close the PR? |
I am sorry. I think I did some wrong operations.. I will reopen it soon... |
Ah, okay. Sure.
Lemme know if you need any kind of help. :)
…On Thu, 29 Mar 2018, 09:38 Kexuan Sun, ***@***.***> wrote:
I am sorry. I think I did some wrong operations.. I will reopen it soon...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4842 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADH7Seju85DswmAKOgkJIJfduY3nXdb9ks5tjF5SgaJpZM4QSjbT>
.
|
Sorry, I think I need to open a new pull request.. @pradyunsg |
Feel free to. :)
…On Thu, 29 Mar 2018, 10:53 Kexuan Sun, ***@***.***> wrote:
Sorry, I think I need to open a new pull request.. @pradyunsg
<https://github.com/pradyunsg>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4842 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADH7SY-2gHV6QOZaXdQHnvAYhbshRIOPks5tjG_MgaJpZM4QSjbT>
.
|
Hi, the new pull request is #5125. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
No description provided.