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:
parent
5c24a798b8
commit
e752b1a26b
1
news/10646.feature.rst
Normal file
1
news/10646.feature.rst
Normal file
|
@ -0,0 +1 @@
|
|||
``pip install <tab>`` autocompletes paths.
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue