[issue12326] Linux 3: code should avoid using sys.platform == 'linux2'

Marc-Andre Lemburg report at bugs.python.org
Fri Aug 19 11:09:40 CEST 2011


Marc-Andre Lemburg <mal at egenix.com> added the comment:

Martin von Gagern wrote:
> 
> Martin von Gagern <Martin.vGagern at gmx.net> added the comment:
> 
> Marc-Andre Lemburg wrote:
>> Both Python and the application will make certain assumptions about
>> the platform depending on the compile time environment.
> 
> Can you give examples for this?

Sure, just have a look at how different the various minor release
Mac OS X versions are. They even changed the default architecture
without bumping the major version of the OS.

A configure run on one OS version will pick up different
environment settings than on a later one. As a result Python
and application extensions use different libs/packages/tools
or even create completely different runtimes (e.g. one for PPC,
the other for i386).

>> So you need both the compile and the runtime version information.
> 
> I very much doubt that any feature in Python is actually enabled if
> compiled under Linux 3. If so that's probably a bug in Python, due to
> the small number of features added from 2.6.39 to 3.0. Either the
> feature was introduced into Linux before 3.0, in which case Python
> should use it as early as possible, or the feature was introduced in
> some 3.x release, in which case not all Linux 3 builds will have it.
> 
> So the single digit major number will not be enough for this kind of
> checks, and the safest way is to check for the feature itself, e.g. by
> simply using it and handling NotImplementedException appropriately. That
> approach is more portable for new platforms as well.

That works fine for features that you can programmatically
control. It doesn't work well for static data that you provide
externally depending on the platform OS version. Take e.g.
the plat-freebsdN directories with the OS dependent
constants/functions as example.

As already mentioned, the diff between Linux 2.x and 3.x will
grow over time and while there may not be much to see now,
things will change in the coming years.

Just look at the differences between plat-linux1 and plat-linux2
(plat-linux1 was phased out in Python 2.4 so you have to go back
to Python 2.3 or earlier).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12326>
_______________________________________


More information about the Python-bugs-list mailing list