Skip to content

Commit

Permalink
🔧 refactor(cli): update import handling for metadata module
Browse files Browse the repository at this point in the history
- Use try-except to support importlib.metadata for Python <3.8
- Move CURRENT_VERSION assignment into check_for_updates function
  • Loading branch information
sudoskys committed Oct 5, 2024
1 parent cbd9763 commit 9d8bf79
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/tsticker/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import atexit
import importlib.metadata as metadata
import os
import pathlib
from asyncio import Semaphore
Expand All @@ -25,9 +24,12 @@
from tsticker.core.const import SERVICE_NAME, USERNAME
from tsticker.core.create import StickerPack, Emote

CURRENT_VERSION = metadata.version("tsticker")
PYPI_URL = "https://pypi.org/pypi/tsticker/json"
try:
from importlib import metadata
except ImportError: # for Python<3.8
import importlib_metadata as metadata

PYPI_URL = "https://pypi.org/pypi/tsticker/json"
magika = Magika()
console = Console()
# 全局请求限制器
Expand All @@ -36,12 +38,12 @@


async def check_for_updates():
CURRENT_VERSION = metadata.version("tsticker")
try:
response = requests.get(PYPI_URL)
if response.status_code == 200:
package_info = response.json()
latest_version = package_info['info']['version']

if latest_version != CURRENT_VERSION:
release_notes = package_info['releases'].get(latest_version, [])
release_info = release_notes[0] if release_notes else {}
Expand Down

0 comments on commit 9d8bf79

Please sign in to comment.