-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
101 lines (90 loc) · 3.64 KB
/
__init__.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
"""
/***************************************************************************
PyPopRF
A QGIS plugin
A plugin for population prediction and dasymetric mapping using machine learning
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2025-01-07
copyright : (C) 2025 by WorldPop SDI Team
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 importlib
import os
import subprocess
import sys
from pathlib import Path
import platform
def classFactory(iface): # pylint: disable=invalid-name
"""Load PyPopRF class from file PyPopRF.
:param iface: A QGIS interface instance.
:type iface: QgsInterface
"""
plugin_dir = Path(__file__).parent
deps_path = os.path.join(plugin_dir, "deps")
if not os.path.exists(deps_path):
requirements_path = os.path.join(plugin_dir, "requirements.txt")
# Determine OS and Python executable
system = platform.system().lower()
if system == "windows":
python = os.path.join(os.environ.get("PYTHONHOME"), "python.exe")
platform_tag = "win_amd64"
elif system == "linux":
python = "python3"
platform_tag = "manylinux2014_x86_64"
elif system == "darwin":
python = "python3"
platform_tag = "macosx_10_14_x86_64"
else:
raise OSError(f"Unsupported operating system: {system}")
try:
# First attempt: with platform-specific wheels
subprocess.check_call(
[
python,
"-m",
"pip",
"install",
"-r",
requirements_path,
"--platform",
platform_tag,
"--only-binary=:all:",
f"--target={deps_path}",
]
)
except subprocess.CalledProcessError as e:
try:
# Second attempt: without platform specifications
subprocess.check_call(
[
python,
"-m",
"pip",
"install",
"-r",
requirements_path,
f"--target={deps_path}",
]
)
except subprocess.CalledProcessError as e:
raise RuntimeError(
f"Failed to install dependencies for {system} ({platform_tag}). Error: {str(e)}"
)
if deps_path not in sys.path:
sys.path.insert(1, deps_path)
importlib.invalidate_caches()
from .qgis_pypoprf import PyPopRF
return PyPopRF(iface)