Improved install command

This commit is contained in:
2021-03-14 10:31:45 +01:00
parent 6094b11068
commit e7796e0371
3 changed files with 71 additions and 18 deletions

View File

@@ -1,12 +1,19 @@
import subprocess
import sys
from contextlib import suppress
from typing import Optional
class Pip:
@staticmethod
def get_package(package: str) -> str:
result = subprocess.check_output([sys.executable, "-m", "pip", "show", package])
def get_package(package: str) -> Optional[str]:
result = None
with suppress(Exception):
result = subprocess.check_output([sys.executable, "-m", "pip", "show", package], stderr=subprocess.DEVNULL)
if result is None:
return None
new_package: list[str] = str(result, 'utf-8').lower().split('\n')
new_version = ''