简体   繁体   English

我需要什么软件包版本?

[英]What package version do I require?

I am developing a Python package that uses several other packages (numpy, scipy, etc...), and am wondering if there is an easy way to determine what minimum version I need for each of the packages. 我正在开发一个使用其他几个软件包(numpy,scipy等)的Python软件包,并且想知道是否有一种简单的方法来确定每个软件包所需的最低版本。 For instance, I need scipy 0.11 because some functions I am using did not exist before that. 例如,我需要scipy 0.11,因为在此之前我所使用的某些功能不存在。 Is there an easier way to figure it out than to check every function call I make? 有没有比检查我进行的每个函数调用更简单的方法了? That would take a while... 那会花点时间...

I know I can just require the versions that I am currently running, but I don't want people to have to update a bunch of packages if they don't need it (ie I am running scipy 0.13, but don't need to require that). 我知道我只需要我当前正在运行的版本,但我不希望人们在不需要时必须更新一堆软件包(即,我正在运行scipy 0.13,但不需要要求)。

There really is no easy way to do this. 确实没有简单的方法可以做到这一点。 Any kind of automated tool would have to rely on metadata that tells it which version of the library each function, class, etc. was first added in. (And even then, the interface or behavior may have changed in an existing function, in a way you're relying on.) Most projects have no such information; 任何一种自动化工具都必须依赖于元数据,该元数据告诉它每个函数,类等首先添加到哪个版本的库中。(即使如此,接口或行为可能在现有函数,您依赖的方式。)大多数项目都没有此类信息; those that do, it's usually only in a form similar to the Python docs (eg, here ), which you would have to scrape and parse. 这样做的话,通常只能采用类似于Python文档的形式(例如here ),您必须对其进行抓取和解析。

A much better solution is to first ensure that you have adequate test coverage, then just install scipy 0.11 and test it. 更好的解决方案是首先确保您具有足够的测试范围,然后安装scipy 0.11并对其进行测试。 Does it work? 它行得通吗? Great, you support 0.11. 太好了,您支持0.11。 If not, you can either try to make it work, or just say that you require 0.12. 如果没有,您可以尝试使其正常运行,或者仅说您需要0.12。

What "adequate" means will depend on your target market. “足够”的含义取决于您的目标市场。 A commercial program sold to enterprise clients with a support contract will need to be much more rigorously tested on the dependencies you claim to support than an open source library aimed at expert developers. 与针对专家开发人员的开源库相比,通过支持合同出售给企业客户的商业程序将需要对您声称要支持的依赖项进行更严格的测试。

In some cases, you can get away with documenting what you test with, and leaving it open whether your code works on earlier versions. 在某些情况下,您可以避免记录测试的内容,并且不管您的代码是否适用于早期版本,都可以将其打开。 0.11 may or may not work, and if users want to try it (especially if they want to report their experiences to you, or to some community resource like a wiki), encourage it, but don't promise to officially support them. 0.11可能有效也可能无效,并且如果用户想尝试它(特别是如果他们想向您或Wiki等社区资源报告其体验),请鼓励使用它,但不要保证会正式支持它们。

Here is what another SO Q/A session suggests: 这是另一个SO Q / A会议建议的内容:

"For the python stuff I write that has external dependencies (3rd party libraries), I write a script that users can run to check their python install to see if the appropriate versions of modules are installed. “对于我编写的具有外部依赖性(第3方库)的python东西,我编写了一个脚本,用户可以运行该脚本来检查其python安装,以查看是否安装了适当版本的模块。

For the modules that don't have a defined 'version' attribute, you can inspect the interfaces it contains (classes and methods) and see if they match the interface they expect. 对于没有定义的“版本”属性的模块,您可以检查其包含的接口(类和方法),并查看它们是否与期望的接口匹配。 Then in the actual code that you're working on, assume that the 3rd party modules have the interface you expect." 然后,在您正在使用的实际代码中,假定第三方模块具有您期望的接口。”

Checking a Python module version at runtime 在运行时检查Python模块版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM