From 34db3c33619c8125f0ec6d5f42b8dcb7831a23d4 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jul 12 2017 10:47:02 +0000 Subject: [PATCH 1/3] utils: Avoid DeprecationWarning for messages for users When the warnings module is configured to log deprecation warnings, it could lead to confusing messages from any imported library. We can instead directly print the warning to stderr. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1455800 Signed-off-by: Lubomír Sedlář --- diff --git a/pyrpkg/utils.py b/pyrpkg/utils.py index 03606a4..2313ef0 100644 --- a/pyrpkg/utils.py +++ b/pyrpkg/utils.py @@ -13,10 +13,9 @@ This module contains a bunch of utilities used elsewhere in pyrpkg. """ -import warnings - import os import six +import sys if six.PY3: def u(s): @@ -29,8 +28,6 @@ else: getcwd = os.getcwdu -warnings.simplefilter('always', DeprecationWarning) - class cached_property(property): """A property caching its return value @@ -72,10 +69,9 @@ def warn_deprecated(clsname, oldname, newname): newname (str): The name of the new attribute, which should be used instead. """ - warnings.warn( - "%s.%s is deprecated and will be removed eventually.\n Please " - "use %s.%s instead." % (clsname, oldname, clsname, newname), - DeprecationWarning, stacklevel=3) + sys.stderr.write( + "DeprecationWarning: %s.%s is deprecated and will be removed eventually.\n" + "Please use %s.%s instead.\n" % (clsname, oldname, clsname, newname)) def _log_value(log_func, value, level, indent, suffix=''): diff --git a/tests/test_utils.py b/tests/test_utils.py index 96f6bdf..e9c67ae 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -148,10 +148,6 @@ class DeprecationUtilsTestCase(unittest.TestCase): self.assertTrue('Foo.old_method' in written_lines[0]) self.assertTrue('Foo.new_method' in written_lines[0]) - warnings.simplefilter('error', DeprecationWarning) - self.assertRaises(DeprecationWarning, foo.old_method) - self.assertEqual(len(written_lines), 1) - class LogResultTestCase(unittest.TestCase): def setUp(self): From fca84e6744cc5d3c124f7b9fbc6ffd8ce5571fd7 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jul 12 2017 10:47:02 +0000 Subject: [PATCH 2/3] Print --dist deprecation warning explicitly Since the warnings module is no longer automatically configured to print deprecation warnings, we should make sure the message gets printed manually. Signed-off-by: Lubomír Sedlář --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 17bd9ab..5893ce0 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -20,12 +20,11 @@ import random import string import sys import time -import warnings import koji import pyrpkg.utils as utils -from pyrpkg import rpkgError +from pyrpkg import rpkgError, log as rpkgLogger from six.moves import xmlrpc_client, configparser OSBS_DEFAULT_CONF_FILE = "/etc/osbs/osbs.conf" @@ -33,8 +32,8 @@ OSBS_DEFAULT_CONF_FILE = "/etc/osbs/osbs.conf" def warning_deprecated_dist(value): """Warning deprecated of option dist""" - warnings.warn('--dist is deprecated and will be removed in future version. ' - 'Use --release instead.', DeprecationWarning) + rpkgLogger.warning('Deprecation warning: --dist is deprecated and will be ' + 'removed in future version. Use --release instead.') return value From 0e97eb16731b0758a1948ad539bd2f42ceab01be Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jul 12 2017 10:47:02 +0000 Subject: [PATCH 3/3] Report deprecation of config via logger Signed-off-by: Lubomír Sedlář --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 5893ce0..cf4a673 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -127,9 +127,9 @@ class cliClient(object): if self.config.has_option(self.name, 'kojiconfig'): kojiconfig = self.config.get(self.name, 'kojiconfig') koji_config_type = 'config' - warnings.warn( - 'kojiconfig is deprecated. Instead, kojiprofile should be used.', - DeprecationWarning) + self.log.warning( + 'Deprecation warning: kojiconfig is deprecated. Instead, ' + 'kojiprofile should be used.') # kojiprofile has higher priority to be used if both kojiconfig and # kojiprofile exist at same time.