瀏覽代碼

feat: deprecate the `kosmorrolib.__version__` module

pull/42/head
Jérôme Deuchnord 2 年之前
父節點
當前提交
47b8b1c2b7
共有 2 個文件被更改,包括 26 次插入1 次删除
  1. +16
    -0
      kosmorrolib/__version__.py
  2. +10
    -1
      kosmorrolib/core.py

+ 16
- 0
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 <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"


+ 10
- 1
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


Loading…
取消
儲存