用纯python编写的通用依赖项解析算法。
mixolog的Python项目详细描述
混音学
用纯python编写的通用依赖项解析算法。
安装
如果您使用的是poetry,它很简单:
poetry add mixology
如果没有,您可以使用pip
:
pip install mixology
用法
mixology是一种依赖性解析算法。 它深受红宝石中Molinillo的启发。
为了开始使用mixology
,需要初始化一个Resolver
实例
与SpecificationProvider
和UI
一起工作
你的系统。
然后,需要使用用户请求的依赖项列表调用Resolver.resolve()
以及可选的“锁定”DependencyGraph
。
规范提供商
SpecificationProvider
类构成基础
对于具有molinillo的客户机库的关键集成点。
它的方法将客户端的特定于域的模型对象转换为解析器理解的概念:
- 嵌套依赖项
- 姓名
- 需求满足
- 查找规范(内部称为可能性)
- 排序依赖项(为了合理的解析器性能)
基类如下:
classSpecificationProvider(object):""" Provides information about specifications and dependencies to the resolver, allowing the Resolver class to remain generic while still providing power and flexibility. This contract contains the methods that users of mixology must implement using knowledge of their own model classes. """@propertydefname_for_explicit_dependency_source(self):# type: () -> strreturn'user-specified dependency'@propertydefname_for_locking_dependency_source(self):# type: () -> strreturn'Lockfile'defsearch_for(self,dependency):# type: (Any) -> List[Any]""" Search for the specifications that match the given dependency. The specifications in the returned list will be considered in reverse order, so the latest version ought to be last. """return[]defdependencies_for(self,specification):# type: (Any) -> List[Any]""" Returns the dependencies of specification. """return[]defis_requirement_satisfied_by(self,requirement,# type: Anyactivated,# type: DependencyGraphspec# type: Any):# type: (...) -> Any""" Determines whether the given requirement is satisfied by the given spec, in the context of the current activated dependency graph. """returnTruedefname_for(self,dependency):# type: (Any) -> str""" Returns the name for the given dependency. """returnstr(dependency)defsort_dependencies(self,dependencies,# type: List[Any]activated,# type: DependencyGraphconflicts# type: Dict[str, List[Conflict]]):# type: (...) -> List[Any]""" Sort dependencies so that the ones that are easiest to resolve are first. Easiest to resolve is (usually) defined by: 1) Is this dependency already activated? 2) How relaxed are the requirements? 3) Are there any conflicts for this dependency? 4) How many possibilities are there to satisfy this dependency? """returnsorted(dependencies,key=lambdadep:(activated.vertex_named(self.name_for(dep)).payloadisNone,conflicts.get(self.name_for(dep)isNone)))defallow_missing(self,dependency):# type: (Any) -> bool""" Returns whether this dependency, which has no possible matching specifications, can safely be ignored. """returnFalse
用户界面
UI
类有助于反馈和调试依赖解析过程。
您可以将其子类化以根据需要进行自定义。
基类如下:
classUI(object):def__init__(self,debug=False):self._debug=debug@propertydefoutput(self):returnsys.stdout@propertydefprogress_rate(self):# type: () -> floatreturn0.33defis_debugging(self):# type: () -> boolreturnself._debugdefindicate_progress(self):# type: () -> Noneself.output.write('.')defbefore_resolution(self):# type: () -> Noneself.output.write('Resolving dependencies...\n')defafter_resolution(self):# type: () -> Noneself.output.write('')defdebug(self,message,depth):# type: (...) -> Noneifself.is_debugging():debug_info=str(message)debug_info='\n'.join([':{}: {}'.format(str(depth).rjust(4),s)forsindebug_info.split('\n')])+'\n'self.output.write(debug_info)
贡献
要在mixology代码库上工作,您需要分叉项目,在本地克隆分叉。
并通过poetry <https://poetry.eustace.io>
安装所需的依赖项。
git clone git@github.com:sdispater/mixology.git poetry install
然后,创建功能分支:
git checkout -b my-new-feature
进行修改,相应地添加测试并执行测试套件:
poetry run pytest tests/
当您准备好提交更改时:
git commit -am 'Add new feature'
推动您的分支:
git push origin my-new-feature
最后创建一个请求。