From ae175f4d7249af236a803dbff3dad30f45462811 Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:14:53 +0000 Subject: [PATCH] fix: requirements install --- group_data.py | 4 ++++ utils.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 utils.py diff --git a/group_data.py b/group_data.py index 17cbb06..b91ed83 100644 --- a/group_data.py +++ b/group_data.py @@ -2,6 +2,10 @@ from typing import List, Dict, Optional import asyncpg +from .utils import pip_install + +pip_install("cashews") + from cashews import cache from telethon import TelegramClient from telethon.errors import StatsMigrateError diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..c52b363 --- /dev/null +++ b/utils.py @@ -0,0 +1,18 @@ +from typing import Optional +import subprocess +from sys import executable +from importlib.util import find_spec + + +def pip_install( + package: str, version: Optional[str] = "", alias: Optional[str] = "" +) -> bool: + """Auto install extra pypi packages""" + if not alias: + # when import name is not provided, use package name + alias = package + if find_spec(alias) is None: + subprocess.call([executable, "-m", "pip", "install", f"{package}{version}"]) + if find_spec(package) is None: + return False + return True