From f8e893bfc269afef14d3e7ccbbade84ccf4590d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Deuchnord?= Date: Wed, 2 Feb 2022 13:15:26 +0100 Subject: [PATCH] feat: deprecate the `kosmorrolib.__version__` module (#42) --- kosmorrolib/__version__.py | 16 ++++++++++++++++ kosmorrolib/core.py | 11 ++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/kosmorrolib/__version__.py b/kosmorrolib/__version__.py index df9e74b..3e70110 100644 --- a/kosmorrolib/__version__.py +++ b/kosmorrolib/__version__.py @@ -16,6 +16,22 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from core import alert_deprecation +from sys import version_info + +python_version = (version_info.major, version_info.minor) +msg_python = ( + '\nOn Python 3.7, you can also use the "importlib-metadata" package.' + if python_version == (3, 7) + else "" +) + +alert_deprecation( + 'Module "kosmorrolib.__version__" is deprecated since version 1.1. ' + "Use the importlib.metadata module provided by Python 3.8+: " + "https://docs.python.org/3/library/importlib.metadata.html." + msg_python +) + __title__ = "kosmorrolib" __description__ = "A library to compute your ephemerides" __url__ = "http://kosmorro.space/lib" diff --git a/kosmorrolib/core.py b/kosmorrolib/core.py index 3424ab0..f499852 100644 --- a/kosmorrolib/core.py +++ b/kosmorrolib/core.py @@ -51,10 +51,19 @@ def flatten_list(the_list: list): return new_list +def alert_deprecation(message): + """Show the given message as a deprecation warning. + + >>> alert_deprecation("This is deprecated.") + sys:1: DeprecationWarning: This is deprecated. + """ + warn(message, DeprecationWarning, stacklevel=2) + + def deprecated(message): def inner(decorated): def f(*args, **kwargs): - warn(message, DeprecationWarning, stacklevel=2) + alert_deprecation(message) return decorated(*args, **kwargs) return f