Package: mixology
MixologyA generic dependency-resolution library written in pure Python.
It is based on thePubGrubalgorithm.InstallationIf you are usingpoetry, it's as simple as:poetryaddmixologyIf not you can usepip:pipinstallmixologyUsageMixology is a dependency resolution algorithm.In order to start using Mixology you need to initialize aVersionSolverinstance
with aPackageSourcewhich should be adapted to work with your system.Then, you need to callVersionSolver.solve()which will return aresultwith the list of decisions
or raise aSolveFailurewhich will give a detailed explanation of the reason why the resolution failed.ExampleThis example is extracted from the test suite of Mixology
and uses thepoetry-semverlibrary.First we need to have our ownPackageSourceclass which implements the required methods
and a simpleDependencyclass. Packages will be represented by simple strings.fromsemverimportVersionfromsemverimportVersionRangefromsemverimportparse_constraintfrommixology.constraintimportConstraintfrommixology.package_sourceimportPackageSourceasBasePackageSourcefrommixology.rangeimportRangefrommixology.unionimportUnionclassDependency:def__init__(self,name,constraint):# type: (str, str) -> Noneself.name=nameself.constraint=parse_constraint(constraint)self.pretty_constraint=constraintdef__str__(self):# type: () -> strreturnself.pretty_constraintclassPackageSource(BasePackageSource):def__init__(self):# type: () -> Noneself._root_version=Version.parse("0.0.0")self._root_dependencies=[]self._packages={}super(PackageSource,self).__init__()@propertydefroot_version(self):returnself._root_versiondefadd(self,name,version,deps=None):# type: (str, str, Optional[Dict[str, str]]) -> NoneifdepsisNone:deps={}version=Version.parse(version)ifnamenotinself._packages:self._packages[name]={}ifversioninself._packages[name]:raiseValueError("{}({}) already exists".format(name,version))dependencies=[]fordep_name,specindeps.items():dependencies.append(Dependency(dep_name,spec))self._packages[name][version]=dependenciesdefroot_dep(self,name,constraint):# type: (str, str) -> Noneself._root_dependencies.append(Dependency(name,constraint))def_versions_for(self,package,constraint=None):# type: (Hashable, Any) -> List[Hashable]ifpackagenotinself._packages:return[]versions=[]forversioninself._packages[package].keys():ifnotconstraintorconstraint.allows_any(Range(version,version,True,True)):versions.append(version)returnsorted(versions,reverse=True)defdependencies_for(self,package,version):# type: (Hashable, Any) -> List[Any]ifpackage==self.root:returnself._root_dependenciesreturnself._packages[package][version]defconvert_dependency(self,dependency):# type: (Dependency) -> Constraintifisinstance(dependency.constraint,VersionRange):constraint=Range(dependency.constraint.min,dependency.constraint.max,dependency.constraint.include_min,dependency.constraint.include_max,dependency.pretty_constraint,)else:# VersionUnionranges=[Range(range.min,range.max,range.include_min,range.include_max,str(range),)forrangeindependency.constraint.ranges]constraint=Union.of(ranges)returnConstraint(dependency.name,constraint)Now, we need to specify our root dependencies and the available packages.source=PackageSource()source.root_dep("a","1.0.0")source.root_dep("b","1.0.0")source.add("a","1.0.0",deps={"shared":">=2.0.0 <4.0.0"})source.add("b","1.0.0",deps={"shared":">=3.0.0 <5.0.0"})source.add("shared","2.0.0")source.add("shared","3.0.0")source.add("shared","3.6.9")source.add("shared","4.0.0")source.add("shared","5.0.0")Now that everything is in place we can create aVersionSolverinstance
with the newly createdPackageSourceand callsolve()to retrieve aSolverResultinstance.frommixology.version_solverimportVersionSolversolver=VersionSolver(source)result=solver.solve()result.decisions# {Package("_root_"): <Version 0.0.0>, 'b': <Version 1.0.0>, 'a': <Version 1.0.0>, 'shared': <Version 3.6.9>}result.attempted_solutions# 1ContributingTo work on the Mixology codebase, you'll want to fork the project, clone the fork locally
and install the required dependencies viapoetry <https://poetry.eustace.io>_.gitclonegit@github.com:sdispater/mixology.git
poetryinstallThen, create your feature branch:gitcheckout-bmy-new-featureMake your modifications, add tests accordingly and execute the test suite:poetryrunpytesttests/When you are ready, commit your changes:gitcommit-am'Add new feature'push your branch:gitpushoriginmy-new-featureand finally create a pull request.