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

Write errors and warnings to stderr (instead of stdout) #5179

Merged
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
3 changes: 1 addition & 2 deletions src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ def handle(self) -> int:

packages = self.argument("name")
if self.option("dev"):
self.line(
self.line_error(
"<warning>The --dev option is deprecated, "
"use the `--group dev` notation instead.</warning>"
)
self.line("")
group = "dev"
else:
group = self.option("group")
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/cache/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def handle(self) -> Optional[int]:
self.line(f"<info>{cache.name}</>")
return 0

self.line("<warning>No caches found</>")
self.line_error("<warning>No caches found</>")
return None
4 changes: 2 additions & 2 deletions src/poetry/console/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def handle(self) -> int:
return 0

for error in check_result["errors"]:
self.line(f"<error>Error: {error}</error>")
self.line_error(f"<error>Error: {error}</error>")

for error in check_result["warnings"]:
self.line(f"<warning>Warning: {error}</warning>")
self.line_error(f"<warning>Warning: {error}</warning>")

return 1
8 changes: 4 additions & 4 deletions src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def handle(self) -> int:

if pyproject.file.exists():
if pyproject.is_poetry_project():
self.line(
self.line_error(
"<error>A pyproject.toml file with a poetry section already"
" exists.</error>"
)
return 1

if pyproject.data.get("build-system"):
self.line(
self.line_error(
"<error>A pyproject.toml file with a defined build-system already"
" exists.</error>"
)
Expand Down Expand Up @@ -235,7 +235,7 @@ def handle(self) -> int:
self.line("")

if not self.confirm("Do you confirm generation?", True):
self.line("<error>Command aborted</error>")
self.line_error("<error>Command aborted</error>")

return 1

Expand Down Expand Up @@ -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("<error>Unable to find package</error>")
self.line_error("<error>Unable to find package</error>")
package = False
else:
choices = self._generate_choice_list(matches, canonicalized_name)
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def handle(self) -> int:
included_groups = []
only_groups = []
if self.option("no-dev"):
self.line(
self.line_error(
"<warning>The `<fg=yellow;options=bold>--no-dev</>` option is"
" deprecated, use the `<fg=yellow;options=bold>--without dev</>`"
" notation instead.</warning>"
)
excluded_groups.append("dev")
elif self.option("dev-only"):
self.line(
self.line_error(
"<warning>The `<fg=yellow;options=bold>--dev-only</>` option is"
" deprecated, use the `<fg=yellow;options=bold>--only dev</>` notation"
" instead.</warning>"
Expand Down Expand Up @@ -151,7 +151,7 @@ def handle(self) -> int:

with_synchronization = self.option("sync")
if self.option("remove-untracked"):
self.line(
self.line_error(
"<warning>The `<fg=yellow;options=bold>--remove-untracked</>` option is"
" deprecated, use the `<fg=yellow;options=bold>--sync</>` option"
" instead.</warning>"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
"Error: poetry.lock is not consistent with pyproject.toml. "
"Run `poetry lock [--no-update]` to fix it."
Expand Down
3 changes: 1 addition & 2 deletions src/poetry/console/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ def handle(self) -> int:
packages = self.argument("packages")

if self.option("dev"):
self.line(
self.line_error(
"<warning>The --dev option is deprecated, "
"use the `--group dev` notation instead.</warning>"
)
self.line("")
group = "dev"
else:
group = self.option("group")
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def handle(self) -> Optional[int]:
included_groups = []
only_groups = []
if self.option("no-dev"):
self.line(
self.line_error(
"<warning>The `<fg=yellow;options=bold>--no-dev</>` option is"
" deprecated, use the `<fg=yellow;options=bold>--without dev</>`"
" notation instead.</warning>"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
"Warning: poetry.lock is not consistent with pyproject.toml. "
"You may be getting improper dependencies. "
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/masonry/builders/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"<warning>A setup.py file already exists. Using it.</warning>"
)
else:
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ def create_venv(
self._poetry.package.python_versions, python_patch
)

io.write_line(
io.write_error_line(
f"<warning>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.</warning> "
Expand Down Expand Up @@ -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"<warning>The virtual environment found in {env.path} seems to"
" be broken.</warning>"
)
Expand Down
5 changes: 4 additions & 1 deletion tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/console/commands/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/console/commands/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/console/commands/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down