Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate platform.dist() and platform.linux_distribution() functions #45663

Closed
sapetnioc mannequin opened this issue Oct 24, 2007 · 75 comments
Closed

Deprecate platform.dist() and platform.linux_distribution() functions #45663

sapetnioc mannequin opened this issue Oct 24, 2007 · 75 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@sapetnioc
Copy link
Mannequin

sapetnioc mannequin commented Oct 24, 2007

BPO 1322
Nosy @malemburg, @birkenfeld, @doko42, @tiran, @benjaminp, @mcepl, @merwok, @encukou, @berkerpeksag, @xnox, @vajrasky, @andy-maier, @leycec, @ShaneHarvey
PRs
  • bpo-28167: bump Deprecated function removal to 3.8 #6669
  • Dependencies
  • bpo-3937: platform.dist(): detect Linux distribution version in a robust, standard way
  • Files
  • debian_version
  • lsb-release
  • platform.py
  • platform_py25.patch
  • test_platform_py26.diff: Patch for python 2.6 trunk. Include some additional linux test cases.
  • test_platform_py26_fix_centos.diff: Fix to patch test_platform_py26.diff return distname with contents of file
  • dist.patch.txt: zooko's patch to identify linux platform by parsing /etc/lsb-release or else invoking lsb_release
  • deprecate_platform_dist.patch
  • deprecate_platform_dist_v2.patch
  • issue1322.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/berkerpeksag'
    closed_at = <Date 2015-05-13.09:33:20.871>
    created_at = <Date 2007-10-24.17:21:04.022>
    labels = ['type-feature', 'library']
    title = 'Deprecate platform.dist() and platform.linux_distribution() functions'
    updated_at = <Date 2018-05-16.23:46:42.863>
    user = 'https://bugs.python.org/sapetnioc'

    bugs.python.org fields:

    activity = <Date 2018-05-16.23:46:42.863>
    actor = 'petr.viktorin'
    assignee = 'berker.peksag'
    closed = True
    closed_date = <Date 2015-05-13.09:33:20.871>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2007-10-24.17:21:04.022>
    creator = 'sapetnioc'
    dependencies = ['3937']
    files = ['8616', '8617', '8663', '8664', '9504', '10298', '11574', '33324', '33334', '36284']
    hgrepos = []
    issue_num = 1322
    keywords = ['patch', 'needs review']
    message_count = 75.0
    messages = ['56710', '56712', '56747', '56748', '56749', '56773', '56774', '56775', '56784', '56785', '56786', '56958', '56959', '58350', '62764', '62774', '62782', '66702', '67046', '69186', '69187', '73652', '73656', '73659', '73660', '73662', '73663', '73666', '73744', '74336', '83762', '83765', '83860', '83861', '134157', '134193', '134219', '134255', '134269', '134277', '137281', '137287', '207397', '207415', '207421', '207422', '207426', '207427', '207500', '224903', '228533', '236794', '242751', '243063', '243090', '243093', '244109', '244110', '256016', '256017', '256018', '256026', '256027', '256111', '256333', '256702', '263312', '263313', '263724', '263725', '263896', '299869', '316660', '316696', '316876']
    nosy_count = 22.0
    nosy_names = ['lemburg', 'georg.brandl', 'doko', 'zooko', 'draghuram', 'christian.heimes', 'sapetnioc', 'benjamin.peterson', 'pavel.vinogradov', 'mcepl', 'bgomes', 'eric.araujo', 'petr.viktorin', 'python-dev', 'pola', 'berker.peksag', 'xnox', 'vajrasky', 'andymaier', 'nir0s', 'leycec', 'ShaneHarvey']
    pr_nums = ['6669']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1322'
    versions = ['Python 3.5']

    @sapetnioc
    Copy link
    Mannequin Author

    sapetnioc mannequin commented Oct 24, 2007

    The distribution name returned by platform.dist() depends on the order
    of os.path.listdir( '/etc' ). It selects the first file matching the
    regex r'(\w+)-_' and takes part of the file name
    (i.e. matchResult.groups()[0]) as distribution name. But there are often
    several files matching this pattern (at least on Fedora and Mandriva).
    For instance, on a Mandriva 2007.1 official, I can see the following files:

    [login@localhost ~]$ ls -l /etc/*-release
    -rw-r--r-- 1 root root 137 jan 18 2007 /etc/lsb-release
    lrwxrwxrwx 1 root root 16 oct 7 17:32 /etc/mandrakelinux-release ->
    mandriva-r
    elease
    lrwxrwxrwx 1 root root 16 oct 7 17:32 /etc/mandrake-release ->
    mandriva-releas
    e
    -rw-r--r-- 1 root root 50 avr 2 2007 /etc/mandriva-release
    lrwxrwxrwx 1 root root 16 oct 7 17:32 /etc/redhat-release ->
    mandriva-release

    Therefore, the result for platform.distrib()[0] could be mandriva,
    mandrake, redhat or even lsb. The first match wins !

    Ignoring symlinks could remove part of the problem. On Mandriva, it
    would leave only lsb-release and mandriva-release. It is possible to
    select the good one by ignoring lsb-release or by verifying the file's
    content (mandriva-release has one line and lsb-release has several
    lines). I do not know if the second method is portable.

    @sapetnioc sapetnioc mannequin added the type-bug An unexpected behavior, bug, or error label Oct 24, 2007
    @gvanrossum
    Copy link
    Member

    Do you have a patch? That would help tremendously.

    @draghuram
    Copy link
    Mannequin

    draghuram mannequin commented Oct 25, 2007

    I think it is safe to ignore lsb-release. In fact, there seems to be a
    command "lsb_release" that gives information about distribution. On my
    SuSE box, this is what I get:

    marvin:# lsb_release -i
    Distributor ID: SUSE LINUX
    marvin:
    # lsb_release -d
    Description: SUSE LINUX 10.1 (i586)
    marvin:~# lsb_release -r
    Release: 10.1

    sapetnioc, can you check if this command exists on your system and if
    so, it's output? platform.dist() can check for this command's existence
    and if present, can perhaps use it to glean distro information. Please
    let me know if you want to write the patch. I will do it otherwise.

    @sapetnioc
    Copy link
    Mannequin Author

    sapetnioc mannequin commented Oct 25, 2007

    I can easily do the patch to ignore symlinks and /etc/lsb-release but I am
    not sure of the appropriate way to look for lsb_update command, is
    distutils.spawn.find_executable( 'lsb_release' ) ok ?
    If you need the patch earlier than begining of next week, you should do it.
    Otherwise I can make it.

    On Mandriva 2007.1, the command exists if the package "lsb-release" is
    installed. I do not know if it is always installed (I selected a checkbox
    "LSB" during install, this checkbox is unchecked by default).
    The output is:

    [yann@localhost ~]$ lsb_release -a
    LSB Version:
    lsb-3.1-ia32:lsb-3.1-noarch:core-3.0-ia32:core-3.0-noarch:core-3.1-ia32:core-3.1-noarch:cxx-3.0-ia32:cxx-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch:lsb-3.0-ia32:lsb-3.0-noarch:qt4-3.1-ia32:qt4-3.1-noarch
    Distributor ID: MandrivaLinux
    Description: Mandriva Linux
    Release: 2007.1
    Codename: Official

    [yann@localhost ~]$ lsb_release -i
    Distributor ID: MandrivaLinux

    [yann@localhost ~]$ lsb_release -d
    Description: Mandriva Linux

    [yann@localhost ~]$ lsb_release -r
    Release: 2007.1

    On Fedora 4 (rather old) , the command is in the package "redhat-lsb".

    yc176684:src$ lsb_release -a
    LSB Version: 1.3
    Distributor ID: FedoraCore
    Description: Fedora Core release 4 (Stentz)
    Release: 4
    Codename: Stentz

    yc176684:src$ lsb_release -i
    Distributor ID: FedoraCore

    yc176684:src$ lsb_release -d
    Description: Fedora Core release 4 (Stentz)

    yc176684:src$ lsb_release -r
    Release: 4

    On Fedora 7, the command is in the package "redhat-lsb" and seem to be
    installed by default.

    gargamel:riviere% lsb_release -a
    LSB
    Version: :core-3.1-ia32:core-3.1-noarch:
    graphics-3.1-ia32:graphics-3.1-noarch
    Distributor ID: Fedora
    Description: Fedora release 7 (Moonshine)
    Release: 7
    Codename: Moonshine

    gargamel:riviere% lsb_release -i
    Distributor ID: Fedora

    gargamel:riviere% lsb_release -d
    Description: Fedora release 7 (Moonshine)

    gargamel:riviere% lsb_release -r
    Release: 7

    On 10/25/07, Raghuram Devarakonda < report@bugs.python.org> wrote:

    Raghuram Devarakonda added the comment:

    I think it is safe to ignore lsb-release. In fact, there seems to be a
    command "lsb_release" that gives information about distribution. On my
    SuSE box, this is what I get:

    marvin:# lsb_release -i
    Distributor ID: SUSE LINUX
    marvin:
    # lsb_release -d
    Description: SUSE LINUX 10.1 (i586)
    marvin:~# lsb_release -r
    Release: 10.1

    sapetnioc, can you check if this command exists on your system and if
    so, it's output? platform.dist() can check for this command's existence
    and if present, can perhaps use it to glean distro information. Please
    let me know if you want to write the patch. I will do it otherwise.

    ----------
    nosy: +draghuram


    Tracker <report@bugs.python.org >
    <http://bugs.python.org/issue1322 >


    @draghuram
    Copy link
    Mannequin

    draghuram mannequin commented Oct 25, 2007

    On 10/25/07, Yann Cointepas <report@bugs.python.org> wrote:

    I can easily do the patch to ignore symlinks and /etc/lsb-release but I am
    not sure of the appropriate way to look for lsb_update command, is
    distutils.spawn.find_executable( 'lsb_release' ) ok ?

    You can just execute the command and if there is any error, default to
    the current code. There is no need to explicitly check for the
    binary's existence.

    If you need the patch earlier than begining of next week, you should do it.
    Otherwise I can make it.

    I don't "need" the patch :-). If you can't get to it some time next
    week, I will try to come up with the patch.

    On Mandriva 2007.1, the command exists if the package "lsb-release" is
    installed. I do not know if it is always installed (I selected a checkbox
    "LSB" during install, this checkbox is unchecked by default).
    The output is:

    [yann@localhost ~]$ lsb_release -a
    LSB Version:
    lsb-3.1-ia32:lsb-3.1-noarch:core-3.0-ia32:core-3.0-noarch:core-3.1-ia32:core-3.1-noarch:cxx-3.0-ia32:cxx-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch:lsb-3.0-ia32:lsb-3.0-noarch:qt4-3.1-ia32:qt4-3.1-noarch
    Distributor ID: MandrivaLinux
    Description: Mandriva Linux
    Release: 2007.1
    Codename: Official

    [yann@localhost ~]$ lsb_release -i
    Distributor ID: MandrivaLinux

    [yann@localhost ~]$ lsb_release -d
    Description: Mandriva Linux

    [yann@localhost ~]$ lsb_release -r
    Release: 2007.1

    On Fedora 4 (rather old) , the command is in the package "redhat-lsb".

    yc176684:src$ lsb_release -a
    LSB Version: 1.3
    Distributor ID: FedoraCore
    Description: Fedora Core release 4 (Stentz)
    Release: 4
    Codename: Stentz

    yc176684:src$ lsb_release -i
    Distributor ID: FedoraCore

    yc176684:src$ lsb_release -d
    Description: Fedora Core release 4 (Stentz)

    yc176684:src$ lsb_release -r
    Release: 4

    On Fedora 7, the command is in the package "redhat-lsb" and seem to be
    installed by default.

    gargamel:riviere% lsb_release -a
    LSB
    Version: :core-3.1-ia32:core-3.1-noarch:
    graphics-3.1-ia32:graphics-3.1-noarch
    Distributor ID: Fedora
    Description: Fedora release 7 (Moonshine)
    Release: 7
    Codename: Moonshine

    gargamel:riviere% lsb_release -i
    Distributor ID: Fedora

    gargamel:riviere% lsb_release -d
    Description: Fedora release 7 (Moonshine)

    gargamel:riviere% lsb_release -r
    Release: 7

    On 10/25/07, Raghuram Devarakonda < report@bugs.python.org> wrote:
    >
    >
    > Raghuram Devarakonda added the comment:
    >
    > I think it is safe to ignore lsb-release. In fact, there seems to be a
    > command "lsb_release" that gives information about distribution. On my
    > SuSE box, this is what I get:
    >
    > marvin:# lsb_release -i
    > Distributor ID: SUSE LINUX
    > marvin:
    # lsb_release -d
    > Description: SUSE LINUX 10.1 (i586)
    > marvin:~# lsb_release -r
    > Release: 10.1
    >
    > sapetnioc, can you check if this command exists on your system and if
    > so, it's output? platform.dist() can check for this command's existence
    > and if present, can perhaps use it to glean distro information. Please
    > let me know if you want to write the patch. I will do it otherwise.
    >
    > ----------
    > nosy: +draghuram
    >
    > __________________________________
    > Tracker <report@bugs.python.org >
    > <http://bugs.python.org/issue1322 >
    > __________________________________
    >

    Added file: http://bugs.python.org/file8609/unnamed


    Tracker <report@bugs.python.org>
    <http://bugs.python.org/issue1322\>


    @tiran
    Copy link
    Member

    tiran commented Oct 26, 2007

    Ony my Ubuntu box lsb_release is just a small Python script that parses
    /etc/lsb-release. I suggest that your read the LSB standards about the
    file and use the information to parse it instead of invoking a program.

    @draghuram
    Copy link
    Mannequin

    draghuram mannequin commented Oct 26, 2007

    Ony my Ubuntu box lsb_release is just a small Python script that parses
    /etc/lsb-release. I suggest that your read the LSB standards about the
    file and use the information to parse it instead of invoking a program.

    Can you please check if it supports all the options mentioned
    previously in the bug report? I agree that reading from a file is
    preferable to running a command, if issues OP mentioned can be
    addressed.

    @tiran
    Copy link
    Member

    tiran commented Oct 26, 2007

    heimes@seneca:$ /usr/bin/lsb_release -a
    LSB Version:
    core-2.0-noarch:core-3.0-noarch:core-3.1-noarch:core-2.0-ia32:core-3.0-ia32:core-3.1-ia32:cxx-2.0-noarch:cxx-3.0-noarch:cxx-3.1-noarch:cxx-2.0-ia32:cxx-3.0-ia32:cxx-3.1-ia32:graphics-2.0-noarch:graphics-3.0-noarch:graphics-3.1-noarch:graphics-2.0-ia32:graphics-3.0-ia32:graphics-3.1-ia32:desktop-3.1-noarch:desktop-3.1-ia32
    Distributor ID: Ubuntu
    Description: Ubuntu 7.10
    Release: 7.10
    Codename: gutsy
    heimes@seneca:
    $ /usr/bin/lsb_release -i
    Distributor ID: Ubuntu
    heimes@seneca:$ /usr/bin/lsb_release -d
    Description: Ubuntu 7.10
    heimes@seneca:
    $ /usr/bin/lsb_release -c
    Codename: gutsy
    heimes@seneca:~$ /usr/bin/lsb_release -r
    Release: 7.10

    Please read http://linux.die.net/man/1/lsb_release. It explains the
    content of /etc/*-release in detail.

    @sapetnioc
    Copy link
    Mannequin Author

    sapetnioc mannequin commented Oct 26, 2007

    I am writing a patch but I have a few questions:

    1. There are at most three places where the distribution name can be
      found. What is the priority order to select only one name ?
      The three places are:
      a) Inside the /etc/lsb-release file
      b) In the name of the /etc/<distrib>-release file
      c) In the content of the /etc/<distrib>-release file
      For instance, on Mandriva 2007.1 the possible names are:
      a) 'MandrivaLinux'
      b) 'mandriva'
      c) 'Mandriva Linux'
      I would suggest to put a) first to be compatible with LSB
      but on most systems it would change the value returned by
      platform.dist after the patch (is it a problem ?).
      I would have liked to use c) as second choice but this space
      in the name set by Mandriva could be a problem (It's possible
      to suppress spaces in the result though).

    2. Can I remove supported_dists parameter of platform.dist ?
      There could be a list of supported distributions but why
      as a parameter of this function ?

    @tiran
    Copy link
    Member

    tiran commented Oct 26, 2007

    I am writing a patch but I have a few questions:

    1. There are at most three places where the distribution name can be
      found. What is the priority order to select only one name ?
      The three places are:
      a) Inside the /etc/lsb-release file
      b) In the name of the /etc/<distrib>-release file
      c) In the content of the /etc/<distrib>-release file

    As far as I remember the specs a /etc/*-release file has a higher
    priority than /etc/lsb-release.

    1. Can I remove supported_dists parameter of platform.dist ?
      There could be a list of supported distributions but why
      as a parameter of this function ?

    I agree. A module global list is better than a list as a function argument.

    Can you also use a global variable instead of "/etc"? Something like
    ETC_DIR = "/etc" for example. It would allow you to ship samples from
    several distribution and run unit tests against each.

    Christian

    @tiran
    Copy link
    Member

    tiran commented Oct 26, 2007

    Can you also use a global variable instead of "/etc"? Something like
    ETC_DIR = "/etc" for example. It would allow you to ship samples from
    several distribution and run unit tests against each.

    I've attached the two relevant files from Ubuntu 7.10 Gutsy.

    @sapetnioc
    Copy link
    Mannequin Author

    sapetnioc mannequin commented Oct 30, 2007

    I joined a modified version of platform.py. Here is a summary of the
    modification:

    • replaced '/etc' by global variable _etc_dir
    • removed supported_dists parameter of dist()
    • each element of dist() result is searched in the following places
      (the first value found is kept):
      1. First line of /etc/<distribname>-release
      2. Contents of /etc/lsb-release
      3. Extract <distribname> from /etc/<distribname>-release

    I tested it on Mandriva 2007.1, Fedora 4 and on a faked /etc directory
    containing the Ubuntu files send by tiran. Results are:
    Mandriva 2007.1: ('MandrivaLinux', '2007.1', 'Official')
    Fedora 4: ('FedoraCore', '4', 'Stentz')
    Faked Ubuntu: ('Ubuntu', '7.10', 'gutsy')

    @tiran
    Copy link
    Member

    tiran commented Oct 30, 2007

    Yann Cointepas wrote:

    I joined a modified version of platform.py. Here is a summary of the
    modification:

    • replaced '/etc' by global variable _etc_dir
    • removed supported_dists parameter of dist()
    • each element of dist() result is searched in the following places
      (the first value found is kept):
      1. First line of /etc/<distribname>-release
      2. Contents of /etc/lsb-release
      3. Extract <distribname> from /etc/<distribname>-release

    Here is an updated patch against Python 2.5 (your file was based on
    Python 2.5's platform.py, wasn't it?).

    CHANGES:

    • Added unit tests
    • Add Lib/test/platform directory for unit tests
    • removed usage of string
    • minor cleanups

    Now for the funny part. You have to port the patch to the svn trunk. The
    file can't be altered in the 2.5 release cycle. The changes are too
    great. Unfortunately the patch doesn't apply cleanly.

    Please add more test data to the platform/ directory and test_platform.py

    In order to build the trunk:
    svn co http://svn.python.org/projects/python/trunk
    cd trunk
    ./configure
    make
    patch -p0 < patchfile
    ./python Lib/test/test_platform.py
    svn diff > patchfile

    Christian

    @tiran tiran added stdlib Python modules in the Lib dir tests Tests in the Lib/test dir labels Oct 30, 2007
    @tiran
    Copy link
    Member

    tiran commented Dec 10, 2007

    I'm mentoring a task for GHOP which is going to fix the problem.

    @tiran tiran self-assigned this Dec 10, 2007
    @pavelvinogradov
    Copy link
    Mannequin

    pavelvinogradov mannequin commented Feb 23, 2008

    I'm work on this issue in
    GHOP(http://code.google.com/p/google-highly-open-participation-psf/issues/detail?id=216&can=1&colspec=ID%20Status%20ClaimedBy%20Due%20NeedsReview%20Summary)
    I'm attach updated patch for python trunk. This patch fixes issue and
    add additional test for some other Linux distributions.

    @tiran
    Copy link
    Member

    tiran commented Feb 23, 2008

    Thanks Pavel!
    First I need confirmation from the GHOP project and Georg that you have
    submitted the contributor form. Then I'm going to merge your patch.

    @tiran tiran assigned birkenfeld and unassigned tiran Feb 23, 2008
    @pavelvinogradov
    Copy link
    Mannequin

    pavelvinogradov mannequin commented Feb 23, 2008

    You can see confirmation from Georg on thread in GHOP:
    http://code.google.com/p/google-highly-open-participation-psf/issues/detail?id=216&can=1&colspec=ID%20Status%20ClaimedBy%20Due%20NeedsReview%20Summary#c20

    I can update patch for 3.0 (it don't applies now) if you are ready to
    commit them.

    @bgomes
    Copy link
    Mannequin

    bgomes mannequin commented May 12, 2008

    In this fix I removed the use of the file name in order to return the
    distname. Now, only the file contents
    is taken into account.

    On Centos, the file name is the same as on Redhat, but its contents is
    different:
    $ cat /etc/redhat-release
    CentOS release 5 (Final)

    Compare:

    With test_platform_py26.diff:
    Python 2.6a3+ (trunk:62996M, May 10 2008, 16:38:41) 
    [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import platform
    >>> platform.dist()
    ('redhat', '5', 'Final')
    >>> 
    
    With the new fix:
    Python 2.6a3+ (trunk:62996M, May 10 2008, 16:38:41) 
    [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import platform
    >>> platform.dist()
    ('CentOS', '5', 'Final')
    >>> 

    I have tested this fix on Ubuntu, Centos5 and RHEL 5 and it works fine.
    Ubuntu: ('Ubuntu', '8.04', 'hardy')
    Fedora: ('fedora', '8', 'Werewolf')

    @benjaminp
    Copy link
    Contributor

    Christian was reviewing this for GHOP.

    @benjaminp benjaminp assigned tiran and unassigned birkenfeld May 18, 2008
    @malemburg
    Copy link
    Member

    Please see the top of platform.py:

    # This module is maintained by Marc-Andre Lemburg <mal@egenix.com>.
    # If you find problems, please submit bug reports/patches via the
    # Python SourceForge Project Page and assign them to "lemburg".

    # Note: Please keep this module compatible to Python 1.5.2.

    I wonder why the ticket wasn't assigned to me.

    Regarding the patch:

    • the dist() function has been superseded by linux_distribution().

    • the supported_dists argument is a documented feature of
      linux_distributions(), so should not be removed

    • the Windows name normalization should not be removed (it fixes a bug
      in Vista)

    • the change from using string functions to using string methods breaks
      1.5.2 compatibility (*)

    • the _ETC_DIR global just makes things harder to read and there's no
      apparent need for it

    (*) It's probably time to drop 1.5.2 compatibility and only keep the
    module compatible to Python 2.1, so this is not much of an issue.

    Overall, I think it's better to define a fixed search order for the
    release files than to try to figure out and parse random release files
    that happen to match the release file RE.

    For that to work, it would help a lot if you could provide the file name
    and contents of various platform release files.

    @malemburg malemburg assigned malemburg and unassigned tiran Jul 3, 2008
    @berkerpeksag berkerpeksag added the type-feature A feature request or enhancement label Oct 5, 2014
    @andy-maier
    Copy link
    Mannequin

    andy-maier mannequin commented Feb 27, 2015

    Do we really think that a package on pypi solves the problem better? The discussion only shows that it is more likely we end up with multiple different packages on pypi, instead of one that is commonly agreed.

    I agree it is tough to get to an agreed upon approach, but having this in the Python base at least ensures that it is the one approach everybody uses.

    The /etc/os-release format seems to be used more often now, so I'm wondering why we cannot come up with a reasonable approach that is backwards compatible, supports /etc/os-release, and (if still needed), also /etc/lsb-release and the lsb_release script.

    Again: If we ever want to end up with just one package on pypi, that very discussion needs to happen.

    It seems to me that if the approach should be compatible, then we cannot use the new generic files (lsb* and os-release) first. The currently implemented approach needs to be used first. Then the new generic files.

    @malemburg
    Copy link
    Member

    Thanks, Berker, your patch looks fine.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 13, 2015

    New changeset 9c606c573ec0 by Berker Peksag in branch 'default':
    Issue bpo-1322: platform.dist() and platform.linux_distribution() functions are now deprecated.
    https://hg.python.org/cpython/rev/9c606c573ec0

    @encukou
    Copy link
    Member

    encukou commented May 13, 2015

    Issues bpo-17762 and bpo-9514 had patches to improve these functions. Time to close them?

    @malemburg
    Copy link
    Member

    On 13.05.2015 16:18, Petr Viktorin wrote:

    Issues bpo-17762 and bpo-9514 had patches to improve these functions. Time to close them?

    Yes. I just did. Thanks for the reminder.

    @xnox
    Copy link
    Mannequin

    xnox mannequin commented May 26, 2015

    Why not change them to parse os-release files as defined by

    http://www.freedesktop.org/software/systemd/man/os-release.html

    A lot of things use these functions to check what one is running on, despite the problems, and do different things at install time.

    This deprecation and eventual removal, will result in a pypi module created with such functionality anyway, that everyone will try to pull in.... or falling that copying in.

    Here in https://clearlinux.org team we have patches to switch these to parse /etc/os-release;/usr/lib/os-release files instead. Would you be open to deprecate parsing any other files but os-release going forward? As that is standard across all linux distributions for quite some time now.

    Regards,

    Dimitri.
    Debian Developer, Ubuntu Core Developer, Clear Linux* Project Developer.

    @xnox
    Copy link
    Mannequin

    xnox mannequin commented May 26, 2015

    Note that things have changed in this space, since the issue was opened in 2007.

    @nir0s
    Copy link
    Mannequin

    nir0s mannequin commented Dec 6, 2015

    I have a premliminary implementation of it: https://github.com/nir0s/ld

    Would love some help. It tries to use adhere to the standards (os-release first, lsb-release later, then, distro-specific release files).

    It also returns more types of values then there were before.

    @doko42
    Copy link
    Member

    doko42 commented Dec 6, 2015

    this is not "fixable". and now when parsing os-release you get different values then you got before, e.g. changing "Ubuntu" to "ubuntu".

    @nir0s
    Copy link
    Mannequin

    nir0s mannequin commented Dec 6, 2015

    I didn't mean to say that it was. Still, it's important to have some implementation of identifying linux distributions and their properties..

    @malemburg
    Copy link
    Member

    This deprecation and eventual removal, will result in a pypi module created with such functionality anyway, that everyone will try to pull in.... or falling that copying in.

    That's the plan, right.

    The stdlib is not the right place for things that change this often. Just look at how many semi standards we've seen in the last few years. There's no point in trying to follow these in a slow moving code base as the Python stdlib. It's much better to put the functionality into a PyPI module which can be updated much more frequently.

    Perhaps you could upload your code to PyPI and then reference it here for people to find ?!

    Thanks.

    @nir0s
    Copy link
    Mannequin

    nir0s mannequin commented Dec 6, 2015

    Apologies.

    This can be simply installed by running pip install ld (from https://pypi.python.org/pypi/ld).

    Some notes:

    • I've just now started writing tests
    • Haven't tested on versions other than 2.7.x and 2.6.x
    • There's some stray code there. This works.. but it's obviously WIP.
    • I'm all into getting as many pull requests to make this as robust as possible as fast as possible.

    @berkerpeksag
    Copy link
    Member

    We should probably delete the "will be removed in Python 3.7" part from the deprecation message to make porting from Python 2 easier. For example, we will add inspect.getargspec() back in 3.6. See bpo-25486.

    @nir0s
    Copy link
    Mannequin

    nir0s mannequin commented Dec 13, 2015

    I would love some comments (and PRs, of course) on ld. Wanna make it as robust as possible.

    @andy-maier
    Copy link
    Mannequin

    andy-maier mannequin commented Dec 18, 2015

    Nir,
    I appreciate very much what you are doing. I was about to do the same ;-)

    I'll review your code shortly. I like the idea to use /etc/os-release, as it has the most complete information. Stay tuned.
    Andy

    Am 6. Dezember 2015 18:12:52 MEZ, schrieb Nir Cohen <report@bugs.python.org>:

    Nir Cohen added the comment:

    I have a premliminary implementation of it: https://github.com/nir0s/ld

    Would love some help. It tries to use adhere to the standards
    (os-release first, lsb-release later, then, distro-specific release
    files).

    It also returns more types of values then there were before.

    ----------
    nosy: +nir0s


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue1322\>


    @leycec
    Copy link
    Mannequin

    leycec mannequin commented Apr 13, 2016

    Deprecating platform.linux_distribution() while retaining platform.win32_ver() and platform.mac_ver() is non-orthogonal, unjustifiable, and (arguably) discriminatory.

    Platform version detection is no more a moving target under Linux than under Windows or OS X -- possibly less so, given the numerous significant revisions to platform.win32_ver() implementations over the dreary years. If Linux is arbitrarily unentitled to platform-specific lookup functions, then other platforms deserve the same.

    Unlike both Windows and OS X, the overwhelming majority of Linux distributions provide a trivially parsable plaintext file publishing high-level platform metadata in "="-delimited shell variable assignment format: the systemd-mandated and freedesktop.org-maintained "/etc/os-release" file. Under edge-case Linux distributions ideologically rejecting this standard (e.g., Gentoo Linux), a subset of the named tuple returned by platform.uname() is trivially returnable.

    Do not parse multiple possibly conflicting files, commands, or standards. Doing so is neither necessary nor desirable. If "/etc/os-release" exists, parse that; else, fallback to platform.uname(). Done. Fait accompli. Quite simple. No moving target exists.

    A robust platform.linux_distribution() implementation adhering to this scheme is implementable in less than 50 lines of code -- possibly less than 20, assuming aggressive cleverness. How? If "/etc/os-release" exists, this file is guaranteed to be POSIX shell-compatible and hence Pythonically parsable via the stdlib shlex.shlex() function. (In brief: iteratively search for tokens containing "=", split these tokens on "=", ignore irrelevant variable names, and retain the remainder. That's it.) The fallback alternative is even briefer.

    Removing core functionality invites third-party API explosion. This is the height of irresponsibility. Brace for heavyweight dependencies, end-user confusion, multiple competing non-standards, and poorly selected PyPi names conflicting with the long-standing GNU toolchain. (See nir0s' "ld", also referred to as "What was nir0s thinking?")

    None of these are good things. Given the unremarkable simplicity of implementing this function correctly, this cul-de-sac of Cthulhian insanity needn't have happened in the first place.

    It did. Now we languish.

    @malemburg
    Copy link
    Member

    The idea is to have similar functionality implemented as a PyPI
    package, which can be updated more often than the stdlib.

    Unlike Windows and Mac OS X, the approach to finding out
    the distribution version is changing too often on Linux (w/r to how
    Python release cycles work). The problem is not complexity, it's
    maintainability.

    If you're confident that you can write the one and only implementation,
    feel free to do so. Put it on PyPI and we can point people to it
    once it has picked up a reasonable following we can point to it
    in the documentation.

    PS: I agree that the package name "ld" is not very intuitive. Perhaps
    Nir could change it to something more easily recognizable, such as
    "linux_distribution" :-)

    Thanks,

    Marc-Andre Lemburg
    eGenix.com

    @andy-maier
    Copy link
    Mannequin

    andy-maier mannequin commented Apr 19, 2016

    Nir currently proposes to change the package name from "ld" to "dist". See python-distro/distro#103
    Comments on this name change proposal are welcome (over there).

    On "Given the unremarkable simplicity of implementing this function correctly ...":

    It seems to me that this is over-simplifying the task somewhat. Nir's "ld" package needs to understand all of the (currently) three different formats on Linux, and goes for a precedence-based approach to consolidate the information. Also, determining supposedly simple things like a reliable distro ID, or a precise distro version is not trivial, given that some Linux distros provide their data quite inconsistently between the different data sources and sometimes change things like distro ID incompatibly in a new minor release.

    Overall, I can only encourage people to try out the "ld" package (v0.5.0 is currently on PyPI) and give feedback (on its GitHub project).

    Does the deprecation and removal of these functions discriminate Linux compared to Windows and OS-X? Maybe, but I'm pragmatic here, and for me the important criteria is the one that was stated from the beginning in this discussion: The higher change rate in Linux fits quite well with the approach of having a separate package that is not part of the standard Python.

    Does that mean that less batteries are now included in Python out of the box: Yes, a very small part of the batteries is now no longer included. But maybe one day when the "ld" package is perfect and does not require a high change rate anymore, it gets added to standard Python.

    Also, there are many packages the average Python project needs these days that are no longer coming with standard Python (six, setuptools, pbr, better unit testers, lxml, M2Crypto, Sphinx, lxml, ........). If you look at the long backlog of pull requests and open issues in standard Python, it is a good thing actually, not to overload the community maintaining the standard Python even further. But that is a bit off-topic for this issue, I am just mentioning it in order to beg for acceptance for the approach taken for linux distro information.

    @andy-maier
    Copy link
    Mannequin

    andy-maier mannequin commented Apr 19, 2016

    @leycec: By the way, the "ld" package *does* use shlex.shlex() to parse the os-release file.

    @andy-maier
    Copy link
    Mannequin

    andy-maier mannequin commented Apr 21, 2016

    Just for completeness:

    The "ld" package is now called "distro" and its v0.6.0 is on PyPI: https://pypi.python.org/pypi/distro

    @ShaneHarvey
    Copy link
    Mannequin

    ShaneHarvey mannequin commented Aug 7, 2017

    When are these functions going to be deprecated? In 3.5, 3.6, and master they still raise PendingDeprecationWarning, not DeprecationWarning:
    https://github.com/python/cpython/blob/v3.5.3/Lib/platform.py#L305-L306
    https://github.com/python/cpython/blob/v3.6.2/Lib/platform.py#L304-L305
    https://github.com/python/cpython/blob/5c4b0d0/Lib/platform.py#L304-L305

    @encukou
    Copy link
    Member

    encukou commented May 15, 2018

    I talked to Ned, the release manager for 3.7.
    It's too late to remove this in 3.7, so I'll update the docs and make the deprecation notice more current/useful, and link to the distro library.

    @encukou
    Copy link
    Member

    encukou commented May 15, 2018

    Marc-Andre, if you agree the function can be removed in 3.8.
    This is tracked in https://bugs.python.org/issue28167

    @encukou
    Copy link
    Member

    encukou commented May 16, 2018

    For the record, I opened an issue on distro about the vicious circle of distro detection instead of feature detection: python-distro/distro#221

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    10 participants