Skip to content

Commit 1196923

Browse files
authored
Add output for poetry lock --check (#5081)
* Add output for poetry lock --check * Rephrase messages * Add punctuation mark at the end of the message * Update wording for installer and export * Put warning back for installer and export * Finalize warning messages * Improve fix messages
1 parent 31657e7 commit 1196923

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/poetry/console/commands/export.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ def handle(self) -> None:
5959
if not locker.is_fresh():
6060
self.line_error(
6161
"<warning>"
62-
"Warning: The lock file is not up to date with "
63-
"the latest changes in pyproject.toml. "
64-
"You may be getting outdated dependencies. "
65-
"Run update to update them."
62+
"Warning: poetry.lock is not consistent with pyproject.toml. "
63+
"You may be getting improper dependencies. "
64+
"Run `poetry lock [--no-update]` to fix it."
6665
"</warning>"
6766
)
6867

src/poetry/console/commands/lock.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ def handle(self) -> int:
3737
)
3838

3939
if self.option("check"):
40-
return (
41-
0
42-
if self.poetry.locker.is_locked() and self.poetry.locker.is_fresh()
43-
else 1
40+
if self.poetry.locker.is_locked() and self.poetry.locker.is_fresh():
41+
self.line("poetry.lock is consistent with pyproject.toml.")
42+
return 0
43+
self.line(
44+
"<error>"
45+
"Error: poetry.lock is not consistent with pyproject.toml. "
46+
"Run `poetry lock [--no-update]` to fix it."
47+
"</error>"
4448
)
49+
return 1
4550

4651
self._installer.lock(update=not self.option("no-update"))
4752

src/poetry/installation/installer.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,9 @@ def _do_install(self, local_repo: Repository) -> int:
258258
if not self._locker.is_fresh():
259259
self._io.write_line(
260260
"<warning>"
261-
"Warning: The lock file is not up to date with "
262-
"the latest changes in pyproject.toml. "
263-
"You may be getting outdated dependencies. "
264-
"Run update to update them."
261+
"Warning: poetry.lock is not consistent with pyproject.toml. "
262+
"You may be getting improper dependencies. "
263+
"Run `poetry lock [--no-update]` to fix it."
265264
"</warning>"
266265
)
267266

tests/console/commands/test_lock.py

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ def test_lock_check_outdated(
8181

8282
tester = command_tester_factory("lock", poetry=poetry_with_outdated_lockfile)
8383
status_code = tester.execute("--check")
84+
expected = (
85+
"Error: poetry.lock is not consistent with pyproject.toml. "
86+
"Run `poetry lock [--no-update]` to fix it.\n"
87+
)
88+
89+
assert tester.io.fetch_output() == expected
8490

8591
# exit with an error
8692
assert status_code == 1
@@ -101,6 +107,8 @@ def test_lock_check_up_to_date(
101107

102108
tester = command_tester_factory("lock", poetry=poetry_with_up_to_date_lockfile)
103109
status_code = tester.execute("--check")
110+
expected = "poetry.lock is consistent with pyproject.toml.\n"
111+
assert tester.io.fetch_output() == expected
104112

105113
# exit with an error
106114
assert status_code == 0

0 commit comments

Comments
 (0)