Skip to content

Commit

Permalink
upgrade extremely useful (and easy to miss) warning to an error
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Dec 13, 2023
1 parent f310a59 commit 39c1249
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
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. "
"Run `poetry lock [--no-update]` to fix it."
"</warning>"
)

locker_extras = {
Expand Down
22 changes: 21 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,19 @@ 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(

Check failure on line 220 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.10

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

Check failure on line 220 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.11

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

Check failure on line 220 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.12

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

Check failure on line 220 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / macOS / 3.10

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

Check failure on line 220 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / macOS / 3.11

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

Check failure on line 220 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / macOS / 3.12

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'
ValueError,
match=re.escape(
"poetry.lock is not consistent with pyproject.toml. You may"
" be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
" it."
),
):
installer.run()

Check failure on line 228 in tests/installation/test_installer.py

View check run for this annotation

Cirrus CI / Tests / FreeBSD / PYTHON:python3.8

tests/installation/test_installer.py#L228

tests.installation.test_installer.test_not_fresh_lock
Raw output
installer = <poetry.installation.installer.Installer object at 0x8077ece20>
locker = <tests.installation.test_installer.Locker object at 0x807e80d00>

    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. You may"
                " be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
                " it."
            ),
        ):
>           installer.run()

tests/installation/test_installer.py:228: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/poetry/installation/installer.py:104: in run
    return self._do_install()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <poetry.installation.installer.Installer object at 0x8077ece20>

    def _do_install(self) -> int:
        from poetry.puzzle.solver import Solver
    
        locked_repository = Repository("poetry-locked")
        if self._update:
            if not self._lock and self._locker.is_locked():
                locked_repository = self._locker.locked_repository()
    
                # If no packages have been whitelisted (The ones we want to update),
                # we whitelist every package in the lock file.
                if not self._whitelist:
                    for pkg in locked_repository.packages:
                        self._whitelist.append(pkg.name)
    
            # Checking extras
            for extra in self._extras:
                if extra not in self._package.extras:
                    raise ValueError(f"Extra [{extra}] is not specified.")
    
            self._io.write_line("<info>Updating dependencies</>")
            solver = Solver(
                self._package,
                self._pool,
                self._installed_repository.packages,
                locked_repository.packages,
                self._io,
            )
    
            with solver.provider.use_source_root(
                source_root=self._env.path.joinpath("src")
            ):
                ops = solver.solve(use_latest=self._whitelist).calculate_operations()
        else:
            self._io.write_line("<info>Installing dependencies from lock file</>")
    
            locked_repository = self._locker.locked_repository()
    
            if not self._locker.is_fresh():
>               raise ValueError(
                    "poetry.lock is not consistent with pyproject.toml. "
                    "Run `poetry lock [--no-update]` to fix it."
                )
E               ValueError: poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.

src/poetry/installation/installer.py:248: ValueError

During handling of the above exception, another exception occurred:

installer = <poetry.installation.installer.Installer object at 0x8077ece20>
locker = <tests.installation.test_installer.Locker object at 0x807e80d00>

    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. You may"
                " be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
                " it."
            ),
        ):
>           installer.run()
E           AssertionError: Regex pattern did not match.
E            Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.'
E            Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

tests/installation/test_installer.py:228: AssertionError

Check failure on line 228 in tests/installation/test_installer.py

View check run for this annotation

Cirrus CI / Tests / FreeBSD / PYTHON:python3.10

tests/installation/test_installer.py#L228

tests.installation.test_installer.test_not_fresh_lock
Raw output
installer = <poetry.installation.installer.Installer object at 0x80805c070>
locker = <tests.installation.test_installer.Locker object at 0x806bbfdc0>

    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. You may"
                " be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
                " it."
            ),
        ):
>           installer.run()

tests/installation/test_installer.py:228: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/poetry/installation/installer.py:104: in run
    return self._do_install()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <poetry.installation.installer.Installer object at 0x80805c070>

    def _do_install(self) -> int:
        from poetry.puzzle.solver import Solver
    
        locked_repository = Repository("poetry-locked")
        if self._update:
            if not self._lock and self._locker.is_locked():
                locked_repository = self._locker.locked_repository()
    
                # If no packages have been whitelisted (The ones we want to update),
                # we whitelist every package in the lock file.
                if not self._whitelist:
                    for pkg in locked_repository.packages:
                        self._whitelist.append(pkg.name)
    
            # Checking extras
            for extra in self._extras:
                if extra not in self._package.extras:
                    raise ValueError(f"Extra [{extra}] is not specified.")
    
            self._io.write_line("<info>Updating dependencies</>")
            solver = Solver(
                self._package,
                self._pool,
                self._installed_repository.packages,
                locked_repository.packages,
                self._io,
            )
    
            with solver.provider.use_source_root(
                source_root=self._env.path.joinpath("src")
            ):
                ops = solver.solve(use_latest=self._whitelist).calculate_operations()
        else:
            self._io.write_line("<info>Installing dependencies from lock file</>")
    
            locked_repository = self._locker.locked_repository()
    
            if not self._locker.is_fresh():
>               raise ValueError(
                    "poetry.lock is not consistent with pyproject.toml. "
                    "Run `poetry lock [--no-update]` to fix it."
                )
E               ValueError: poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.

src/poetry/installation/installer.py:248: ValueError

During handling of the above exception, another exception occurred:

installer = <poetry.installation.installer.Installer object at 0x80805c070>
locker = <tests.installation.test_installer.Locker object at 0x806bbfdc0>

    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. You may"
                " be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
                " it."
            ),
        ):
E       AssertionError: Regex pattern did not match.
E        Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.'
E        Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

tests/installation/test_installer.py:220: AssertionError

Check failure on line 228 in tests/installation/test_installer.py

View check run for this annotation

Cirrus CI / Tests / FreeBSD / PYTHON:python3.11

tests/installation/test_installer.py#L228

tests.installation.test_installer.test_not_fresh_lock
Raw output
installer = <poetry.installation.installer.Installer object at 0x8093d4b90>
locker = <tests.installation.test_installer.Locker object at 0x80519b450>

    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. You may"
                " be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
                " it."
            ),
        ):
>           installer.run()

tests/installation/test_installer.py:228: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/poetry/installation/installer.py:104: in run
    return self._do_install()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <poetry.installation.installer.Installer object at 0x8093d4b90>

    def _do_install(self) -> int:
        from poetry.puzzle.solver import Solver
    
        locked_repository = Repository("poetry-locked")
        if self._update:
            if not self._lock and self._locker.is_locked():
                locked_repository = self._locker.locked_repository()
    
                # If no packages have been whitelisted (The ones we want to update),
                # we whitelist every package in the lock file.
                if not self._whitelist:
                    for pkg in locked_repository.packages:
                        self._whitelist.append(pkg.name)
    
            # Checking extras
            for extra in self._extras:
                if extra not in self._package.extras:
                    raise ValueError(f"Extra [{extra}] is not specified.")
    
            self._io.write_line("<info>Updating dependencies</>")
            solver = Solver(
                self._package,
                self._pool,
                self._installed_repository.packages,
                locked_repository.packages,
                self._io,
            )
    
            with solver.provider.use_source_root(
                source_root=self._env.path.joinpath("src")
            ):
                ops = solver.solve(use_latest=self._whitelist).calculate_operations()
        else:
            self._io.write_line("<info>Installing dependencies from lock file</>")
    
            locked_repository = self._locker.locked_repository()
    
            if not self._locker.is_fresh():
>               raise ValueError(
                    "poetry.lock is not consistent with pyproject.toml. "
                    "Run `poetry lock [--no-update]` to fix it."
                )
E               ValueError: poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.

src/poetry/installation/installer.py:248: ValueError

During handling of the above exception, another exception occurred:

installer = <poetry.installation.installer.Installer object at 0x8093d4b90>
locker = <tests.installation.test_installer.Locker object at 0x80519b450>

    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. You may"
                " be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
                " it."
            ),
        ):
E       AssertionError: Regex pattern did not match.
E        Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.'
E        Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

tests/installation/test_installer.py:220: AssertionError

Check failure on line 228 in tests/installation/test_installer.py

View check run for this annotation

Cirrus CI / Tests / FreeBSD / PYTHON:python3.9

tests/installation/test_installer.py#L228

tests.installation.test_installer.test_not_fresh_lock
Raw output
installer = <poetry.installation.installer.Installer object at 0x806315490>
locker = <tests.installation.test_installer.Locker object at 0x806358c10>

    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. You may"
                " be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
                " it."
            ),
        ):
>           installer.run()

tests/installation/test_installer.py:228: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/poetry/installation/installer.py:104: in run
    return self._do_install()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <poetry.installation.installer.Installer object at 0x806315490>

    def _do_install(self) -> int:
        from poetry.puzzle.solver import Solver
    
        locked_repository = Repository("poetry-locked")
        if self._update:
            if not self._lock and self._locker.is_locked():
                locked_repository = self._locker.locked_repository()
    
                # If no packages have been whitelisted (The ones we want to update),
                # we whitelist every package in the lock file.
                if not self._whitelist:
                    for pkg in locked_repository.packages:
                        self._whitelist.append(pkg.name)
    
            # Checking extras
            for extra in self._extras:
                if extra not in self._package.extras:
                    raise ValueError(f"Extra [{extra}] is not specified.")
    
            self._io.write_line("<info>Updating dependencies</>")
            solver = Solver(
                self._package,
                self._pool,
                self._installed_repository.packages,
                locked_repository.packages,
                self._io,
            )
    
            with solver.provider.use_source_root(
                source_root=self._env.path.joinpath("src")
            ):
                ops = solver.solve(use_latest=self._whitelist).calculate_operations()
        else:
            self._io.write_line("<info>Installing dependencies from lock file</>")
    
            locked_repository = self._locker.locked_repository()
    
            if not self._locker.is_fresh():
>               raise ValueError(
                    "poetry.lock is not consistent with pyproject.toml. "
                    "Run `poetry lock [--no-update]` to fix it."
                )
E               ValueError: poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.

src/poetry/installation/installer.py:248: ValueError

During handling of the above exception, another exception occurred:

installer = <poetry.installation.installer.Installer object at 0x806315490>
locker = <tests.installation.test_installer.Locker object at 0x806358c10>

    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. You may"
                " be getting improper dependencies. Run `poetry lock [--no-update]` to fix"
                " it."
            ),
        ):
>           installer.run()
E           AssertionError: Regex pattern did not match.
E            Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.'
E            Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

tests/installation/test_installer.py:228: AssertionError

Check failure on line 228 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.8

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

Check failure on line 228 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.9

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

Check failure on line 228 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / macOS / 3.8

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'

Check failure on line 228 in tests/installation/test_installer.py

View workflow job for this annotation

GitHub Actions / macOS / 3.9

test_not_fresh_lock AssertionError: Regex pattern did not match. Regex: 'poetry\\.lock\\ is\\ not\\ consistent\\ with\\ pyproject\\.toml\\.\\ You\\ may\\ be\\ getting\\ improper\\ dependencies\\.\\ Run\\ `poetry\\ lock\\ \\[\\-\\-no\\-update\\]`\\ to\\ fix\\ it\\.' Input: 'poetry.lock is not consistent with pyproject.toml. Run `poetry lock [--no-update]` to fix it.'


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

0 comments on commit 39c1249

Please sign in to comment.