Unverified Commit 6359a8bc authored by Sébastien Eustace's avatar Sébastien Eustace
Browse files

Fix operations solving

parent 7b606248
Loading
Loading
Loading
Loading
+39 −38
Changes for poetry/installation/installer.py: 39 added lines, 38 removed lines.
Original line number Diff line number Diff line
@@ -135,19 +135,9 @@ class Installer:
            # If we are installing from lock
            # Filter the operations by comparing it with what is
            # currently installed
            ops = []
            for package in locked_repository.packages:
                ops.append(Install(package))
            ops = self._get_operations_from_lock(locked_repository)

        for op in ops:
            if op.job_type == 'install':
                local_repo.add_package(op.package)
            elif op.job_type == 'update':
                local_repo.add_package(op.target_package)
            elif op.job_type == 'uninstall':
                local_repo.remove_package(op.package)

        ops = self._filter_operations(ops)
        self._populate_local_repo(local_repo, ops, locked_repository)

        self._io.new_line()

@@ -247,44 +237,55 @@ class Installer:

        self._installer.remove(operation.package)

    def _filter_operations(self,
                           ops: List[Operation]
                           ) -> List[Operation]:
        installed_repo = InstalledRepository.load(self._io.venv)
        new_ops = []
    def _populate_local_repo(self, local_repo, ops, locked_repository):
        # Add all locked packages from the lock and go from there
        for package in locked_repository.packages:
            local_repo.add_package(package)

        # Now, walk through all operations and add/remove/update accordingly
        for op in ops:
            if isinstance(op, Update):
                package = op.target_package
            else:
                package = op.package

            is_installed = False
            for installed in installed_repo.packages:
                if package.name == installed.name:
                    is_installed = True
                    if op.job_type == 'uninstall':
                        new_ops.append(op)
            acted_on = False
            for pkg in local_repo.packages:
                if pkg.name == package.name:
                    # The package we operate on is in the local repo
                    if op.job_type == 'update':
                        if pkg.version == package.version:
                            break

                    if package.version != installed.version:
                        new_ops.append(Update(installed, package))
                    elif package.category == 'dev' and not self.is_dev_mode():
                        if op.job_type == 'uninstall':
                            new_ops.append(op)
                        else:
                            new_ops.append(Uninstall(installed))
                    else:
                        # Nothing to do
                        break
                        local_repo.remove_package(pkg)
                        local_repo.add_package(op.target_package)
                    elif op.job_type == 'uninstall':
                        local_repo.remove_package(op.package)

            if not is_installed:
                if op.job_type in ['update', 'uninstall']:
                    continue
                    acted_on = True

                new_ops.append(op)
            if not acted_on:
                local_repo.add_package(package)

        return new_ops
    def _get_operations_from_lock(self,
                                  locked_repository: Repository
                                  ) -> List[Operation]:
        installed_repo = InstalledRepository.load(self._io.venv)
        ops = []

        for locked in locked_repository.packages:
            is_installed = False
            for installed in installed_repo.packages:
                if locked.name == installed.name:
                    is_installed = True
                    if locked.category == 'dev' and not self.is_dev_mode():
                        ops.append(Uninstall(locked))
                    elif locked.version != installed.version:
                        ops.append(Update(
                            installed, locked
                        ))

            if not is_installed:
                ops.append(Install(locked))

        return ops
+7 −7
Changes for poetry/puzzle/solver.py: 7 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@ from .ui import UI

class Solver:

    def __init__(self, installed, io):
        self._installed = installed
    def __init__(self, locked, io):
        self._locked = locked
        self._io = io

    def solve(self, requested, repository, fixed=None) -> List[Operation]:
@@ -46,21 +46,21 @@ class Solver:

        operations = []
        for package in packages:
            processed = False
            for pkg in self._installed.packages:
            installed = False
            for pkg in self._locked.packages:
                if package.name == pkg.name:
                    installed = True
                    # Checking version
                    if package.version != pkg.version:
                        processed = True
                        operations.append(Update(pkg, package))

                    break

            if not processed:
            if not installed:
                operations.append(Install(package))

        # Checking for removals
        for pkg in self._installed.packages:
        for pkg in self._locked.packages:
            remove = True
            for package in packages:
                if pkg.name == package.name: