Skip to content

Commit

Permalink
feat: deprecate the kosmorrolib.__version__ module (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deuchnord authored and Jérôme Deuchnord committed Nov 12, 2023
1 parent 29b9f55 commit f8e893b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions kosmorrolib/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

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"
Expand Down
11 changes: 10 additions & 1 deletion kosmorrolib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f8e893b

Please sign in to comment.