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

(🎁) upgrade warning about inconsistent lock file to an error #8737

Merged
merged 3 commits into from
Feb 10, 2024
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
7 changes: 2 additions & 5 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,9 @@ def _do_install(self) -> int:
locked_repository = self._locker.locked_repository()

if not self._locker.is_fresh():
self._io.write_error_line(
"<warning>"
"Warning: poetry.lock is not consistent with pyproject.toml. "
"You may be getting improper dependencies. "
raise ValueError(
"poetry.lock is not consistent with pyproject.toml. "
KotlinIsland marked this conversation as resolved.
Show resolved Hide resolved
"Run `poetry lock [--no-update]` to fix it."
"</warning>"
)

locker_extras = {
Expand Down
21 changes: 20 additions & 1 deletion tests/installation/test_installer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import re

from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -97,6 +98,7 @@ def __init__(self, lock_path: Path) -> None:
self._lock = lock_path / "poetry.lock"
self._written_data = None
self._locked = False
self._fresh = True
self._lock_data = None
self._content_hash = self._get_content_hash()

Expand All @@ -121,8 +123,13 @@ def mock_lock_data(self, data: dict[str, Any]) -> None:
def is_locked(self) -> bool:
return self._locked

def fresh(self, is_fresh: bool = True) -> Locker:
self._fresh = is_fresh

return self

def is_fresh(self) -> bool:
return True
return self._fresh

def _get_content_hash(self) -> str:
return "123456789"
Expand Down Expand Up @@ -208,6 +215,18 @@ def test_run_no_dependencies(installer: Installer, locker: Locker) -> None:
assert locker.written_data == expected


def test_not_fresh_lock(installer: Installer, locker: Locker) -> None:
locker.locked().fresh(False)
with pytest.raises(
ValueError,
match=re.escape(
"poetry.lock is not consistent with pyproject.toml. "
"Run `poetry lock [--no-update]` to fix it."
),
):
installer.run()


def test_run_with_dependencies(
installer: Installer, locker: Locker, repo: Repository, package: ProjectPackage
) -> None:
Expand Down
Loading