Steve Amerige
Steve Amerige

Reputation: 1499

Without Updating, How to determine Python script is Portable?

Under what conditions can a python script be considered portable given the following assumptions:

Perhaps the solution is that a portable Python program is a program with no module dependencies and if the destination Python program version is also compatible. But, (1) I don't know if having no module dependencies is something that a Python script developer can live with; and, (2) I don't know what Python program version compatibility would actually mean (e.g., is any Python 2 script of any minor/patch version compatible with any other Python 2 script version)? Also, I assume that actually some modules are "core" modules that are always present across Python installations. Is this true? And, can incompatibilities arise if core modules or other modules that are deemed to always be present across Python installations have different version numbers. Can module version differences render a script non-portable?

The question is: is there any way via scripting to analyze a Python script to determine that it is portable, given the above constraints? Lacking that, is there any way via human inspection to make the same determination?

Upvotes: 0

Views: 67

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 149125

There are 2 possible ways (AFAIK) to develop scripts that have to be later run in closed production environment:

  • if you have full knowledge of the exact production environment, set up a test environment that is a clone of the production one. It makes sense for developpement teams that have no access to the production system but only develop for a specific platform.
  • if you want to be able to distribute your module to potentially unknown customers, you apply a reversed logic: you list all the requirements for your script and let the admin team control whether they meet them.

The latter way is more complex in a subtle way: as you normally want your script to be portable across most possible versions, you have to build (and automate) a testing platform for the different versions you declare to support.

In theory, it is possible to know in advance where a script will be portable: if it never comes close to any corner case, only use standard Python modules and only features that has not changed for many versions, it is likely to be portable across all those versions. But such requirements are hard to meet and even harder to control, so testing against different versions is the only foolproof way to make sure that a script will actually be portable.

Upvotes: 1

Related Questions