#279 Use module distro instead of platform
Merged 2 years ago by cqi. Opened 2 years ago by cqi.
cqi/fedpkg use-distro  into  master

file modified
+2 -2

@@ -13,13 +13,13 @@ 

  import os

  import git

  import re

- import platform

  

  from datetime import datetime, timedelta

  

  from . import cli  # noqa

  from .lookaside import FedoraLookasideCache

  from pyrpkg.utils import cached_property

+ from .utils import linux_distribution

  

  try:

      from bodhi.client.bindings import BodhiClient as _BodhiClient

@@ -232,7 +232,7 @@ 

             conflicting

          """

          try:

-             runtime_os, runtime_version, _ = platform.linux_distribution()

+             runtime_os, runtime_version, _ = linux_distribution()

          except Exception:

              return None

  

file modified
+5

@@ -20,6 +20,11 @@ 

  from requests.exceptions import ConnectionError

  from pyrpkg import rpkgError

  

+ try:

+     from distro import linux_distribution  # noqa

+ except ImportError:

+     from platform import linux_distribution  # noqa

+ 

  

  def query_pdc(server_url, endpoint, params, timeout=60):

      api_url = '{0}/rest_api/v1/{1}/'.format(

file modified
+4

@@ -32,6 +32,10 @@ 

      tests_require += [

          'unittest2'

      ]

+ else:

+     install_requires += [

+         'distro',

+     ]

  

  

  setup(

file modified
+4 -4

@@ -24,20 +24,20 @@ 

          super(TestDetermineRuntimeEnv, self).setUp()

          self.cmd = self.make_commands()

  

-     @patch('platform.linux_distribution')

+     @patch('fedpkg.linux_distribution')

      def test_return_fedora_disttag(self, linux_distribution):

          linux_distribution.return_value = ('Fedora', '25', 'Twenty Five')

  

          result = self.cmd._determine_runtime_env()

          self.assertEqual('fc25', result)

  

-     @patch('platform.linux_distribution')

+     @patch('fedpkg.linux_distribution')

      def test_return_None_if_os_is_unknown(self, linux_distribution):

          linux_distribution.side_effect = ValueError

  

          self.assertEqual(None, self.cmd._determine_runtime_env())

  

-     @patch('platform.linux_distribution')

+     @patch('fedpkg.linux_distribution')

      def test_return_for_rhel(self, linux_distribution):

          linux_distribution.return_value = ('Red Hat Enterprise Linux Server',

                                             '6.8',

@@ -55,7 +55,7 @@ 

          ]

  

          for dist, expected_dist_tag in dists:

-             with patch('platform.linux_distribution', return_value=dist):

+             with patch('fedpkg.linux_distribution', return_value=dist):

                  result = self.cmd._determine_runtime_env()

                  self.assertEqual(expected_dist_tag, result)

  

platform.linux_distribution is deprecated. This patch uses recommended
replacement module distro.

Fixes #278

Signed-off-by: Chenxiong Qi cqi@redhat.com

The code looks good to me (but I've not tested it).

Also for me it is good.

Pull-Request has been merged by cqi

2 years ago