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: python-poetry#3028
  • Loading branch information
abn committed Oct 1, 2020
1 parent 7a5f260 commit 60ad8b5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
13 changes: 12 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 @@ -23,4 +31,7 @@ def handle(self):

self._installer.lock()

return self._installer.run()
if self.option("no-update"):
self._installer.refresh_lock_file()
else:
return self._installer.run()
33 changes: 30 additions & 3 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,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 +173,33 @@ def use_executor(self, use_executor=True): # type: (bool) -> Installer

return self

def refresh_lock_file(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 +256,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 60ad8b5

Please sign in to comment.