Commit aef3d1ec by Sébastien Eustace

Add update command

parent 186a8309
......@@ -8,6 +8,7 @@ from poetry.utils.venv import Venv
from .commands import AboutCommand
from .commands import InstallCommand
from .commands import LockCommand
from .commands import UpdateCommand
class Application(BaseApplication):
......@@ -38,6 +39,7 @@ class Application(BaseApplication):
AboutCommand(),
InstallCommand(),
LockCommand(),
UpdateCommand(),
]
def do_run(self, i, o) -> int:
......
from .about import AboutCommand
from .install import InstallCommand
from .lock import LockCommand
from .update import UpdateCommand
......@@ -31,5 +31,6 @@ exist it will look for <comment>poetry.toml</> and do the same.
)
installer.dev_mode(not self.option('no-dev'))
installer.dry_run(self.option('dry-run'))
return installer.run()
from poetry.installation import Installer
from poetry.repositories.pypi_repository import PyPiRepository
from .command import Command
class UpdateCommand(Command):
"""
Update dependencies as according to the <comment>poetry.toml</> file.
update
{ packages?* : The packages to update. }
{ --f|features=* : Features to install. }
{ --no-dev : Do not install dev dependencies. }
{ --dry-run : Outputs the operations but will not execute anything
(implicitly enables --verbose). }
"""
def handle(self):
installer = Installer(
self.output,
self.poetry.package,
self.poetry.locker,
PyPiRepository()
)
installer.dev_mode(not self.option('no-dev'))
installer.dry_run(self.option('dry-run'))
# Force update
installer.update(True)
return installer.run()
......@@ -98,18 +98,18 @@ class Installer:
def _do_install(self, local_repo):
locked_repository = Repository()
# initialize locked repo if we are installing from lock
if not self._update:
if not self._update or self._locker.is_locked():
locked_repository = self._locker.locked_repository(self._dev_mode)
if self._update:
self._io.writeln('<info>Updating dependencies</>')
solver = Solver(locked_repository, self._io)
request = self._package.requires
if self.is_dev_mode():
request += self._package.dev_requires
if self._update:
self._io.writeln('<info>Updating dependencies</>')
ops = solver.solve(request, self._repository)
else:
self._io.writeln('<info>Installing dependencies from lock file</>')
......@@ -130,7 +130,7 @@ class Installer:
# if they are present in the local repo
# TODO
if ops and self._execute_operations:
if ops and (self._execute_operations or self._dry_run):
installs = []
updates = []
uninstalls = []
......@@ -166,7 +166,6 @@ class Installer:
elif op.job_type == 'update':
local_repo.add_package(op.target_package)
if self._execute_operations:
self._execute(op)
def _execute(self, operation: Operation) -> None:
......@@ -178,15 +177,40 @@ class Installer:
getattr(self, f'_execute_{method}')(operation)
def _execute_install(self, operation: Install) -> None:
self._io.writeln(
f' - Installing <info>{operation.package.name}</> '
f'(<comment>{operation.package.full_pretty_version}</>)'
)
if not self._execute_operations:
return
self._installer.install(operation.package)
def _execute_update(self, operation: Update) -> None:
self._installer.update(
operation.initial_package,
operation.target_package
source = operation.target_package
target = operation.target_package
self._io.writeln(
f' - Updating <info>{target.name}</> '
f'(<comment>{source.pretty_version}</>'
f' -> <comment>{target.pretty_version}</>)'
)
if not self._execute_operations:
return
self._installer.update(source, target)
def _execute_uninstall(self, operation: Uninstall) -> None:
self._io.writeln(
f' - Removing <info>{operation.package.name}</> '
f'(<comment>{operation.package.full_pretty_version}</>)'
)
if not self._execute_operations:
return
self._installer.remove(operation.package)
def _get_operations_from_lock(self,
......
......@@ -8,28 +8,12 @@ class PipInstaller:
self._io = io
def install(self, package):
self._io.writeln(
f' - Installing <info>{package.name}</> '
f'(<comment>{package.full_pretty_version}</>)'
)
self.run('install', self.requirement(package), '--no-deps')
def update(self, source, target):
self._io.writeln(
f' - Updating <info>{target.name}</> '
f'(<comment>{source.pretty_version}</>'
f' -> <comment>{target.pretty_version}</>)'
)
self.run('install', self.requirement(target), '--no-deps', '-U')
def remove(self, package):
self._io.writeln(
f' - Removing <info>{package.name}</> '
f'(<comment>{package.full_pretty_version}</>)'
)
self.run('uninstall', package.name)
def run(self, *args) -> str:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment