]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #1322: platform.dist() and platform.linux_distribution() functions are now...
authorBerker Peksag <berker.peksag@gmail.com>
Wed, 13 May 2015 09:32:20 +0000 (12:32 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Wed, 13 May 2015 09:32:20 +0000 (12:32 +0300)
Initial patch by Vajrasky Kok.

Doc/library/platform.rst
Doc/whatsnew/3.5.rst
Lib/platform.py
Lib/test/test_platform.py
Misc/NEWS

index e27f2ad8b0efb2489489329cbbbf9c7e27311876..679cc6b23ca8ca537b39751db6630d371e6494b0 100644 (file)
@@ -247,6 +247,8 @@ Unix Platforms
 
    This is another name for :func:`linux_distribution`.
 
+   .. deprecated-removed:: 3.5 3.7
+
 .. 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.
@@ -263,6 +265,8 @@ Unix Platforms
    parameters.  ``id`` is the item in parentheses after the version number.  It
    is usually the version codename.
 
+   .. deprecated-removed:: 3.5 3.7
+
 .. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048)
 
    Tries to determine the libc version against which the file executable (defaults
index a29ff10636075e42e372511ab0de4f18ae97bfcd..b7883652b5d93387cd2309094f2edf2c6fe16e13 100644 (file)
@@ -700,6 +700,11 @@ Deprecated Python modules, functions and methods
   :meth:`~string.Formatter.format` method of the :class:`string.Formatter`
   class has been deprecated.
 
+* :func:`platform.dist` and :func:`platform.linux_distribution` functions are
+  now deprecated and will be removed in Python 3.7.  Linux distributions use
+  too many different ways of describing themselves, so the functionality is
+  left to a package.
+  (Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.)
 
 Deprecated functions and types of the C API
 -------------------------------------------
index b1c659ebbf42abe1e229ecf30ea799c09aadbf31..52a009a3699b4ebd0a44b3b6dde1f534b3541187 100755 (executable)
@@ -297,6 +297,15 @@ 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.
 
@@ -363,9 +372,13 @@ def dist(distname='', version='', id='',
         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):
 
index ededbdba421949ed2a85d1e45712942897fba4bb..f4ce36d35d09045f5a3249ebcf758370941b4680 100644 (file)
@@ -311,10 +311,24 @@ class PlatformTest(unittest.TestCase):
             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()
index 77e6f1d65533d268a34e0820c77a7ad892d07e71..b15d70f10df0b9c005be496e277c337c5359dfc6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -45,6 +45,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #1322: platform.dist() and platform.linux_distribution() functions are
+  now deprecated.  Initial patch by Vajrasky Kok.
+
 - Issue #22486: Added the math.gcd() function.  The fractions.gcd() function now is
   deprecated.  Based on patch by Mark Dickinson.