Skip to content

Commit 6f73309

Browse files
committed
feat: deprecate the kosmorrolib.__version__ module (#42)
1 parent 6c8d5cf commit 6f73309

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

kosmorrolib/__version__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
# You should have received a copy of the GNU Affero General Public License
1717
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

19+
from core import alert_deprecation
20+
from sys import version_info
21+
22+
python_version = (version_info.major, version_info.minor)
23+
msg_python = (
24+
'\nOn Python 3.7, you can also use the "importlib-metadata" package.'
25+
if python_version == (3, 7)
26+
else ""
27+
)
28+
29+
alert_deprecation(
30+
'Module "kosmorrolib.__version__" is deprecated since version 1.1. '
31+
"Use the importlib.metadata module provided by Python 3.8+: "
32+
"https://docs.python.org/3/library/importlib.metadata.html." + msg_python
33+
)
34+
1935
__title__ = "kosmorrolib"
2036
__description__ = "A library to compute your ephemerides"
2137
__url__ = "http://kosmorro.space/lib"

kosmorrolib/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,19 @@ def flatten_list(the_list: list):
5151
return new_list
5252

5353

54+
def alert_deprecation(message):
55+
"""Show the given message as a deprecation warning.
56+
57+
>>> alert_deprecation("This is deprecated.")
58+
sys:1: DeprecationWarning: This is deprecated.
59+
"""
60+
warn(message, DeprecationWarning, stacklevel=2)
61+
62+
5463
def deprecated(message):
5564
def inner(decorated):
5665
def f(*args, **kwargs):
57-
warn(message, DeprecationWarning, stacklevel=2)
66+
alert_deprecation(message)
5867
return decorated(*args, **kwargs)
5968

6069
return f

0 commit comments

Comments
 (0)