用纯python编写的通用依赖项解析算法。

mixolog的Python项目详细描述


混音学

用纯python编写的通用依赖项解析算法。

安装

如果您使用的是poetry,它很简单:

poetry add mixology

如果没有,您可以使用pip

pip install mixology

用法

mixology是一种依赖性解析算法。 它深受红宝石中Molinillo的启发。

为了开始使用mixology,需要初始化一个Resolver实例 与SpecificationProviderUI一起工作 你的系统。

然后,需要使用用户请求的依赖项列表调用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

最后创建一个请求。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在Kotlin中加速从短数组到位图的转换   java如何计算用户从5个组合框中选择的项目的总成本   如何实现Java图像处理来进行模板匹配?   java Android Studio Gradle找不到'com'。安卓支持:设计:22.2.0'(Android设计支持库)   Tomcat上的hibernate Java持久性没有名为EntityManager的持久性提供程序   Weblogic中有两个EAR的java Log4j日志记录问题   Java忽略字符串   java stringbuffer和“0&”导致截断或转义   在java中用猜测的字母替换破折号   java使用枚举查找长字符串描述   在Android Studio中选择图像后,java应用程序退出(未调用OnActivityResult)   java什么是类似于Rails的面向对象桌面应用程序框架?   java有没有一种方法可以在调试时永久更改变量的值,从而在后续调用中不被重写?   java NullPointerException从数据库获取数据时,使用注释调用Struts 2中的操作