Bug 1595220 - streamline and sanitize output of distro/platform linux_distribution call in mozinfo r=jmaher
authorEdwin Takahashi <egao@mozilla.com>
Wed, 13 Nov 2019 19:42:41 +0000
changeset 501820 3d5e40454c304b5614cb5725c3f5d8cab82c7be3
parent 501819 73c69599b3f12fa0f2dc45ee29fb202c93a9a695
child 501821 cbd4aa02eba91ea5645c4d92fa5fe1d6adf63a1e
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1595220
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1595220 - streamline and sanitize output of distro/platform linux_distribution call in mozinfo r=jmaher Differential Revision: https://phabricator.services.mozilla.com/D52440
testing/mozbase/mozinfo/mozinfo/mozinfo.py
testing/mozbase/mozinfo/setup.py
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py
+++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py
@@ -94,30 +94,29 @@ if system in ["Microsoft", "Windows"]:
         version = "%d.%d.%d" % (major, minor, build_number)
 
     os_version = "%d.%d" % (major, minor)
 elif system.startswith(('MINGW', 'MSYS_NT')):
     # windows/mingw python build (msys)
     info['os'] = 'win'
     os_version = version = unknown
 elif system == "Linux":
-    # Only attempt to import distro for Linux.
-    # https://github.com/nir0s/distro/issues/177
+    # Attempt to use distro package to determine Linux distribution first.
+    # Failing that, fall back to use the platform method.
+    # Note that platform.linux_distribution() will be deprecated as of 3.8
+    # and this block will be removed once support for 2.7/3.5 is dropped.
     try:
-        import distro
+        from distro import linux_distribution
     except ImportError:
-        pass
-    # First use distro package, then fall back to platform.
-    # This will only until Mozilla upgrades python to 3.8.
-    if hasattr(distro, "linux_distribution"):
-        (distribution, os_version, codename) = distro.linux_distribution()
-    elif hasattr(platform, "linux_distribution"):
-        (distribution, os_version, codename) = platform.linux_distribution()
-    else:
-        (distribution, os_version, codename) = platform.dist()
+        from platform import linux_distribution
+
+    output = linux_distribution()
+    (distribution, os_version, codename) = tuple(
+        str(item.title()) for item in output)
+
     if not processor:
         processor = machine
     version = "%s %s" % (distribution, os_version)
 
     # Bug in Python 2's `platform` library:
     # It will return a triple of empty strings if the distribution is not supported.
     # It works on Python 3. If we don't have an OS version,
     # the unit tests fail to run.
--- a/testing/mozbase/mozinfo/setup.py
+++ b/testing/mozbase/mozinfo/setup.py
@@ -1,17 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import
 
 from setuptools import setup
 
-PACKAGE_VERSION = "1.2.0"
+PACKAGE_VERSION = "1.2.1"
 
 # dependencies
 deps = [
     "distro == 1.4.0",
     "mozfile >= 0.12",
 ]
 
 setup(