From 75bec03ace2d7b67adfb75ade13b0481745dd549 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Randy=20D=C3=B6ring?=
<30527984+radoering@users.noreply.github.com>
Date: Thu, 10 Feb 2022 17:52:45 +0100
Subject: [PATCH] Write errors and warnings to stderr (instead of stdout)
---
src/poetry/console/commands/add.py | 3 +--
src/poetry/console/commands/cache/list.py | 2 +-
src/poetry/console/commands/check.py | 4 ++--
src/poetry/console/commands/init.py | 8 ++++----
src/poetry/console/commands/install.py | 6 +++---
src/poetry/console/commands/lock.py | 2 +-
src/poetry/console/commands/remove.py | 3 +--
src/poetry/console/commands/show.py | 2 +-
src/poetry/installation/installer.py | 2 +-
src/poetry/masonry/builders/editable.py | 2 +-
src/poetry/utils/env.py | 4 ++--
tests/console/commands/test_add.py | 5 ++++-
tests/console/commands/test_cache.py | 2 +-
tests/console/commands/test_check.py | 2 +-
tests/console/commands/test_init.py | 2 +-
tests/console/commands/test_lock.py | 2 +-
16 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/src/poetry/console/commands/add.py b/src/poetry/console/commands/add.py
index d0e734a1587..49d960a85d3 100644
--- a/src/poetry/console/commands/add.py
+++ b/src/poetry/console/commands/add.py
@@ -95,11 +95,10 @@ def handle(self) -> int:
packages = self.argument("name")
if self.option("dev"):
- self.line(
+ self.line_error(
"The --dev option is deprecated, "
"use the `--group dev` notation instead."
)
- self.line("")
group = "dev"
else:
group = self.option("group")
diff --git a/src/poetry/console/commands/cache/list.py b/src/poetry/console/commands/cache/list.py
index c9f1dece726..f861b3e0be7 100644
--- a/src/poetry/console/commands/cache/list.py
+++ b/src/poetry/console/commands/cache/list.py
@@ -20,5 +20,5 @@ def handle(self) -> Optional[int]:
self.line(f"{cache.name}>")
return 0
- self.line("No caches found>")
+ self.line_error("No caches found>")
return None
diff --git a/src/poetry/console/commands/check.py b/src/poetry/console/commands/check.py
index 87c8dc2b32f..28d83b7cb89 100644
--- a/src/poetry/console/commands/check.py
+++ b/src/poetry/console/commands/check.py
@@ -23,9 +23,9 @@ def handle(self) -> int:
return 0
for error in check_result["errors"]:
- self.line(f"Error: {error}")
+ self.line_error(f"Error: {error}")
for error in check_result["warnings"]:
- self.line(f"Warning: {error}")
+ self.line_error(f"Warning: {error}")
return 1
diff --git a/src/poetry/console/commands/init.py b/src/poetry/console/commands/init.py
index 5430f4534e6..ecc6a1a8a59 100644
--- a/src/poetry/console/commands/init.py
+++ b/src/poetry/console/commands/init.py
@@ -81,14 +81,14 @@ def handle(self) -> int:
if pyproject.file.exists():
if pyproject.is_poetry_project():
- self.line(
+ self.line_error(
"A pyproject.toml file with a poetry section already"
" exists."
)
return 1
if pyproject.data.get("build-system"):
- self.line(
+ self.line_error(
"A pyproject.toml file with a defined build-system already"
" exists."
)
@@ -235,7 +235,7 @@ def handle(self) -> int:
self.line("")
if not self.confirm("Do you confirm generation?", True):
- self.line("Command aborted")
+ self.line_error("Command aborted")
return 1
@@ -292,7 +292,7 @@ def _determine_requirements(
canonicalized_name = canonicalize_name(constraint["name"])
matches = self._get_pool().search(canonicalized_name)
if not matches:
- self.line("Unable to find package")
+ self.line_error("Unable to find package")
package = False
else:
choices = self._generate_choice_list(matches, canonicalized_name)
diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py
index c150e1bd203..2c71a687341 100644
--- a/src/poetry/console/commands/install.py
+++ b/src/poetry/console/commands/install.py
@@ -110,14 +110,14 @@ def handle(self) -> int:
included_groups = []
only_groups = []
if self.option("no-dev"):
- self.line(
+ self.line_error(
"The `--no-dev>` option is"
" deprecated, use the `--without dev>`"
" notation instead."
)
excluded_groups.append("dev")
elif self.option("dev-only"):
- self.line(
+ self.line_error(
"The `--dev-only>` option is"
" deprecated, use the `--only dev>` notation"
" instead."
@@ -151,7 +151,7 @@ def handle(self) -> int:
with_synchronization = self.option("sync")
if self.option("remove-untracked"):
- self.line(
+ self.line_error(
"The `--remove-untracked>` option is"
" deprecated, use the `--sync>` option"
" instead."
diff --git a/src/poetry/console/commands/lock.py b/src/poetry/console/commands/lock.py
index 0a9f83cfcb7..fd7510370c3 100644
--- a/src/poetry/console/commands/lock.py
+++ b/src/poetry/console/commands/lock.py
@@ -40,7 +40,7 @@ def handle(self) -> int:
if self.poetry.locker.is_locked() and self.poetry.locker.is_fresh():
self.line("poetry.lock is consistent with pyproject.toml.")
return 0
- self.line(
+ self.line_error(
""
"Error: poetry.lock is not consistent with pyproject.toml. "
"Run `poetry lock [--no-update]` to fix it."
diff --git a/src/poetry/console/commands/remove.py b/src/poetry/console/commands/remove.py
index 772ccc99f48..124264a6aff 100644
--- a/src/poetry/console/commands/remove.py
+++ b/src/poetry/console/commands/remove.py
@@ -36,11 +36,10 @@ def handle(self) -> int:
packages = self.argument("packages")
if self.option("dev"):
- self.line(
+ self.line_error(
"The --dev option is deprecated, "
"use the `--group dev` notation instead."
)
- self.line("")
group = "dev"
else:
group = self.option("group")
diff --git a/src/poetry/console/commands/show.py b/src/poetry/console/commands/show.py
index 8d561146ad3..e9fcefec3ce 100644
--- a/src/poetry/console/commands/show.py
+++ b/src/poetry/console/commands/show.py
@@ -98,7 +98,7 @@ def handle(self) -> Optional[int]:
included_groups = []
only_groups = []
if self.option("no-dev"):
- self.line(
+ self.line_error(
"The `--no-dev>` option is"
" deprecated, use the `--without dev>`"
" notation instead."
diff --git a/src/poetry/installation/installer.py b/src/poetry/installation/installer.py
index 781cee08731..2b03db67b20 100644
--- a/src/poetry/installation/installer.py
+++ b/src/poetry/installation/installer.py
@@ -256,7 +256,7 @@ def _do_install(self, local_repo: Repository) -> int:
locked_repository = self._locker.locked_repository(True)
if not self._locker.is_fresh():
- self._io.write_line(
+ self._io.write_error_line(
""
"Warning: poetry.lock is not consistent with pyproject.toml. "
"You may be getting improper dependencies. "
diff --git a/src/poetry/masonry/builders/editable.py b/src/poetry/masonry/builders/editable.py
index a55ddffcf26..12342ba429f 100644
--- a/src/poetry/masonry/builders/editable.py
+++ b/src/poetry/masonry/builders/editable.py
@@ -83,7 +83,7 @@ def _setup_build(self) -> None:
has_setup = setup.exists()
if has_setup:
- self._io.write_line(
+ self._io.write_error_line(
"A setup.py file already exists. Using it."
)
else:
diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py
index 7102a862fd1..7e2218d684e 100644
--- a/src/poetry/utils/env.py
+++ b/src/poetry/utils/env.py
@@ -860,7 +860,7 @@ def create_venv(
self._poetry.package.python_versions, python_patch
)
- io.write_line(
+ io.write_error_line(
f"The currently activated Python version {python_patch} is not"
f" supported by the project ({self._poetry.package.python_versions}).\n"
"Trying to find and use a compatible version. "
@@ -936,7 +936,7 @@ def create_venv(
create_venv = False
if force:
if not env.is_sane():
- io.write_line(
+ io.write_error_line(
f"The virtual environment found in {env.path} seems to"
" be broken."
)
diff --git a/tests/console/commands/test_add.py b/tests/console/commands/test_add.py
index 498bc611ae7..54232ed6aaa 100644
--- a/tests/console/commands/test_add.py
+++ b/tests/console/commands/test_add.py
@@ -857,9 +857,11 @@ def test_add_to_dev_section_deprecated(
tester.execute("cachy --dev")
- expected = """\
+ warning = """\
The --dev option is deprecated, use the `--group dev` notation instead.
+"""
+ expected = """\
Using version ^0.2.0 for cachy
Updating dependencies
@@ -872,6 +874,7 @@ def test_add_to_dev_section_deprecated(
• Installing cachy (0.2.0)
"""
+ assert tester.io.fetch_error() == warning
assert tester.io.fetch_output() == expected
assert tester.command.installer.executor.installations_count == 1
diff --git a/tests/console/commands/test_cache.py b/tests/console/commands/test_cache.py
index e31bbcca425..9bf42286bbb 100644
--- a/tests/console/commands/test_cache.py
+++ b/tests/console/commands/test_cache.py
@@ -68,4 +68,4 @@ def test_cache_list_empty(tester: "CommandTester", repository_cache_dir: "Path")
No caches found
"""
- assert tester.io.fetch_output() == expected
+ assert tester.io.fetch_error() == expected
diff --git a/tests/console/commands/test_check.py b/tests/console/commands/test_check.py
index efe1a45cec4..d59e26011b4 100644
--- a/tests/console/commands/test_check.py
+++ b/tests/console/commands/test_check.py
@@ -45,4 +45,4 @@ def test_check_invalid(mocker: "MockerFixture", tester: "CommandTester"):
which is deprecated. Use "allow-prereleases" instead.
"""
- assert tester.io.fetch_output() == expected
+ assert tester.io.fetch_error() == expected
diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py
index 76429f0c794..4e11f393a29 100644
--- a/tests/console/commands/test_init.py
+++ b/tests/console/commands/test_init.py
@@ -811,7 +811,7 @@ def test_init_existing_pyproject_with_build_system_fails(
pyproject_file.write_text(decode(existing_section))
tester.execute(inputs=init_basic_inputs)
assert (
- tester.io.fetch_output().strip()
+ tester.io.fetch_error().strip()
== "A pyproject.toml file with a defined build-system already exists."
)
assert existing_section in pyproject_file.read_text()
diff --git a/tests/console/commands/test_lock.py b/tests/console/commands/test_lock.py
index 7bcf708de07..e7a49b64bc5 100644
--- a/tests/console/commands/test_lock.py
+++ b/tests/console/commands/test_lock.py
@@ -86,7 +86,7 @@ def test_lock_check_outdated(
"Run `poetry lock [--no-update]` to fix it.\n"
)
- assert tester.io.fetch_output() == expected
+ assert tester.io.fetch_error() == expected
# exit with an error
assert status_code == 1