Bug 1595220 - streamline and sanitize output of distro/platform linux_distribution call in mozinfo r=jmaher
☠☠ backed out by f644542d11c1 ☠ ☠
authorEdwin Takahashi <egao@mozilla.com>
Tue, 12 Nov 2019 19:23:31 +0000
changeset 501677 4b4f0fb8292c18cd114e92ed3f1c57f187a7d5eb
parent 501676 37b70cca0d2fafeb578520983bae2c0a5fd8e540
child 501678 fee367f20825d755948e2e50ba4b93997307a69e
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, 1595147
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 Simplified and streamlined the logic in the Linux side of things, to address 1595147. Only attempt to import and use either `platform` or `distro`, not both. Perform sanitization of the output string since `distro.linux_distribution()` has a slightly different output than the `platform` equivalent. Minor version bump to 1.2.1 denoting a bugfix for release to pypi. 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.lower()) 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(