diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-11-19 14:52:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-11-19 14:53:01 +0000 |
commit | f3b6c222fb11c96e2f8bbaa0622f46c8ec486874 (patch) | |
tree | 0f38497775e27d3e16b20573b36dd22aa5b24f3e /gitlint-core/gitlint/deprecation.py | |
parent | Releasing debian version 0.17.0-1. (diff) | |
download | gitlint-f3b6c222fb11c96e2f8bbaa0622f46c8ec486874.tar.xz gitlint-f3b6c222fb11c96e2f8bbaa0622f46c8ec486874.zip |
Merging upstream version 0.18.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gitlint-core/gitlint/deprecation.py')
-rw-r--r-- | gitlint-core/gitlint/deprecation.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gitlint-core/gitlint/deprecation.py b/gitlint-core/gitlint/deprecation.py new file mode 100644 index 0000000..bf13460 --- /dev/null +++ b/gitlint-core/gitlint/deprecation.py @@ -0,0 +1,40 @@ +import logging + + +LOG = logging.getLogger("gitlint.deprecated") +DEPRECATED_LOG_FORMAT = "%(levelname)s: %(message)s" + + +class Deprecation: + """Singleton class that handles deprecation warnings and behavior.""" + + # LintConfig class that is used to determine deprecation behavior + config = None + + # Set of warning messages that have already been logged, to prevent duplicate warnings + warning_msgs = set() + + @classmethod + def get_regex_method(cls, rule, regex_option): + """Returns the regex method to be used for a given rule based on general.regex-style-search option. + Logs a warning if the deprecated re.match method is returned.""" + + # if general.regex-style-search is set, just return re.search + if cls.config.regex_style_search: + return regex_option.value.search + + warning_msg = ( + f"{rule.id} - {rule.name}: gitlint will be switching from using Python regex 'match' (match beginning) to " + "'search' (match anywhere) semantics. " + f"Please review your {rule.name}.regex option accordingly. " + "To remove this warning, set general.regex-style-search=True. " + "More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search" + ) + + # Only log warnings once + if warning_msg not in cls.warning_msgs: + log = logging.getLogger("gitlint.deprecated.regex_style_search") + log.warning(warning_msg) + cls.warning_msgs.add(warning_msg) + + return regex_option.value.match |