New submission from STINNER Victor <victor.stin...@haypocalc.com>:

sys.platform contains the major system version. If you test the sys.platform 
value (e.g. sys.platform == 'linux2'), your program doesn't work anymore with 
the new system major version (e.g. Linux 3). This problem is common with 
NetBSD, OpenBSD and FreeBSD. You don't have the problem if you test the prefix 
of sys.platform (e.g. sys.platform.startswith('linux')), but this code pattern 
is rare.

Because of the release of Linux 3, it was proposed in #12326 to remove the 
major version from sys.platform. It is already done for Cygwin and Darwin. 
Example of new sys.platform values: 'linux', 'freebsd', 'hp-ux', ... (instead 
of 'linux2', 'freebsd8', hp-ux11', ...).

I don't know if "osf1" becomes "osf". I don't know if "irix646" becomes "irix6" 
or just "irix"?

What about sys.platform=="win32"? Should it be truncated to "win"? Many tests 
use already sys.platform.startswith("win"). And what about 
sys.platform=="java"? It would be nice to be consistent (e.g. never have digits 
in sys.platform).

Without the major version, it's much easier when you only care of the system 
name: you can use a dictionary with the name for the key (it's used in 
regrtest.py with my patch).

Another example :
------------------------
    if sys.platform in ('netbsd1', 'netbsd2', 'netbsd3',
                        'Darwin1.2', 'darwin',
                        'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
                        'freebsd6', 'freebsd7', 'freebsd8',
                        'bsdos2', 'bsdos3', 'bsdos4',
                        'openbsd', 'openbsd2', 'openbsd3', 'openbsd4'):
------------------------
becomes:
------------------------
    if sys.platform in ('netbsd', 'freebsd', 'openbsd', 'bsdos', 
                        'Darwin1.2', 'darwin'):
------------------------
('Darwin1.2'? WTF?)

This issue follows my previous commit 50f1922bc1d5:

   Issue #12326: don't test the major version of sys.platform
   Use startswith, instead of ==, when testing sys.platform to support
   new platforms like Linux 3 or OpenBSD 5.

I chose to keep sys.platform in distutils and packaging because these modules 
are supposed to work on older Python versions (e.g. packaging will be 
backported to Python 2.4-3.2).

Attached patch implements this issue. It requires platform.major(): see issue 
#12794. The patch require to rerun "autoconf".

----------
files: sys_platform_without_major.patch
keywords: patch
messages: 142540
nosy: haypo, loewis
priority: normal
severity: normal
status: open
title: Remove the major version from sys.platform
versions: Python 3.3
Added file: http://bugs.python.org/file22964/sys_platform_without_major.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12795>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to