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

Pass --no-input #1029

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ repos:
rev: v1.1.1
hooks:
- id: mypy
args: ['--ignore-missing-imports', '--strict-equality','--no-implicit-optional']
args: ['--warn-unused-ignores', '--strict-equality','--no-implicit-optional']
exclude: 'testdata/test_package_specifier/local_extras/setup.py'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [docs] Add more examples for `pipx run`
- [docs] Add subsection to make README easier to read
- Add `pipx install --preinstall` to support preinstalling build requirements
- Pass `--no-input` to pip when output is not piped to parent stdout

## 1.2.0

Expand Down
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
MAN_DEPENDENCIES = [".", "argparse-manpage[setuptools]"]
LINT_DEPENDENCIES = [
"black==22.8.0",
"mypy==0.930",
"mypy==1.1.1",
"packaging>=20.0",
"ruff==0.0.254",
"types-jinja2",
Expand Down Expand Up @@ -103,7 +103,7 @@ def tests_with_options(session, net_pypiserver):
if net_pypiserver:
pypiserver_option = ["--net-pypiserver"]
else:
session.install("pypiserver")
session.install("pypiserver[passlib]")
refresh_packages_cache(session)
pypiserver_option = []

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ max-complexity = 15

[tool.pytest.ini_options]
markers = ["all_packages: test install with maximum number of packages"]

[[tool.mypy.overrides]]
module = [
"packaging.*",
"platformdirs"
]
ignore_missing_imports = true
8 changes: 5 additions & 3 deletions src/pipx/animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ def print_animation(
# for Windows pre-ANSI-terminal-support (before Windows 10 TH2 (v1511))
# https://stackoverflow.com/a/10455937
def win_cursor(visible: bool) -> None:
if sys.platform != "win32": # hello mypy
return
ci = _CursorInfo()
handle = ctypes.windll.kernel32.GetStdHandle(-11) # type: ignore[attr-defined]
ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci)) # type: ignore[attr-defined]
handle = ctypes.windll.kernel32.GetStdHandle(-11)
ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci))
ci.visible = visible
ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci)) # type: ignore[attr-defined]
ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci))


def hide_cursor() -> None:
Expand Down
1 change: 1 addition & 0 deletions src/pipx/shared_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def upgrade(
self.python_path,
"-m",
"pip",
"--no-input",
"--disable-pip-version-check",
"install",
*_pip_args,
Expand Down
40 changes: 27 additions & 13 deletions src/pipx/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,15 @@ def install_package(
):
# do not use -q with `pip install` so subprocess_post_check_pip_errors
# has more information to analyze in case of failure.
cmd = (
[str(self.python_path), "-m", "pip", "install"]
+ pip_args
+ [package_or_url]
)
cmd = [
str(self.python_path),
"-m",
"pip",
"--no-input",
"install",
*pip_args,
package_or_url,
]
# no logging because any errors will be specially logged by
# subprocess_post_check_handle_pip_error()
pip_process = run_subprocess(cmd, log_stdout=False, log_stderr=False)
Expand Down Expand Up @@ -284,11 +288,15 @@ def install_unmanaged_packages(
with animate(f"installing {', '.join(requirements)}", self.do_animation):
# do not use -q with `pip install` so subprocess_post_check_pip_errors
# has more information to analyze in case of failure.
cmd = (
[str(self.python_path), "-m", "pip", "install"]
+ pip_args
+ requirements
)
cmd = [
str(self.python_path),
"-m",
"pip",
"--no-input",
"install",
*pip_args,
*requirements,
]
# no logging because any errors will be specially logged by
# subprocess_post_check_handle_pip_error()
pip_process = run_subprocess(cmd, log_stdout=False, log_stderr=False)
Expand All @@ -301,7 +309,13 @@ def install_package_no_deps(self, package_or_url: str, pip_args: List[str]) -> s
f"determining package name from {package_or_url!r}", self.do_animation
):
old_package_set = self.list_installed_packages()
cmd = ["install"] + ["--no-dependencies"] + pip_args + [package_or_url]
cmd = [
"--no-input",
"install",
"--no-dependencies",
*pip_args,
package_or_url,
]
pip_process = self._run_pip(cmd)
subprocess_post_check(pip_process, raise_error=False)
if pip_process.returncode:
Expand Down Expand Up @@ -429,7 +443,7 @@ def upgrade_package_no_metadata(
self.do_animation,
):
pip_process = self._run_pip(
["install"] + pip_args + ["--upgrade", package_name]
["--no-input", "install"] + pip_args + ["--upgrade", package_name]
)
subprocess_post_check(pip_process)

Expand All @@ -448,7 +462,7 @@ def upgrade_package(
self.do_animation,
):
pip_process = self._run_pip(
["install"] + pip_args + ["--upgrade", package_or_url]
["--no-input", "install"] + pip_args + ["--upgrade", package_or_url]
)
subprocess_post_check(pip_process)

Expand Down
26 changes: 23 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest # type: ignore

from helpers import WIN
from pipx import commands, constants, shared_libs, venv
from pipx import commands, constants, interpreter, shared_libs, venv

PIPX_TESTS_DIR = Path(".pipx_tests")
PIPX_TESTS_PACKAGE_LIST_DIR = Path("testdata/tests_packages")
Expand Down Expand Up @@ -57,6 +57,11 @@ def pipx_temp_env_helper(
monkeypatch.setattr(constants, "PIPX_VENV_CACHEDIR", home_dir / ".cache")
monkeypatch.setattr(constants, "PIPX_LOG_DIR", home_dir / "logs")

monkeypatch.setattr(interpreter, "DEFAULT_PYTHON", sys.executable)

if "PIPX_DEFAULT_PYTHON" in os.environ:
monkeypatch.delenv("PIPX_DEFAULT_PYTHON")

# macOS needs /usr/bin in PATH to compile certain packages, but
# applications in /usr/bin cause test_install.py tests to raise warnings
# which make tests fail (e.g. on Github ansible apps exist in /usr/bin)
Expand All @@ -74,7 +79,9 @@ def pipx_temp_env_helper(
# IMPORTANT: use 127.0.0.1 not localhost
# Using localhost on Windows creates enormous slowdowns
# (for some reason--perhaps IPV6/IPV4 tries, timeouts?)
monkeypatch.setenv("PIP_INDEX_URL", "http://127.0.0.1:8080/simple")
monkeypatch.setenv(
"PIP_INDEX_URL", "http://username:[email protected]:8080/simple"
)


@pytest.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -114,10 +121,23 @@ def pipx_local_pypiserver(request):
with open(
request.config.invocation_params.dir / PIPX_TESTS_DIR / "pypiserver.log", "w"
) as pypiserver_err_fh:
pypiserver_htpasswd = str(
request.config.invocation_params.dir / PIPX_TESTS_DIR / "htpasswd"
)

from passlib.apache import HtpasswdFile # type: ignore

ht = HtpasswdFile(pypiserver_htpasswd, new=True)
ht.set_password("username", "password")
ht.save()

pypiserver_process = subprocess.Popen(
[
"pypi-server",
"--authenticate=update",
"run",
"--verbose",
"--authenticate=update,download,list",
f"--passwords={pypiserver_htpasswd}",
"--disable-fallback",
str(pipx_cache_dir / f"{sys.version_info[0]}.{sys.version_info[1]}"),
],
Expand Down
6 changes: 6 additions & 0 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,9 @@ def test_force_install_changes(pipx_temp_env, capsys):
def test_preinstall(pipx_temp_env, caplog):
assert not run_pipx_cli(["install", "--preinstall", "black", "nox"])
assert "black" in caplog.text


@pytest.mark.xfail
def test_do_not_wait_for_input(pipx_temp_env, pipx_session_shared_dir, monkeypatch):
monkeypatch.setenv("PIP_INDEX_URL", "http://127.0.0.1:8080/simple")
run_pipx_cli(["install", "pycowsay"])