Skip to content

Commit

Permalink
lock: allow for no-update refresh of lock files
Browse files Browse the repository at this point in the history
Relates-to: #3028
  • Loading branch information
abn committed Oct 1, 2020
1 parent 7a5f260 commit 4e95465
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
10 changes: 9 additions & 1 deletion poetry/console/commands/lock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from cleo import option

from .installer_command import InstallerCommand


Expand All @@ -6,6 +8,12 @@ class LockCommand(InstallerCommand):
name = "lock"
description = "Locks the project dependencies."

options = [
option(
"no-update", None, "Do not update locked versions, only refresh lock file."
),
]

help = """
The <info>lock</info> command reads the <comment>pyproject.toml</> file from the
current directory, processes it, and locks the dependencies in the <comment>poetry.lock</>
Expand All @@ -21,6 +29,6 @@ def handle(self):
self.poetry.config.get("experimental.new-installer", False)
)

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

return self._installer.run()
37 changes: 34 additions & 3 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def set_locker(self, locker): # type: (Locker) -> Installer
return self

def run(self):
# Check if refresh
if not self._update and self._lock and self._locker.is_locked():
self._do_refresh()

# Force update if there is no lock file present
if not self._update and not self._locker.is_locked():
self._update = True
Expand Down Expand Up @@ -137,11 +141,11 @@ def update(self, update=True): # type: (bool) -> Installer

return self

def lock(self): # type: () -> Installer
def lock(self, update=True): # type: (bool) -> Installer
"""
Prepare the installer for locking only.
"""
self.update()
self.update(update=update)
self.execute_operations(False)
self._lock = True

Expand Down Expand Up @@ -173,6 +177,33 @@ def use_executor(self, use_executor=True): # type: (bool) -> Installer

return self

def _do_refresh(self):
from poetry.puzzle import Solver

locked_repository = self._locker.locked_repository(True)

# Checking extras
for extra in self._extras:
if extra not in self._package.extras:
raise ValueError("Extra [{}] is not specified.".format(extra))

solver = Solver(
self._package,
self._pool,
self._installed_repository,
locked_repository,
self._io,
remove_untracked=self._remove_untracked,
)

ops = solver.solve(use_latest=[])

local_repo = Repository()
self._populate_local_repo(local_repo, ops)

if self._update or self._lock:
self._write_lock_file(local_repo)

def _do_install(self, local_repo):
from poetry.puzzle import Solver

Expand Down Expand Up @@ -229,7 +260,7 @@ def _do_install(self, local_repo):

self._populate_local_repo(local_repo, ops)

if self._update:
if self._update or self._lock:
self._write_lock_file(local_repo)

if self._lock:
Expand Down

0 comments on commit 4e95465

Please sign in to comment.