diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -242,32 +242,40 @@ Mac OS Platform Unix Platforms -------------- .. function:: dist(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...)) This is another name for :func:`linux_distribution`. + .. deprecated-removed:: 3.5 3.7 + The Linux distributions use too many different ways of describing + themselves, so the functionality is left to a package. + .. function:: linux_distribution(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...), full_distribution_name=1) Tries to determine the name of the Linux OS distribution name. ``supported_dists`` may be given to define the set of Linux distributions to look for. It defaults to a list of currently supported Linux distributions identified by their release file name. If ``full_distribution_name`` is true (default), the full distribution read from the OS is returned. Otherwise the short name taken from ``supported_dists`` is used. Returns a tuple ``(distname,version,id)`` which defaults to the args given as parameters. ``id`` is the item in parentheses after the version number. It is usually the version codename. + .. deprecated-removed:: 3.5 3.7 + The Linux distributions use too many different ways of describing + themselves, so the functionality is left to a package. + .. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048) Tries to determine the libc version against which the file executable (defaults to the Python interpreter) is linked. Returns a tuple of strings ``(lib, version)`` which default to the given parameters in case the lookup fails. Note that this function has intimate knowledge of how different libc versions add symbols to the executable is probably only usable for executables compiled diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -293,16 +293,20 @@ Deprecated Python modules, functions and slated for removal in Python 3.6. * :mod:`smtpd` has in the past always decoded the DATA portion of email messages using the ``utf-8`` codec. This can now be controlled by the new *decode_data* keyword to :class:`~smtpd.SMTPServer`. The default value is ``True``, but this default is deprecated. Specify the *decode_data* keyword with an appropriate value to avoid the deprecation warning. +* :func:`platform.dist` and :func:`platform.linux_distribution` functions are + deprecated and will be removed in Python 3.7 (contributed by Vajrasky Kok and + Berker Peksag in :issue:`1322`). + Deprecated functions and types of the C API ------------------------------------------- * None yet. Deprecated features diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -293,16 +293,25 @@ def _parse_release_file(firstline): if len(l) > 1: id = l[1] return '', version, id def linux_distribution(distname='', version='', id='', supported_dists=_supported_dists, full_distribution_name=1): + import warnings + warnings.warn("dist() and linux_distribution() functions are deprecated " + "in Python 3.5 and will be removed in Python 3.7", + PendingDeprecationWarning, stacklevel=2) + return _linux_distribution(distname, version, id, supported_dists, + full_distribution_name) + +def _linux_distribution(distname, version, id, supported_dists, + full_distribution_name): """ Tries to determine the name of the Linux OS distribution name. The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. supported_dists may be given to define the set of Linux @@ -359,19 +368,23 @@ def dist(distname='', version='', id='', The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. Returns a tuple (distname, version, id) which default to the args given as parameters. """ - return linux_distribution(distname, version, id, - supported_dists=supported_dists, - full_distribution_name=0) + import warnings + warnings.warn("dist() and linux_distribution() functions are deprecated " + "in Python 3.5 and will be removed in Python 3.7", + PendingDeprecationWarning, stacklevel=2) + return _linux_distribution(distname, version, id, + supported_dists=supported_dists, + full_distribution_name=0) def popen(cmd, mode='r', bufsize=-1): """ Portable popen() interface. """ import warnings warnings.warn('use os.popen instead', DeprecationWarning, stacklevel=2) return os.popen(cmd, mode, bufsize) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -306,15 +306,29 @@ class PlatformTest(unittest.TestCase): with mock.patch('platform._UNIXCONFDIR', tempdir): distname, version, distid = platform.linux_distribution() self.assertEqual(distname, 'Fedora') self.assertEqual(version, '19') self.assertEqual(distid, 'Schr\xf6dinger\u2019s Cat') -def test_main(): - support.run_unittest( - PlatformTest - ) + +class DeprecationTest(unittest.TestCase): + + def test_dist_deprecation(self): + with self.assertWarns(PendingDeprecationWarning) as cm: + platform.dist() + self.assertEqual(str(cm.warning), + 'dist() and linux_distribution() functions are ' + 'deprecated in Python 3.5 and will be removed in ' + 'Python 3.7') + + def test_linux_distribution_deprecation(self): + with self.assertWarns(PendingDeprecationWarning) as cm: + platform.linux_distribution() + self.assertEqual(str(cm.warning), + 'dist() and linux_distribution() functions are ' + 'deprecated in Python 3.5 and will be removed in ' + 'Python 3.7') if __name__ == '__main__': - test_main() + unittest.main()