From 1701fac885539425f8067a3eeeb7c01a9f5c63b7 Mon Sep 17 00:00:00 2001 From: Wackyator Date: Mon, 2 Oct 2023 14:06:12 +0530 Subject: [PATCH] fix: add default values for optional values --- py-rattler/rattler/solver/solver.py | 45 +++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/py-rattler/rattler/solver/solver.py b/py-rattler/rattler/solver/solver.py index 4a3c4ee80..b8be17c35 100644 --- a/py-rattler/rattler/solver/solver.py +++ b/py-rattler/rattler/solver/solver.py @@ -1,5 +1,5 @@ from __future__ import annotations -from typing import List +from typing import List, Optional from rattler.match_spec.match_spec import MatchSpec from rattler.rattler import py_solve @@ -11,19 +11,52 @@ def solve( specs: List[MatchSpec], available_packages: List[SparseRepoData], - locked_packages: List[RepoDataRecord], - pinned_packages: List[RepoDataRecord], - virtual_packages: List[GenericVirtualPackage], + locked_packages: Optional[List[RepoDataRecord]] = None, + pinned_packages: Optional[List[RepoDataRecord]] = None, + virtual_packages: Optional[List[GenericVirtualPackage]] = None, ) -> List[RepoDataRecord]: """ - Resolve the dependencies and return the [`RepoDataRecord`]s + Resolve the dependencies and return the `RepoDataRecord`s that should be present in the environment. + + Arguments: + specs: A list of matchspec to solve. + available_packages: A list of RepoData to use for solving the `specs`. + locked_packages: Records of packages that are previously selected. + If the solver encounters multiple variants of a single + package (identified by its name), it will sort the records + and select the best possible version. However, if there + exists a locked version it will prefer that variant instead. + This is useful to reduce the number of packages that are + updated when installing new packages. Usually you add the + currently installed packages or packages from a lock-file here. + pinned_packages: Records of packages that are previously selected and CANNOT + be changed. If the solver encounters multiple variants of + a single package (identified by its name), it will sort the + records and select the best possible version. However, if + there is a variant available in the `pinned_packages` field it + will always select that version no matter what even if that + means other packages have to be downgraded. + virtual_packages: A list of virtual packages considered active. + + Returns: + Resolved list of `RepoDataRecord`s. """ + + if not locked_packages: + locked_packages = list() + + if not pinned_packages: + pinned_packages = list() + + if not virtual_packages: + virtual_packages = list() + return [ RepoDataRecord._from_py_record(solved_package) for solved_package in py_solve( [spec._match_spec for spec in specs], - available_packages, + [package._sparse for package in available_packages], [package._record for package in locked_packages], [package._record for package in pinned_packages], [v_package._generic_virtual_package for v_package in virtual_packages],