用纯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如何在NetBeans中使用LTI CIVIL(DLL文件)运行嵌入HTML页面的小程序   如何在java中调用solr分析api?   编译jitsi项目时,java转换为Dalvik格式失败,错误为1   java是合并2个Spring数据JPA存储库类的最佳架构选择   java在portlet应用程序中从JSP传回参数   java logback以编程方式获取ref appender   java无法解析符号FirebaseListAdapter   java扩展现有spring jpa存储库函数   java使用pdfbox从msoffice转换为pdf   java如何启动客户端机器exe文件而不依赖浏览器?   javascript屏蔽ui wicket数据源   java是否使用SpringXML实体在带注释的文件中设置属性?   JavaJSON序列化流   java中的split为字符串数组添加了空空间   使用java从XML中查找重复的实体标记   java两个相互关联的组合框   java我没有初始化变量,但仍然收到一个输出   java将焦点设置为其他jframe   C#和Java类属性之间有什么区别?