-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall_deps.py
62 lines (58 loc) · 2.42 KB
/
install_deps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Loop_plugin
A QGIS plugin
This plugin preprocess shapefile inputs to generate python script and json file that are used as input for map2loop
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2022-10-13
copyright : (C) 2022 by Michel M. Nzikou / CET - UWA
email : [email protected]
git sha : $Format:%H$
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
import subprocess,pathlib
import os, sys,glob
def install_module(module_name):
"""
Function to install a Python module using pip
module_name: the module to check
"""
try:
subprocess.run(["pip", "install", module_name])
res = subprocess.run(
["pip", "install", module_name],
capture_output=True,
text=True,
shell=True,
)
print(f"Successfully installed {module_name}")
except subprocess.CalledProcessError:
print(f"Failed to install {module_name}")
# check modules and install if it does not exist
return
def create_requirement_list():
'''
This function read all the module requirement and test whether it exist and if not will install it.
file_path : the qgis main file
'''
plugin_dir = os.path.dirname(os.path.abspath(__file__))
#file_path = os.path.join(str(plugin_dir),'requirements.txt')
file_path = [a for a in glob.glob(plugin_dir+'/*') if 'requirements.txt' in str(a)]
with open(str(file_path[0]), 'r') as file:
req_list =[]
for line in file:
# Process each line here
req_list.append(line.strip())
print(line.strip()) # strip() removes the newline character at the end of each line
return req_list