| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
s, |
| 23 |
). |
| 24 |
|
| •25 |
import sys, importlib, platform, os, shutil, subprocess |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
from .version import NOMPROG |
| 32 |
|
| 33 |
|
| 34 |
dependances = {'PyQt5': 'python3-pyqt5', |
| 35 |
'matplotlib': 'python3-matplotlib', |
| 36 |
'scipy': 'python3-scipy', |
| 37 |
'numpy': 'python3-numpy', |
| 38 |
'mpmath': 'python3-mpmath', |
| 39 |
'PyQt5.Qsci': 'python3-pyqt5.qsci', |
| 40 |
'PyQt5.QtSvg': 'python3-pyqt5.qtsvg', |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
pip_packages = {'PyQt5.Qsci': 'Qscintilla', |
| 47 |
'PyQt5.QtSvg': '', |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
python_version_min = (3, 5) |
| 52 |
python_version_max = (3, 99) |
| 53 |
|
| 54 |
plateforme = platform.system() |
| 55 |
|
| 56 |
b |
| 57 |
) |
| 58 |
latex = False |
| 59 |
latex_unicode = True |
| 60 |
moteur_de_rendu = 'Qt5Agg' |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
def tester_dependances(): |
| 66 |
""" |
| 67 |
Cette procédure teste si la liste des dépendances est à jour. Dans le cas |
| 68 |
contraire, elle émet comme message une suite de commandes que |
| 69 |
l'utilisateur peut lancer (s'il est administrateur/sudoer) afin de |
| 70 |
satisfaire la liste des dépendances. |
| 71 |
""" |
| 72 |
if hasattr(sys, 'frozen'): |
| 73 |
. |
| 74 |
return |
| 75 |
|
| 76 |
version_python_supportee = True |
| 77 |
if sys.version_info[:2] < python_version_min: |
| 78 |
print(" ** Erreur fatale **") |
| 79 |
print(NOMPROG + " nécessite Python %d.%d au minimum." % python_version_min) |
| 80 |
version_python_supportee = False |
| 81 |
elif sys.version_info[:2] > python_version_max: |
| 82 |
print(" ** Erreur fatale **") |
| 83 |
print(NOMPROG + " supporte Python %d.%d au maximum." % python_version_max) |
| 84 |
version_python_supportee = False |
| 85 |
|
| 86 |
if not version_python_supportee: |
| 87 |
print("Python %d.%d détecté." % sys.version_info[:2]) |
| 88 |
sys.exit(-1) |
| 89 |
|
| 90 |
|
| 91 |
modules_manquants = [] |
| 92 |
for module in dependances: |
| 93 |
module_name = module |
| 94 |
try: |
| •95 |
importlib.import_module(module) |
| 96 |
except ModuleNotFoundError: |
| 97 |
modules_manquants.append(module_name) |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
if modules_manquants: |
| 102 |
try: |
| 103 |
if not sys.stdin.isatty(): |
| 104 |
raise ImportError |
| 105 |
if input(f"Certaines librairies manquent : {modules_manquants}.\n" |
| 106 |
"Voulez-vous les installer automatiquement ? (o/N)" |
| 107 |
).lower() not in ('o', 'oui', 'yes', 'y'): |
| 108 |
raise ImportError |
| 109 |
|
| 110 |
pip_modules = [pip_packages.get(module, module) for module in modules_manquants] |
| 111 |
try: |
| 112 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user'] + pip_modules) |
| 113 |
except subprocess.CalledProcessError: |
| 114 |
|
| 115 |
try: |
| 116 |
subprocess.check_call([sys.executable, '-m', 'pip', 'install'] + pip_modules) |
| 117 |
except subprocess.CalledProcessError: |
| 118 |
print("L'installation automatique des modules manquants a échouée.") |
| 119 |
raise ImportError |
| 120 |
print('Des modules indispensables ont été installés.') |
| 121 |
print('Redémarrage de Géophar...') |
| 122 |
os.execv(sys.executable, [sys.executable] + sys.argv) |
| 123 |
sys.exit() |
| 124 |
except ImportError: |
| 125 |
if plateforme == 'Linux' and shutil.which('apt'): |
| 126 |
paquets = ' '.join(dependances[m] for m in modules_manquants) |
| 127 |
print(f""" |
| 128 |
[\033[91mERREUR\033[39m] Certains paquets sont manquants : {paquets}. |
| 129 |
|
| 130 |
Votre distribution semble être dérivée de Debian ou d'Ubuntu, |
| 131 |
il est possible de remédier à cette situation en lançant la commande : |
| 132 |
---------------------------------------------------------------------- |
| 133 |
\033[1m\ |
| 134 |
sudo apt update; sudo apt install {paquets}\ |
| 135 |
\033[0m |
| 136 |
---------------------------------------------------------------------- |
| 137 |
Vous pourrez ensuite relancer Géophar. |
| 138 |
""") |
| 139 |
else: |
| 140 |
print('** Erreur fatale **\nLes modules suivants sont introuvables !') |
| 141 |
print('MODULE(S) MANQUANT(S): %s.' % ', '.join(modules_manquants)) |
| 142 |
sys.exit(-1) |
| 143 |
|
| 144 |
|
| 145 |
def configurer_dependances(): |
| 146 |
import PyQt5 |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
try: |
| 152 |
|
| 153 |
import pyparsing |
| 154 |
except ImportError: |
| 155 |
pass |
| 156 |
import matplotlib |
| 157 |
matplotlib.rcParams['backend'] = 'Qt5Agg' |
| 158 |
try: |
| 159 |
|
| 160 |
if matplotlib.__version__.split(".")[0] < '3': |
| 161 |
matplotlib.rcParams['backend.qt5'] ='PyQt5' |
| 162 |
matplotlib.rcParams["text.latex.unicode"] = latex_unicode |
| 163 |
except KeyError: |
| 164 |
pass |
| 165 |
matplotlib.use(moteur_de_rendu) |
| 166 |
matplotlib.rcParams['text.usetex'] = latex |
| 167 |
|
| 168 |
|
| 169 |
matplotlib.rcParams['font.family'] ='serif' |
| 170 |
|
| 171 |
matplotlib.rcParams['font.serif'] ='STIXGeneral' |
| 172 |
|
| 173 |
matplotlib.rcParams['mathtext.fontset'] ='stix' |
| 174 |
|