feat: dependencies version check
This commit is contained in:
parent
15debf339d
commit
9bc3d9b29d
@ -45,8 +45,8 @@ from . import environment, utils
|
|||||||
|
|
||||||
# TODO: remove dependency as soon as replication will be installed as a module
|
# TODO: remove dependency as soon as replication will be installed as a module
|
||||||
DEPENDENCIES = {
|
DEPENDENCIES = {
|
||||||
"replication",
|
("replication", '0.0.11'),
|
||||||
"deepdiff",
|
("deepdiff", '5.0.1'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import socket
|
import socket
|
||||||
|
import re
|
||||||
|
|
||||||
|
VERSION_EXPR = re.compile('\d+\.\d+\.\d+')
|
||||||
|
|
||||||
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
||||||
DEFAULT_CACHE_DIR = os.path.join(
|
DEFAULT_CACHE_DIR = os.path.join(
|
||||||
@ -47,14 +50,22 @@ def install_pip():
|
|||||||
subprocess.run([str(PYTHON_PATH), "-m", "ensurepip"])
|
subprocess.run([str(PYTHON_PATH), "-m", "ensurepip"])
|
||||||
|
|
||||||
|
|
||||||
def install_package(name):
|
def install_package(name, version):
|
||||||
logging.debug(f"Using {PYTHON_PATH} for installation")
|
logging.info(f"installing {name} version...")
|
||||||
subprocess.run([str(PYTHON_PATH), "-m", "pip", "install", name])
|
subprocess.run([str(PYTHON_PATH), "-m", "pip", "install", f"{name}=={version}"])
|
||||||
|
|
||||||
|
def check_package_version(name, required_version):
|
||||||
|
logging.info(f"Checking {name} version...")
|
||||||
|
out = subprocess.run(f"{str(PYTHON_PATH)} -m pip show {name}", capture_output=True)
|
||||||
|
|
||||||
def upgrade_package(name):
|
version = VERSION_EXPR.search(out.stdout.decode())
|
||||||
logging.debug(f"Using {PYTHON_PATH} for update")
|
|
||||||
subprocess.run([str(PYTHON_PATH), "-m", "pip", "install", name, "--upgrade"])
|
if version and version.group() == required_version:
|
||||||
|
logging.info(f"{name} is up to date")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logging.info(f"{name} need an update")
|
||||||
|
return False
|
||||||
|
|
||||||
def get_ip():
|
def get_ip():
|
||||||
"""
|
"""
|
||||||
@ -82,9 +93,9 @@ def setup(dependencies, python_path):
|
|||||||
if not module_can_be_imported("pip"):
|
if not module_can_be_imported("pip"):
|
||||||
install_pip()
|
install_pip()
|
||||||
|
|
||||||
for package_name in dependencies:
|
for package_name, package_version in dependencies:
|
||||||
if not module_can_be_imported(package_name):
|
if not module_can_be_imported(package_name):
|
||||||
install_package(package_name)
|
install_package(package_name, package_version)
|
||||||
module_can_be_imported(package_name)
|
module_can_be_imported(package_name)
|
||||||
else:
|
elif not check_package_version(package_name, package_version):
|
||||||
upgrade_package(package_name)
|
install_package(package_name, package_version)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user