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

Fix the lock content hash not being updated with the add/remove commands #2710

Merged
merged 1 commit into from
Jul 24, 2020
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
9 changes: 8 additions & 1 deletion poetry/console/commands/installer_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@

if TYPE_CHECKING:
from poetry.installation.installer import Installer
from poetry.installation.installer import Optional


class InstallerCommand(EnvCommand):
def __init__(self):
self._installer = None
self._installer = None # type: Optional[Installer]

super(InstallerCommand, self).__init__()

def reset_poetry(self):
super(InstallerCommand, self).reset_poetry()

self._installer.set_package(self.poetry.package)
self._installer.set_locker(self.poetry.locker)

@property
def installer(self): # type: () -> Installer
return self._installer
Expand Down
1 change: 0 additions & 1 deletion poetry/console/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def handle(self):
# Update packages
self.reset_poetry()

self._installer.set_package(self.poetry.package)
self._installer.use_executor(
self.poetry.config.get("experimental.new-installer", False)
)
Expand Down
5 changes: 5 additions & 0 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def set_package(self, package): # type: (ProjectPackage) -> Installer

return self

def set_locker(self, locker): # type: (Locker) -> Installer
self._locker = locker

return self

def run(self):
# Force update if there is no lock file present
if not self._update and not self._locker.is_locked():
Expand Down
2 changes: 2 additions & 0 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ def test_add_prefers_stable_releases(app, repo, tester):


def test_add_with_lock(app, repo, tester):
content_hash = app.poetry.locker._get_content_hash()
repo.add_package(get_package("cachy", "0.2.0"))

tester.execute("cachy --lock")
Expand All @@ -806,6 +807,7 @@ def test_add_with_lock(app, repo, tester):
"""

assert expected == tester.io.fetch_output()
assert content_hash != app.poetry.locker.lock_data["metadata"]["content-hash"]


def test_add_no_constraint_old_installer(app, repo, installer, old_tester):
Expand Down
6 changes: 4 additions & 2 deletions tests/console/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def reset_poetry(self):
self._poetry = Factory().create_poetry(self._poetry.file.path.parent)
self._poetry.set_pool(poetry.pool)
self._poetry.set_config(poetry.config)
self._poetry.set_locker(poetry.locker)
self._poetry.set_locker(
Locker(poetry.locker.lock.path, self._poetry.local_config)
)


class Locker(BaseLocker):
Expand Down Expand Up @@ -163,7 +165,7 @@ def _write_lock_data(self, data):
self._locked = True
return

self._lock_data = None
self._lock_data = data


class Poetry(BasePoetry):
Expand Down