简体   繁体   中英

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. For instance, I need scipy 0.11 because some functions I am using did not exist before that. 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).

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.

A much better solution is to first ensure that you have adequate test coverage, then just install scipy 0.11 and test it. Does it work? Great, you support 0.11. If not, you can either try to make it work, or just say that you require 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.

Here is what another SO Q/A session suggests:

"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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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