Skip to content

Commit

Permalink
Add output for poetry lock --check (#5081)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
artemrys authored Feb 9, 2022
1 parent 31657e7 commit 1196923
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/poetry/console/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ def handle(self) -> None:
if not locker.is_fresh():
self.line_error(
"<warning>"
"Warning: The lock file is not up to date with "
"the latest changes in pyproject.toml. "
"You may be getting outdated dependencies. "
"Run update to update them."
"Warning: poetry.lock is not consistent with pyproject.toml. "
"You may be getting improper dependencies. "
"Run `poetry lock [--no-update]` to fix it."
"</warning>"
)

Expand Down
13 changes: 9 additions & 4 deletions src/poetry/console/commands/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ def handle(self) -> int:
)

if self.option("check"):
return (
0
if self.poetry.locker.is_locked() and self.poetry.locker.is_fresh()
else 1
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(
"<error>"
"Error: poetry.lock is not consistent with pyproject.toml. "
"Run `poetry lock [--no-update]` to fix it."
"</error>"
)
return 1

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

Expand Down
7 changes: 3 additions & 4 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ def _do_install(self, local_repo: Repository) -> int:
if not self._locker.is_fresh():
self._io.write_line(
"<warning>"
"Warning: The lock file is not up to date with "
"the latest changes in pyproject.toml. "
"You may be getting outdated dependencies. "
"Run update to update them."
"Warning: poetry.lock is not consistent with pyproject.toml. "
"You may be getting improper dependencies. "
"Run `poetry lock [--no-update]` to fix it."
"</warning>"
)

Expand Down
8 changes: 8 additions & 0 deletions tests/console/commands/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def test_lock_check_outdated(

tester = command_tester_factory("lock", poetry=poetry_with_outdated_lockfile)
status_code = tester.execute("--check")
expected = (
"Error: poetry.lock is not consistent with pyproject.toml. "
"Run `poetry lock [--no-update]` to fix it.\n"
)

assert tester.io.fetch_output() == expected

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

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

# exit with an error
assert status_code == 0
Expand Down

0 comments on commit 1196923

Please sign in to comment.