开发者

How to see if code is backwards compatible for Python?

I have some code that I am trying to make it play nicely with ESRI's geoprocessor. However, ESRI's geoprocessor runs on Python 2.2, 2.3, 2.4, 2.5. We need to make our tools work on any version. So I've spent a lot of time working and coding workarounds for different versions, such that the wrapper geoprocessor has identical functionality across all versions.

Now here's the big thing, is there some sort of application that can basically scan modules to see if its syntax and methods are backwards compatible with the above Python version's?

Unfortunately, I cannot install Python 2.2 since I have Arcgis 9.3, which requires Python 2.5. And vice versa, I've gotten pretty much all the module dependencies sorted and worked out. (win32com, ctypes, 开发者_Python百科etc.).

But I am worried about my actual code, I could spend hours going and reading what keywords were added for what version etc, however this basically will be a huge headache. Is there some sort of application that does these things?


If you are actively developing a commercial product, and you -really- want to support all these versions properly, I would suggest:

  1. Writing an automated test suite that can be run and tests functionality for your entire library/application/whatever.

  2. Setting up a machine, or ideally virtual machine for each test environment (python 2.2-2.6 and any platform combinations if your product is not win32 only). This is especially easy to do nowadays given that there are several free virtualization products now (VirtualBox and VMWare Server, to name two)

  3. Using something like buildbot to automate the test running on all the other platforms, and collecting the results.

I might mention however, that there have been significant changes between 2.2 and 2.3, and again between 2.3 and 2.4. This is why most python libraries out there only support 2.3, and a number are moving to only supporting 2.4 and up now.

Every major release has a "What's new in python 2.x" document, but coding for 2.2 means you miss out on:

  • Generators (2.3) (well actually, you can get them in 2.2 with from __future__ import generators)
  • Generator expressions (2.4)
  • the subprocess module (2.4)
  • Decorator syntax (2.4)
  • sets (2.3)
  • decimal (2.4, but can be backported)
  • datetime (2.3)
  • itertools (2.3)

Just to name a very small subset of awesome things you probably can't have.

You have to really consider how badly you want to support a 7-year old python version, and miss out on a lot of cool features that can reduce your code size (or possibly just increase readability).


Try pyqver: https://github.com/ghewgill/pyqver/

Gives you the minimum version for given python script analyzing the keywords and modules used.

Also, you can compile locally python 2.2 and use virtualenv to create a python 2.2 environment with the --python flag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜