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

pip should use the distro module: platform.linux_distribution() has been deprecated in Python 3.5 #3823

Closed
vstinner opened this Issue Jun 29, 2016 · 12 comments

Comments

Projects
None yet
7 participants
@vstinner
Contributor

vstinner commented Jun 29, 2016

  • Pip version: development version
  • Python version: 3.5
  • Operating System: Fedora 24

Description:

"pip install PrettyTable" logs a PendingDeprecationWarning because platform.linux_distribution() has been deprecated in Python 3.5:

.../pip/download.py:93: PendingDeprecationWarning: dist() and linux_distribution() functions are deprecated in Python 3.5
  zip(["name", "version", "id"], platform.linux_distribution()),

I suggest to replace the function with the distro module:

FYI platform.linux_distribution() and platform.dist() have been deprecated by https://bugs.python.org/issue1322

@vstinner vstinner changed the title from pip should use distro: platform.linux_distribution() is deprecated to pip should use the distro module: platform.linux_distribution() has been deprecated in Python 3.5 Jun 29, 2016

@AbdealiJK

This comment has been minimized.

Show comment
Hide comment
@AbdealiJK

AbdealiJK Jun 29, 2016

Would this imply that if pip is installed, distro will also be installed ?

Because I want to use distro in my setup.py and would not need to download it inside setup.py or use setup_requires for it if it's available because of pip.

Would this imply that if pip is installed, distro will also be installed ?

Because I want to use distro in my setup.py and would not need to download it inside setup.py or use setup_requires for it if it's available because of pip.

@vstinner

This comment has been minimized.

Show comment
Hide comment
@vstinner

vstinner Jun 29, 2016

Contributor

Would this imply that if pip is installed, distro will also be installed ?

No, I suggest to put it in pip/_vendor/ "hidden" package.

Contributor

vstinner commented Jun 29, 2016

Would this imply that if pip is installed, distro will also be installed ?

No, I suggest to put it in pip/_vendor/ "hidden" package.

@nir0s

This comment has been minimized.

Show comment
Hide comment
@nir0s

nir0s Jul 4, 2016

That would be swell. LMK if I can help.

nir0s commented Jul 4, 2016

That would be swell. LMK if I can help.

@xavfernandez xavfernandez added this to the 8.2 milestone Jul 6, 2016

@xavfernandez

This comment has been minimized.

Show comment
Hide comment
@xavfernandez

xavfernandez Jul 6, 2016

Contributor

Seems like a good idea, it would be good to avoid PendingDeprecationWarning on 3.6.
cc @dstufft @pfmoore

Contributor

xavfernandez commented Jul 6, 2016

Seems like a good idea, it would be good to avoid PendingDeprecationWarning on 3.6.
cc @dstufft @pfmoore

@pfmoore

This comment has been minimized.

Show comment
Hide comment
@pfmoore

pfmoore Jul 6, 2016

Member

It's only a tiny module, so I don't see a big issue. As I don't use Linux, I don't have any view on whether distro is the "right" solution here - I don't know what options exist - so I'm OK with whatever the experts agree on.

Member

pfmoore commented Jul 6, 2016

It's only a tiny module, so I don't see a big issue. As I don't use Linux, I don't have any view on whether distro is the "right" solution here - I don't know what options exist - so I'm OK with whatever the experts agree on.

@dstufft

This comment has been minimized.

Show comment
Hide comment
@dstufft

dstufft Jul 6, 2016

Member

I've planned on doing that yes, I jsut hadn't gotten around to it yet.

Member

dstufft commented Jul 6, 2016

I've planned on doing that yes, I jsut hadn't gotten around to it yet.

@nir0s

This comment has been minimized.

Show comment
Hide comment
@nir0s

nir0s Jul 7, 2016

If you provide me with the information, I can submit the PR

nir0s commented Jul 7, 2016

If you provide me with the information, I can submit the PR

xavfernandez added a commit to xavfernandez/pip that referenced this issue Aug 12, 2016

Vendore distro==0.6.0
To avoid DeprecationWarning for platform.linux_distribution()

Closes #3823
@xavfernandez

This comment has been minimized.

Show comment
Hide comment
@xavfernandez

xavfernandez Aug 12, 2016

Contributor

I've pushed #3906 hopefully I did not forget anything ?

Contributor

xavfernandez commented Aug 12, 2016

I've pushed #3906 hopefully I did not forget anything ?

xavfernandez added a commit to xavfernandez/pip that referenced this issue Aug 12, 2016

Vendor distro==0.6.0
To avoid DeprecationWarning for platform.linux_distribution()

Closes #3823
@xavfernandez

This comment has been minimized.

Show comment
Hide comment
@xavfernandez

xavfernandez Aug 12, 2016

Contributor

@nir0s hmm for some reason, pip's tests get stuck on pypy with the vendored distro (==0.6.0): any clue ?

Contributor

xavfernandez commented Aug 12, 2016

@nir0s hmm for some reason, pip's tests get stuck on pypy with the vendored distro (==0.6.0): any clue ?

@xavfernandez

This comment has been minimized.

Show comment
Hide comment
@xavfernandez

xavfernandez Aug 12, 2016

Contributor

My bad, it must have been a glitch in travis. Relaunching the build fixed it.

Contributor

xavfernandez commented Aug 12, 2016

My bad, it must have been a glitch in travis. Relaunching the build fixed it.

@dstufft dstufft closed this in #3906 Aug 12, 2016

dstufft added a commit that referenced this issue Aug 12, 2016

Vendor distro==0.6.0 (#3906)
To avoid DeprecationWarning for platform.linux_distribution()

Closes #3823
@chrullrich

This comment has been minimized.

Show comment
Hide comment
@chrullrich

chrullrich Aug 29, 2016

This change breaks pip on Windows fully, completely, and entirely:

(pipve) C:\Daten>python -m pip list
Traceback (most recent call last):
  File "C:\Program Files\Python35\lib\runpy.py", line 174, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Program Files\Python35\lib\runpy.py", line 133, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\Program Files\Python35\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "c:\daten\projekte\other\pip\pip\__init__.py", line 16, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "c:\daten\projekte\other\pip\pip\vcs\mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "c:\daten\projekte\other\pip\pip\download.py", line 40, in <module>
    from pip._vendor import distro
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 1040, in <module>
    _distroi = LinuxDistribution()
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 591, in __init__
    if include_lsb else {}
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 925, in _lsb_release_info
    raise subprocess.CalledProcessError(rc, cmd, err)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1

platform.linux_distribution() did not attempt to run an external command to get LSB release information; the new code does, and then stumbles when the attempt to run a non-existing command fails with exit code 1 rather than 127.

If an lsb_release command returning the correct exit status (127) is provided to simulate the expected failure mode, the next failure is this:

(pipve) C:\Daten>python -m pip list
Traceback (most recent call last):
  File "C:\Program Files\Python35\lib\runpy.py", line 174, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Program Files\Python35\lib\runpy.py", line 133, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\Program Files\Python35\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "c:\daten\projekte\other\pip\pip\__init__.py", line 16, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "c:\daten\projekte\other\pip\pip\vcs\mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "c:\daten\projekte\other\pip\pip\download.py", line 40, in <module>
    from pip._vendor import distro
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 1040, in <module>
    _distroi = LinuxDistribution()
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 592, in __init__
    self._distro_release_info = self._distro_release_info()
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 977, in _distro_release_info
    basenames = os.listdir(_UNIXCONFDIR)
FileNotFoundError: [WinError 3] The system cannot find the path specified: '/etc'

chrullrich commented Aug 29, 2016

This change breaks pip on Windows fully, completely, and entirely:

(pipve) C:\Daten>python -m pip list
Traceback (most recent call last):
  File "C:\Program Files\Python35\lib\runpy.py", line 174, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Program Files\Python35\lib\runpy.py", line 133, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\Program Files\Python35\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "c:\daten\projekte\other\pip\pip\__init__.py", line 16, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "c:\daten\projekte\other\pip\pip\vcs\mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "c:\daten\projekte\other\pip\pip\download.py", line 40, in <module>
    from pip._vendor import distro
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 1040, in <module>
    _distroi = LinuxDistribution()
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 591, in __init__
    if include_lsb else {}
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 925, in _lsb_release_info
    raise subprocess.CalledProcessError(rc, cmd, err)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1

platform.linux_distribution() did not attempt to run an external command to get LSB release information; the new code does, and then stumbles when the attempt to run a non-existing command fails with exit code 1 rather than 127.

If an lsb_release command returning the correct exit status (127) is provided to simulate the expected failure mode, the next failure is this:

(pipve) C:\Daten>python -m pip list
Traceback (most recent call last):
  File "C:\Program Files\Python35\lib\runpy.py", line 174, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Program Files\Python35\lib\runpy.py", line 133, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\Program Files\Python35\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "c:\daten\projekte\other\pip\pip\__init__.py", line 16, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "c:\daten\projekte\other\pip\pip\vcs\mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "c:\daten\projekte\other\pip\pip\download.py", line 40, in <module>
    from pip._vendor import distro
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 1040, in <module>
    _distroi = LinuxDistribution()
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 592, in __init__
    self._distro_release_info = self._distro_release_info()
  File "c:\daten\projekte\other\pip\pip\_vendor\distro.py", line 977, in _distro_release_info
    basenames = os.listdir(_UNIXCONFDIR)
FileNotFoundError: [WinError 3] The system cannot find the path specified: '/etc'
@chrullrich

This comment has been minimized.

Show comment
Hide comment
@chrullrich

chrullrich Aug 29, 2016

Note that the full distro package (as opposed to the version integrated into pip) defends itself aggressively against failing in this manner:

(pipve) C:\Daten>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import distro
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\daten\projekte\other\distro\distro.py", line 39, in <module>
    raise ImportError('Unsupported platform: {0}'.format(sys.platform))
ImportError: Unsupported platform: win32

chrullrich commented Aug 29, 2016

Note that the full distro package (as opposed to the version integrated into pip) defends itself aggressively against failing in this manner:

(pipve) C:\Daten>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import distro
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\daten\projekte\other\distro\distro.py", line 39, in <module>
    raise ImportError('Unsupported platform: {0}'.format(sys.platform))
ImportError: Unsupported platform: win32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment