Skip to content

Commit

Permalink
feat: Add version to deprecated function (#3491)
Browse files Browse the repository at this point in the history
* Add the ability to pass a version to the deprecated function to print
  that it will be removed after that version.

Signed-off-by: Ryan Blakley <[email protected]>
  • Loading branch information
ryan-blakley authored Aug 9, 2022
1 parent 77f0196 commit 05459e0
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 43 deletions.
2 changes: 1 addition & 1 deletion insights/combiners/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def hostname(hf, hd, hs, sid):
Raises:
Exception: If no hostname can be found in any of the source parsers.
"""
deprecated(hostname, "Use the `Hostname` class instead.")
deprecated(hostname, "Use the `Hostname` class instead.", "3.0.300")
return Hostname(hf, hd, hs, sid)


Expand Down
3 changes: 2 additions & 1 deletion insights/combiners/modinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class ModInfo(dict):
def __init__(self, mi_all, mi_each):
deprecated(
ModInfo,
'Please use the :class:`insights.parsers.modinfo.KernelModulesInfo` instead.'
"Please use the :class:`insights.parsers.modinfo.KernelModulesInfo` instead.",
"3.1.25"
)
self.retpoline_y = set()
self.retpoline_n = set()
Expand Down
3 changes: 2 additions & 1 deletion insights/combiners/package_provides_httpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class PackageProvidesHttpdAll(LegacyItemAccess):
def __init__(self, package_provides_httpd):
deprecated(
PackageProvidesHttpdAll,
'Please use the :class:`insights.parsers.package_provides.PackageProvidesCommand` instead.'
"Please use the :class:`insights.parsers.package_provides.PackageProvidesCommand` instead.",
"3.0.300"
)
self.data = {}
for pkg in package_provides_httpd:
Expand Down
3 changes: 2 additions & 1 deletion insights/combiners/package_provides_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class PackageProvidesJavaAll(LegacyItemAccess):
def __init__(self, package_provides_java):
deprecated(
PackageProvidesJavaAll,
'Please use the :class:`insights.parsers.package_provides.PackageProvidesCommand` instead.'
"Please use the :class:`insights.parsers.package_provides.PackageProvidesCommand` instead.",
"3.0.300"
)
self.data = {}
for pkg in package_provides_java:
Expand Down
2 changes: 1 addition & 1 deletion insights/combiners/redhat_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def redhat_release(rh_release, un):
"""

deprecated(redhat_release, "Use the `RedHatRelease` class instead.")
deprecated(redhat_release, "Use the `RedHatRelease` class instead.", "3.0.300")

if un and un.release_tuple[0] != -1:
return Release(*un.release_tuple)
Expand Down
2 changes: 1 addition & 1 deletion insights/combiners/uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def uptime(ut):
Raises:
SkipComponent: If no data is available or if ``loadavg`` is not available.
"""
deprecated(uptime, "Use the `Uptime` parser instead.")
deprecated(uptime, "Use the `Uptime` parser instead.", "3.0.300")

if ut.loadavg:
return Uptime(ut.currtime, ut.updays, ut.uphhmm,
Expand Down
2 changes: 1 addition & 1 deletion insights/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,6 @@ class AttributeDict(dict):
"""

def __init__(self, *args, **kwargs):
deprecated(AttributeDict, "Please set attributes explicitly.")
deprecated(AttributeDict, "Please set attributes explicitly.", "3.0.300")
super(AttributeDict, self).__init__(*args, **kwargs)
self.__dict__ = self
2 changes: 1 addition & 1 deletion insights/parsers/aws_instance_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AWSInstanceType(CommandParser):
"""

def __init__(self, *args, **kwargs):
deprecated(AWSInstanceType, "Use AWSInstanceIdDoc in insights.insights.aws_instance_id instead.")
deprecated(AWSInstanceType, "Use AWSInstanceIdDoc in insights.insights.aws_instance_id instead.", "3.0.300")
super(AWSInstanceType, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/corosync.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CoroSyncConfig(SysconfigOptions):
''
"""
def __init__(self, *args, **kwargs):
deprecated(CoroSyncConfig, "Import CorosyncSysconfig from insights.parsers.sysconfig instead")
deprecated(CoroSyncConfig, "Import CorosyncSysconfig from insights.parsers.sysconfig instead.", "3.0.300")
super(CoroSyncConfig, self).__init__(*args, **kwargs)

@property
Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/dirsrv_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DirsrvSysconfig(SysconfigOptions):
Parse the `dirsrv` service's start-up configuration.
"""
def __init__(self, *args, **kwargs):
deprecated(DirsrvSysconfig, "Import DirsrvSysconfig from insights.parsers.sysconfig instead")
deprecated(DirsrvSysconfig, "Import DirsrvSysconfig from insights.parsers.sysconfig instead.", "3.0.300")
super(DirsrvSysconfig, self).__init__(*args, **kwargs)

set_properties = True
6 changes: 5 additions & 1 deletion insights/parsers/docker_storage_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ class DockerStorageSetup(SysconfigOptions):
A parser for accessing /etc/sysconfig/docker-storage-setup.
"""
def __init__(self, *args, **kwargs):
deprecated(DockerStorageSetup, "Import DockerStorageSetupSysconfig from insights.parsers.sysconfig instead")
deprecated(
DockerStorageSetup,
"Import DockerStorageSetupSysconfig from insights.parsers.sysconfig instead.",
"3.0.300"
)
super(DockerStorageSetup, self).__init__(*args, **kwargs)
2 changes: 1 addition & 1 deletion insights/parsers/etc_udev_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ class UdevRules40Redhat(LogFileOutput):
True
"""
def __init__(self, *args, **kwargs):
deprecated(UdevRules40Redhat, "Import UdevRules40Redhat from insights.parsers.udev_rules instread.")
deprecated(UdevRules40Redhat, "Import UdevRules40Redhat from insights.parsers.udev_rules instread.", "3.0.300")
super(UdevRules40Redhat, self).__init__(*args, **kwargs)
6 changes: 5 additions & 1 deletion insights/parsers/foreman_tasks_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ class ForemanTasksConfig(Parser, LegacyItemAccess):
False
"""
def __init__(self, *args, **kwargs):
deprecated(ForemanTasksConfig, "Import ForemanTasksSysconfig from insights.parsers.sysconfig instead")
deprecated(
ForemanTasksConfig,
"Import ForemanTasksSysconfig from insights.parsers.sysconfig instead",
"3.0.300"
)
super(ForemanTasksConfig, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down
4 changes: 2 additions & 2 deletions insights/parsers/ipcs_sem.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class IpcsS(CommandParser):
{'owner': 'postgres', 'perms': '600', 'nsems': '1', 'key': '0x00000000'}
"""
def __init__(self, *args, **kwargs):
deprecated(IpcsS, "Import IpcsS from insights.parsers.ipcs instead")
deprecated(IpcsS, "Import IpcsS from insights.parsers.ipcs instead.", "3.0.300")
super(IpcsS, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down Expand Up @@ -132,7 +132,7 @@ class IpcsSI(CommandParser):
"""
def __init__(self, *args, **kwargs):
deprecated(IpcsSI, "Import IpcsSI from insights.parsers.ipcs instead")
deprecated(IpcsSI, "Import IpcsSI from insights.parsers.ipcs instead.", "3.0.300")
super(IpcsSI, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/ksmstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def is_running(context):
Check if Kernel Samepage Merging is enabled. 'True' if KSM is
on (i.e. ``/sys/kernel/mm/ksm/run`` is '1') or 'False' if not.
"""
deprecated(is_running, "Use the `KSMState` class instead.")
deprecated(is_running, "Use the `KSMState` class instead.", "3.0.300")
ksminfo = {}
ksminfo['running'] = (context.content[0].split()[0] == '1')
return ksminfo
Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/lsvmbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class LsvmBus(CommandParser):
"""
def __init__(self, *args, **kwargs):
deprecated(LsvmBus, "Use the SysVmBusDeviceInfo combiner instead")
deprecated(LsvmBus, "Use the SysVmBusDeviceInfo combiner instead.", "3.0.300")
super(LsvmBus, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down
21 changes: 14 additions & 7 deletions insights/parsers/modinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ class ModInfoAll(KernelModulesInfo):
def __init__(self, *args, **kwargs):
deprecated(
ModInfoAll,
'Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.'
"Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.",
"3.0.300"
)
super(ModInfoAll, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -383,7 +384,8 @@ class ModInfoEach(CommandParser, ModInfo):
def __init__(self, *args, **kwargs):
deprecated(
ModInfoEach,
'Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.'
"Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.",
"3.0.300"
)
super(ModInfoEach, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -451,7 +453,8 @@ class ModInfoI40e(ModInfoEach):
def __init__(self, *args, **kwargs):
deprecated(
ModInfoI40e,
'Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.'
"Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.",
"3.0.300"
)
super(ModInfoI40e, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -498,7 +501,8 @@ class ModInfoVmxnet3(ModInfoEach):
def __init__(self, *args, **kwargs):
deprecated(
ModInfoVmxnet3,
'Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.'
"Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.",
"3.0.300"
)
super(ModInfoVmxnet3, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -546,7 +550,8 @@ class ModInfoIgb(ModInfoEach):
def __init__(self, *args, **kwargs):
deprecated(
ModInfoIgb,
'Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.'
"Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.",
"3.0.300"
)
super(ModInfoIgb, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -594,7 +599,8 @@ class ModInfoIxgbe(ModInfoEach):
def __init__(self, *args, **kwargs):
deprecated(
ModInfoIxgbe,
'Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.'
"Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.",
"3.0.300"
)
super(ModInfoIxgbe, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -634,6 +640,7 @@ class ModInfoVeth(ModInfoEach):
def __init__(self, *args, **kwargs):
deprecated(
ModInfoVeth,
'Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.'
"Please use the :class:`insights.combiners.modinfo.ModulesInfo` instead.",
"3.0.300"
)
super(ModInfoVeth, self).__init__(*args, **kwargs)
2 changes: 1 addition & 1 deletion insights/parsers/multipath_v4_ll.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,5 @@ def get_multipath_v4_ll(context):
.. warning::
Deprecated parser, please use :class:`MultipathDevices` instead.
"""
deprecated(get_multipath_v4_ll, "Use the `MultipathDevices` class instead.")
deprecated(get_multipath_v4_ll, "Use the `MultipathDevices` class instead.", "3.0.300")
return MultipathDevices(context).devices
2 changes: 1 addition & 1 deletion insights/parsers/netconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ class NetConsole(SysconfigOptions, LegacyItemAccess):
``SysconfigOptions`` shared parser class.
'''
def __init__(self, *args, **kwargs):
deprecated(NetConsole, "Import NetconsoleSysconfig from insights.parsers.sysconfig instead")
deprecated(NetConsole, "Import NetconsoleSysconfig from insights.parsers.sysconfig instead.", "3.0.300")
super(NetConsole, self).__init__(*args, **kwargs)
3 changes: 2 additions & 1 deletion insights/parsers/nfs_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def reconstitute(path, d):
"""
deprecated(
NFSExportsBase.reconstitute,
'Please use the `raw_lines` dictionary property of the parser instance'
"Please use the `raw_lines` dictionary property of the parser instance.",
"3.0.300"
)
return " ".join([path] + ["%s(%s)" % (host, ",".join(options))
for host, options in d.items()])
Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/nginx_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class NginxConf(Parser, LegacyItemAccess):
'127.0.0.1:1025'
"""
def __init__(self, *args, **kwargs):
deprecated(NginxConf, "Import NginxConfTree from insights.combiners.nginx_conf instead")
deprecated(NginxConf, "Import NginxConfTree from insights.combiners.nginx_conf instead.", "3.0.300")
super(NginxConf, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down
3 changes: 2 additions & 1 deletion insights/parsers/package_provides_httpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class PackageProvidesHttpd(CommandParser):
def parse_content(self, content):
deprecated(
PackageProvidesHttpd,
'Please use the :class:`insights.parsers.package_provides.PackageProvidesCommand` instead.'
"Please use the :class:`insights.parsers.package_provides.PackageProvidesCommand` instead.",
"3.0.300"
)
if len(content) == 0:
raise SkipException("Error: ", 'there is not httpd application running')
Expand Down
3 changes: 2 additions & 1 deletion insights/parsers/package_provides_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class PackageProvidesJava(CommandParser):
def parse_content(self, content):
deprecated(
PackageProvidesJava,
'Please use the :class:`insights.parsers.package_provides.PackageProvidesCommand` instead.'
"Please use the :class:`insights.parsers.package_provides.PackageProvidesCommand` instead.",
"3.0.300"
)
if len(content) == 0:
raise ParseException("Error: ", 'there is not java application running')
Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/pluginconf_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PluginConfD(LegacyItemAccess, Parser):
#gpgcheck = 0
"""
def parse_content(self, content):
deprecated(PluginConfD, "Deprecated. Use 'PluginConfDIni' instead.")
deprecated(PluginConfD, "Deprecated. Use 'PluginConfDIni' instead.", "3.0.300")
plugin_dict = {}
section_dict = {}
key = None
Expand Down
6 changes: 5 additions & 1 deletion insights/parsers/puppetserver_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class PuppetserverConfig(Parser, LegacyItemAccess):
False
"""
def __init__(self, *args, **kwargs):
deprecated(PuppetserverConfig, "Import PuppetserverSysconfig from insights.parsers.sysconfig instead")
deprecated(
PuppetserverConfig,
"Import PuppetserverSysconfig from insights.parsers.sysconfig instead.",
"3.0.300"
)
super(PuppetserverConfig, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down
6 changes: 5 additions & 1 deletion insights/parsers/satellite_postgresql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ class SatelliteKatelloEmptyURLRepositories(SatellitePostgreSQLQuery):
columns = ['id', 'name']

def __init__(self, *args, **kwargs):
deprecated(SatelliteKatelloEmptyURLRepositories, 'Please use the SatelliteQualifiedKatelloRepos parser in the current module.')
deprecated(
SatelliteKatelloEmptyURLRepositories,
"Please use the SatelliteQualifiedKatelloRepos parser in the current module.",
"3.1.25"
)
super(SatelliteKatelloEmptyURLRepositories, self).__init__(*args, **kwargs)


Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/systemctl_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class SystemctlShow(CommandParser, dict):
In CMD's output, empty properties are suppressed by default.
"""
def __init__(self, *args, **kwargs):
deprecated(SystemctlShow, "Deprecated. Use 'SystemctlShowServiceAll' instead.")
deprecated(SystemctlShow, "Deprecated. Use 'SystemctlShowServiceAll' instead.", "3.0.300")
super(SystemctlShow, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/systemd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class MultiOrderedDict(dict):
"""

def __init__(self, *args, **kwargs):
deprecated(MultiOrderedDict, "This class is deprecated")
deprecated(MultiOrderedDict, "This class is deprecated.", "3.0.300")
super(MultiOrderedDict, self).__init__(*args, **kwargs)

def __setitem__(self, key, value):
Expand Down
2 changes: 1 addition & 1 deletion insights/parsers/up2date.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Up2Date(LegacyItemAccess, Parser):
serverURL=https://rhnproxy.glb.tech.markit.partners/XMLRPC
"""
def __init__(self, *args, **kwargs):
deprecated(Up2Date, "Import Up2DateSysconfig from insights.parsers.sysconfig instead")
deprecated(Up2Date, "Import Up2DateSysconfig from insights.parsers.sysconfig instead.", "3.0.300")
super(Up2Date, self).__init__(*args, **kwargs)

def parse_content(self, content):
Expand Down
4 changes: 2 additions & 2 deletions insights/parsers/yum_list_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class YumInstalledRpm(InstalledRpm):
with an additional ``.repo`` attribute.
"""
def __init__(self, data):
deprecated(YumInstalledRpm, "Import YumListRpm from insights.parsers.yum_list instead")
deprecated(YumInstalledRpm, "Import YumListRpm from insights.parsers.yum_list instead.", "3.0.300")
self.repo = None
"""str: yum / dnf repository name, if available."""

Expand All @@ -38,7 +38,7 @@ class YumListInstalled(CommandParser, RpmList):
"""

def __init__(self, context):
deprecated(YumListInstalled, "Import YumListBase from insights.parsers.yum_list instead")
deprecated(YumListInstalled, "Import YumListBase from insights.parsers.yum_list instead.", "3.0.300")
self.expired_cache = False
"""bool: Indicates if the yum repo cache is expired."""

Expand Down
16 changes: 11 additions & 5 deletions insights/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def check_log_level(*args, **kwargs):
return _f


def deprecated(func, solution):
def deprecated(func, solution, version=None):
"""
Mark a parser or combiner as deprecated, and give a message of how to fix
this. This will emit a warning in the logs when the function is used.
Expand All @@ -156,8 +156,9 @@ def deprecated(func, solution):
function that replaces the thing being deprecated. For example,
"use the `fnord()` function" or "use the `search()` method with
the parameter `name='(value)'`".
version (str): The last version of insights-core that the function
will be available before it is removed.
"""

def get_name_line(src):
for line in src:
if "@" not in line:
Expand All @@ -166,9 +167,14 @@ def get_name_line(src):
path = inspect.getsourcefile(func)
src, line_no = inspect.getsourcelines(func)
name = get_name_line(src) or "Unknown"
the_msg = "<{c}> at {p}:{l} is deprecated: {s}".format(
c=name, p=path, l=line_no, s=solution
)
if version:
the_msg = "<{c}> at {p}:{l} is deprecated: {s} This function will be removed after version: {v}.".format(
c=name, p=path, l=line_no, s=solution, v=version
)
else:
the_msg = "<{c}> at {p}:{l} is deprecated: {s}".format(
c=name, p=path, l=line_no, s=solution
)

warnings.warn(the_msg, DeprecationWarning)

Expand Down

0 comments on commit 05459e0

Please sign in to comment.