Skip to content

Commit 6125b6a

Browse files
committed
Incorporating suggestions
1 parent e0fab00 commit 6125b6a

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

docs/cli.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ poetry check
638638

639639
### Options
640640

641-
* `--lock`: Verify that `poetry.lock` is consistent with `pyproject.toml`.
641+
* `--lock`: Verifies that `poetry.lock` exists for the current `pyproject.toml`.
642642

643643
## search
644644

src/poetry/console/commands/check.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CheckCommand(Command):
1717
"lock",
1818
None,
1919
(
20-
"Check that the <comment>poetry.lock</> file corresponds to the current"
20+
"Checks that <comment>poetry.lock</> exists for the current"
2121
" version of <comment>pyproject.toml</>."
2222
),
2323
),
@@ -74,18 +74,6 @@ def validate_classifiers(
7474
return errors, warnings
7575

7676
def handle(self) -> int:
77-
if self.option("lock"):
78-
if self.poetry.locker.is_locked() and self.poetry.locker.is_fresh():
79-
self.line("poetry.lock is consistent with pyproject.toml.")
80-
return 0
81-
self.line_error(
82-
"<error>"
83-
"Error: poetry.lock is not consistent with pyproject.toml. "
84-
"Run `poetry lock [--no-update]` to fix it."
85-
"</error>"
86-
)
87-
return 1
88-
8977
from poetry.factory import Factory
9078
from poetry.pyproject.toml import PyProjectTOML
9179

@@ -100,6 +88,15 @@ def handle(self) -> int:
10088
check_result["errors"].extend(errors)
10189
check_result["warnings"].extend(warnings)
10290

91+
# Verify that lock file is consistent
92+
if self.option("lock") and not self.poetry.locker.is_locked():
93+
check_result["errors"] += ["poetry.lock was not found."]
94+
if self.poetry.locker.is_locked() and not self.poetry.locker.is_fresh():
95+
check_result["errors"] += [
96+
"poetry.lock is not consistent with pyproject.toml. Run `poetry"
97+
" lock [--no-update]` to fix it."
98+
]
99+
103100
if not check_result["errors"] and not check_result["warnings"]:
104101
self.info("All set!")
105102

tests/console/commands/test_check.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ def test_check_invalid(
7575
new_callable=mocker.PropertyMock,
7676
)
7777

78-
tester.execute()
78+
tester.execute("--lock")
7979

8080
expected = """\
8181
Error: 'description' is a required property
8282
Error: Project name (invalid) is same as one of its dependencies
8383
Error: Unrecognized classifiers: ['Intended Audience :: Clowns'].
84+
Error: poetry.lock was not found.
8485
Warning: A wildcard Python dependency is ambiguous.\
8586
Consider specifying a more explicit one.
8687
Warning: The "pendulum" dependency specifies the "allows-prereleases" property,\
@@ -112,7 +113,7 @@ def test_check_private(
112113
assert tester.io.fetch_output() == expected
113114

114115

115-
def test_lock_check_outdated(
116+
def test_check_lock_outdated(
116117
command_tester_factory: CommandTesterFactory,
117118
poetry_with_outdated_lockfile: Poetry,
118119
http: type[httpretty.httpretty],
@@ -138,7 +139,7 @@ def test_lock_check_outdated(
138139
assert status_code == 1
139140

140141

141-
def test_lock_check_up_to_date(
142+
def test_check_lock_up_to_date(
142143
command_tester_factory: CommandTesterFactory,
143144
poetry_with_up_to_date_lockfile: Poetry,
144145
http: type[httpretty.httpretty],
@@ -153,7 +154,7 @@ def test_lock_check_up_to_date(
153154

154155
tester = command_tester_factory("check", poetry=poetry_with_up_to_date_lockfile)
155156
status_code = tester.execute("--lock")
156-
expected = "poetry.lock is consistent with pyproject.toml.\n"
157+
expected = "All set!\n"
157158
assert tester.io.fetch_output() == expected
158159

159160
# exit with an error

0 commit comments

Comments
 (0)