Commit aef3d1ec by Sébastien Eustace

Add update command

parent 186a8309
...@@ -8,6 +8,7 @@ from poetry.utils.venv import Venv ...@@ -8,6 +8,7 @@ from poetry.utils.venv import Venv
from .commands import AboutCommand from .commands import AboutCommand
from .commands import InstallCommand from .commands import InstallCommand
from .commands import LockCommand from .commands import LockCommand
from .commands import UpdateCommand
class Application(BaseApplication): class Application(BaseApplication):
...@@ -38,6 +39,7 @@ class Application(BaseApplication): ...@@ -38,6 +39,7 @@ class Application(BaseApplication):
AboutCommand(), AboutCommand(),
InstallCommand(), InstallCommand(),
LockCommand(), LockCommand(),
UpdateCommand(),
] ]
def do_run(self, i, o) -> int: def do_run(self, i, o) -> int:
......
from .about import AboutCommand from .about import AboutCommand
from .install import InstallCommand from .install import InstallCommand
from .lock import LockCommand from .lock import LockCommand
from .update import UpdateCommand
...@@ -31,5 +31,6 @@ exist it will look for <comment>poetry.toml</> and do the same. ...@@ -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.dev_mode(not self.option('no-dev'))
installer.dry_run(self.option('dry-run'))
return installer.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: ...@@ -98,18 +98,18 @@ class Installer:
def _do_install(self, local_repo): def _do_install(self, local_repo):
locked_repository = Repository() locked_repository = Repository()
# initialize locked repo if we are installing from lock # 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) locked_repository = self._locker.locked_repository(self._dev_mode)
if self._update:
self._io.writeln('<info>Updating dependencies</>')
solver = Solver(locked_repository, self._io) solver = Solver(locked_repository, self._io)
request = self._package.requires request = self._package.requires
if self.is_dev_mode(): if self.is_dev_mode():
request += self._package.dev_requires request += self._package.dev_requires
if self._update:
self._io.writeln('<info>Updating dependencies</>')
ops = solver.solve(request, self._repository) ops = solver.solve(request, self._repository)
else: else:
self._io.writeln('<info>Installing dependencies from lock file</>') self._io.writeln('<info>Installing dependencies from lock file</>')
...@@ -130,7 +130,7 @@ class Installer: ...@@ -130,7 +130,7 @@ class Installer:
# if they are present in the local repo # if they are present in the local repo
# TODO # TODO
if ops and self._execute_operations: if ops and (self._execute_operations or self._dry_run):
installs = [] installs = []
updates = [] updates = []
uninstalls = [] uninstalls = []
...@@ -166,7 +166,6 @@ class Installer: ...@@ -166,7 +166,6 @@ class Installer:
elif op.job_type == 'update': elif op.job_type == 'update':
local_repo.add_package(op.target_package) local_repo.add_package(op.target_package)
if self._execute_operations:
self._execute(op) self._execute(op)
def _execute(self, operation: Operation) -> None: def _execute(self, operation: Operation) -> None:
...@@ -178,15 +177,40 @@ class Installer: ...@@ -178,15 +177,40 @@ class Installer:
getattr(self, f'_execute_{method}')(operation) getattr(self, f'_execute_{method}')(operation)
def _execute_install(self, operation: Install) -> None: 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) self._installer.install(operation.package)
def _execute_update(self, operation: Update) -> None: def _execute_update(self, operation: Update) -> None:
self._installer.update( source = operation.target_package
operation.initial_package, target = operation.target_package
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: 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) self._installer.remove(operation.package)
def _get_operations_from_lock(self, def _get_operations_from_lock(self,
......
...@@ -8,28 +8,12 @@ class PipInstaller: ...@@ -8,28 +8,12 @@ class PipInstaller:
self._io = io self._io = io
def install(self, package): 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') self.run('install', self.requirement(package), '--no-deps')
def update(self, source, target): 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') self.run('install', self.requirement(target), '--no-deps', '-U')
def remove(self, package): def remove(self, package):
self._io.writeln(
f' - Removing <info>{package.name}</> '
f'(<comment>{package.full_pretty_version}</>)'
)
self.run('uninstall', package.name) self.run('uninstall', package.name)
def run(self, *args) -> str: 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