Unverified Commit 186a8309 authored by Sébastien Eustace's avatar Sébastien Eustace
Browse files

Add an actual pip installer

parent 2a104075
Loading
Loading
Loading
Loading
+3 −1
Changes for poetry/console/application.py: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from poetry.utils.venv import Venv

from .commands import AboutCommand
from .commands import InstallCommand
from .commands import LockCommand


class Application(BaseApplication):
@@ -35,7 +36,8 @@ class Application(BaseApplication):

        return commands + [
            AboutCommand(),
            InstallCommand()
            InstallCommand(),
            LockCommand(),
        ]

    def do_run(self, i, o) -> int:
+1 −0
Changes for poetry/console/commands/__init__.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
from .about import AboutCommand
from .install import InstallCommand
from .lock import LockCommand
+1 −1
Changes for poetry/console/commands/install.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ class InstallCommand(Command):
    help = """The <info>install</info> command reads the <comment>poetry.lock</> file from
the current directory, processes it, and downloads and installs all the
libraries and dependencies outlined in that file. If the file does not
exist it will look for <comment>poetry.json</> and do the same.
exist it will look for <comment>poetry.toml</> and do the same.

<info>poetry install</info>    
"""
+32 −0
Changes for poetry/console/commands/lock.py: 32 added lines, 0 removed lines.
Original line number Diff line number Diff line
from poetry.installation import Installer
from poetry.repositories.pypi_repository import PyPiRepository

from .command import Command


class LockCommand(Command):
    """
    Locks the project dependencies.

    lock
        { --no-dev : Do not install dev dependencies. }
    """

    help = """The <info>lock</info> command reads the <comment>poetry.toml</> file from
the current directory, processes it, and locks the depdencies in the <comment>poetry.lock</> file.

<info>poetry lock</info>    
"""

    def handle(self):
        installer = Installer(
            self.output,
            self.poetry.package,
            self.poetry.locker,
            PyPiRepository()
        )

        installer.update(True)
        installer.execute_operations(False)

        return installer.run()
+24 −17
Changes for poetry/installation/installer.py: 24 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ from poetry.puzzle.operations.operation import Operation
from poetry.repositories import Repository
from poetry.repositories.installed_repository import InstalledRepository

from .pip_installer import PipInstaller


class Installer:

@@ -30,6 +32,8 @@ class Installer:
        self._dev_mode = True
        self._execute_operations = True

        self._installer = PipInstaller(self._io.venv, self._io)

    def run(self):
        # Force update if there is no lock file present
        if not self._update and not self._locker.is_locked():
@@ -78,6 +82,19 @@ class Installer:
    def is_dev_mode(self) -> bool:
        return self._dev_mode

    def update(self, update=True) -> 'Installer':
        self._update = update

        return self

    def is_updating(self) -> bool:
        return self._update

    def execute_operations(self, execute=True) -> 'Installer':
        self._execute_operations = execute

        return self

    def _do_install(self, local_repo):
        locked_repository = Repository()
        # initialize locked repo if we are installing from lock
@@ -113,7 +130,7 @@ class Installer:
        # if they are present in the local repo
        # TODO

        if ops:
        if ops and self._execute_operations:
            installs = []
            updates = []
            uninstalls = []
@@ -149,6 +166,7 @@ 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:
@@ -160,27 +178,16 @@ 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}</>)'
        )
        self._installer.install(operation.package)

    def _execute_update(self, operation: Update) -> None:
        name = operation.target_package.name
        original = operation.initial_package.pretty_version
        target = operation.target_package.pretty_version

        self._io.writeln(
            f'  - Updating <info>{name}</> '
            f'(<comment>{original}</>'
            f' -> <comment>{target}</>)'
        self._installer.update(
            operation.initial_package,
            operation.target_package
        )

    def _execute_uninstall(self, operation: Uninstall) -> None:
        self._io.writeln(
            f'  - Removing <info>{operation.package.name}</> '
            f'(<comment>{operation.package.full_pretty_version}</>)'
        )
        self._installer.remove(operation.package)

    def _get_operations_from_lock(self,
                                  locked_repository: Repository
Loading