views:

133

answers:

2

Okay basically 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 heres 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?

See 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, etc.).

But i am worried about my actual code, i could spend ours 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?

+4  A: 

Try pyqver: http://github.com/ghewgill/pyqver/blob/master/pyqver.py

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.

Rho
virtualenv requires setuptools, which requires python 2.3.5 and up. Also, a quick glance at virtualenv.py itself shows it imports into "logging", which is only available starting python 2.3. It also requires the "subprocess" module from 2.4, which can be backported to 2.3, but even the code itself only admits as much as "will probably work" about that one. Yes, python 2.2 is -really- end of life, and isn't supported even by a lot of the helpful tools out there.
Crast
Thats awesome. I'll give that a shot in a bit. But really just looking at certain things. I think i am going to curl up and cry.
UberJumper
Also i cannot install lower level versions of python since they will block me from using whatever arcgis geoprocessing python library i have installed. It needs to be a matching version, i cannot install more then one version of arcgis on a machine. So i think i am going to look at virtual boxing and see what i can do. Ugh.
UberJumper
+7  A: 

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

Crast
Roughly on average more then 50% of arcgis users are still using 9.1 / 9.0. Which needs 2.3 or 2.2 respectively. You cannot use their python modules without the corresponding version of python they require. It sucks i know. But ESRI doesn't really give a damn. Espcially when there is 3 different API's, 9.3 has the pythonic api, 9.2 is not really pythonic but does everything via enumerations. 9.1 and lower uses a bizzare mishmash of custom COM libraries and win32com.client.Dispatch. It sucks i know.
UberJumper
It seems then that you could have a lot to benefit from automated test suites and from buildbot. Especially if you want your product to behave the same working with 3 disparate API's, some well-thought out regression tests will pay great dividends for the future. Many projects have their buildbots configured to run with every VCS commit, and then email them if any tests fail. This can stomp newly introduced bugs much quicker.
Crast