a
This commit is contained in:
parent
b6da0e3c93
commit
fdfcf36e4e
1 changed files with 46 additions and 46 deletions
|
@ -1,60 +1,60 @@
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
import subprocess as sp
|
# import subprocess as sp
|
||||||
import requests
|
# import requests
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from decouple import config
|
# from decouple import config
|
||||||
|
|
||||||
# def install_available(pipfile):
|
# def install_available(pipfile):
|
||||||
""" Install Python packages or their dependencies mentioned in
|
# """ Install Python packages or their dependencies mentioned in
|
||||||
pipfile if they are available in System repos
|
# pipfile if they are available in System repos
|
||||||
"""
|
# """
|
||||||
|
|
||||||
def is_available_in_system_repos(package):
|
# def is_available_in_system_repos(package):
|
||||||
try:
|
# try:
|
||||||
sp.check_output(['apk', 'info', f'py3-{package}'])
|
# sp.check_output(['apk', 'info', f'py3-{package}'])
|
||||||
except:
|
# except:
|
||||||
return False
|
# return False
|
||||||
else:
|
# else:
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
if get_distro_name() == "alpine":
|
# if get_distro_name() == "alpine":
|
||||||
dependencies = []
|
# dependencies = []
|
||||||
|
|
||||||
need_to_be_installed = []
|
# need_to_be_installed = []
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
with open(pipfile) as f:
|
# with open(pipfile) as f:
|
||||||
lines = f.readlines()
|
# lines = f.readlines()
|
||||||
try:
|
# try:
|
||||||
start_index = lines.index("[packages]\n")
|
# start_index = lines.index("[packages]\n")
|
||||||
end_index = lines.index("\n", start_index)
|
# end_index = lines.index("\n", start_index)
|
||||||
for package in lines[start_index: end_index]:
|
# for package in lines[start_index: end_index]:
|
||||||
if '= "*"' in package:
|
# if '= "*"' in package:
|
||||||
package = package[:package.index(" =")]
|
# package = package[:package.index(" =")]
|
||||||
if is_available_in_system_repos(package):
|
# if is_available_in_system_repos(package):
|
||||||
need_to_be_installed.append(f"py3-{package}")
|
# need_to_be_installed.append(f"py3-{package}")
|
||||||
else:
|
# else:
|
||||||
dependencies.append(package)
|
# dependencies.append(package)
|
||||||
except ValueError:
|
# except ValueError:
|
||||||
print("Not Found")
|
# print("Not Found")
|
||||||
except:
|
# except:
|
||||||
return
|
# return
|
||||||
else:
|
# else:
|
||||||
for dependency in dependencies:
|
# for dependency in dependencies:
|
||||||
content = requests.get(f"https://libraries.io/api/pypi/{dependency}/latest/dependencies?api_key={config('LIBRARIES_IO_API')}")
|
# content = requests.get(f"https://libraries.io/api/pypi/{dependency}/latest/dependencies?api_key={config('LIBRARIES_IO_API')}")
|
||||||
content = json.loads(content.content.decode("utf-8"))
|
# content = json.loads(content.content.decode("utf-8"))
|
||||||
for subdependency in content["dependencies"]:
|
# for subdependency in content["dependencies"]:
|
||||||
subdependency = subdependency["name"]
|
# subdependency = subdependency["name"]
|
||||||
if is_available_in_system_repos(subdependency):
|
# if is_available_in_system_repos(subdependency):
|
||||||
need_to_be_installed.append(f"py3-{subdependency}")
|
# need_to_be_installed.append(f"py3-{subdependency}")
|
||||||
|
|
||||||
for package in need_to_be_installed:
|
# for package in need_to_be_installed:
|
||||||
try:
|
# try:
|
||||||
sp.check_output(["apk", "add", package])
|
# sp.check_output(["apk", "add", package])
|
||||||
except:
|
# except:
|
||||||
print(f"Could not install {package}")
|
# print(f"Could not install {package}")
|
||||||
|
|
||||||
def install_available(project_path):
|
def install_available(project_path):
|
||||||
if get_distro_name() == "alpine":
|
if get_distro_name() == "alpine":
|
||||||
|
|
Loading…
Reference in a new issue