1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Include files/folders in pip install autocomplete (#10682)

This commit is contained in:
Andy Freeland 2022-01-25 10:27:09 -08:00 committed by GitHub
parent 5c24a798b8
commit e752b1a26b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

1
news/10646.feature.rst Normal file
View file

@ -0,0 +1 @@
``pip install <tab>`` autocompletes paths.

View file

@ -59,6 +59,14 @@ def autocomplete() -> None:
print(dist)
sys.exit(1)
should_list_installables = (
not current.startswith("-") and subcommand_name == "install"
)
if should_list_installables:
for path in auto_complete_paths(current, "path"):
print(path)
sys.exit(1)
subcommand = create_command(subcommand_name)
for opt in subcommand.parser.option_list_all:
@ -138,7 +146,7 @@ def auto_complete_paths(current: str, completion_type: str) -> Iterable[str]:
starting with ``current``.
:param current: The word to be completed
:param completion_type: path completion type(`file`, `path` or `dir`)i
:param completion_type: path completion type(``file``, ``path`` or ``dir``)
:return: A generator of regular files and/or directories
"""
directory, filename = os.path.split(current)

View file

@ -237,10 +237,10 @@ def test_completion_not_files_after_option(
) -> None:
"""
Test not getting completion files after options which not applicable
(e.g. ``pip install``)
(e.g. ``pip wheel``)
"""
res, env = autocomplete(
words=("pip install r"),
words=("pip wheel r"),
cword="2",
cwd=data.completion_paths,
)
@ -256,6 +256,24 @@ def test_completion_not_files_after_option(
), "autocomplete function completed <dir> when it should not complete"
def test_pip_install_complete_files(
autocomplete: DoAutocomplete, data: TestData
) -> None:
"""``pip install`` autocompletes wheel and sdist files."""
res, env = autocomplete(
words=("pip install r"),
cword="2",
cwd=data.completion_paths,
)
assert all(
out in res.stdout
for out in (
"requirements.txt",
"resources",
)
), "autocomplete function could not complete <path>"
@pytest.mark.parametrize("cl_opts", ["-U", "--user", "-h"])
def test_completion_not_files_after_nonexpecting_option(
autocomplete: DoAutocomplete, data: TestData, cl_opts: str