1
+ import importlib
1
2
import os
2
- import sys
3
- import subprocess
4
3
import site
5
- import importlib
4
+ import subprocess
5
+ import sys
6
6
from pathlib import Path
7
7
8
+ import pathlib # For testing purposes
8
9
import click
10
+ import geonature .utils .config
9
11
from click import ClickException
10
-
11
- from geonature .utils .env import ROOT_DIR
12
- from geonature .utils .module import iter_modules_dist , get_dist_from_code , module_db_upgrade
13
-
14
12
from geonature .core .command .main import main
15
- import geonature .utils .config
16
- from geonature .utils .config import config
17
13
from geonature .utils .command import (
18
- install_frontend_dependencies ,
19
- create_frontend_module_config ,
20
14
build_frontend ,
15
+ create_frontend_module_config ,
16
+ install_frontend_dependencies ,
21
17
)
18
+ from geonature .utils .config import config
19
+ from geonature .utils .env import ROOT_DIR
20
+ from geonature .utils .module import get_dist_from_code , iter_modules_dist , module_db_upgrade
22
21
23
22
24
23
@main .command ()
30
29
@click .option ("--build" , type = bool , required = False , default = True )
31
30
@click .option ("--upgrade-db" , type = bool , required = False , default = True )
32
31
def install_gn_module (x_arg , module_path , module_code , build , upgrade_db ):
32
+ """
33
+ Command definition to install a GeoNature module
34
+
35
+ Parameters
36
+ ----------
37
+ x_arg : list
38
+ additional arguments
39
+ module_path : str
40
+ path of the module directory
41
+ module_code : str
42
+ code of the module, deprecated in future release
43
+ build : boolean
44
+ is the frontend rebuild
45
+ upgrade_db : boolean
46
+ migrate the revision associated with the module
47
+
48
+ Raises
49
+ ------
50
+ ClickException
51
+ No module found with the given module code
52
+ ClickException
53
+ No module code was detected in the code
54
+ """
33
55
click .echo ("Installation du backend…" )
34
56
subprocess .run (f"pip install -e '{ module_path } '" , shell = True , check = True )
35
57
@@ -40,7 +62,7 @@ def install_gn_module(x_arg, module_path, module_code, build, upgrade_db):
40
62
if module_code :
41
63
# load python package
42
64
module_dist = get_dist_from_code (module_code )
43
- if not module_dist :
65
+ if not module_dist : # FIXME : technically can't go there...
44
66
raise ClickException (f"Aucun module ayant pour code { module_code } n’a été trouvé" )
45
67
else :
46
68
for module_dist in iter_modules_dist ():
@@ -56,7 +78,6 @@ def install_gn_module(x_arg, module_path, module_code, build, upgrade_db):
56
78
raise ClickException (
57
79
f"Impossible de détecter le code du module, essayez de le spécifier."
58
80
)
59
-
60
81
# symlink module in exernal module directory
61
82
module_frontend_path = (module_path / "frontend" ).resolve ()
62
83
module_symlink = ROOT_DIR / "frontend" / "external_modules" / module_code .lower ()
@@ -68,7 +89,6 @@ def install_gn_module(x_arg, module_path, module_code, build, upgrade_db):
68
89
else :
69
90
click .echo (f"Création du lien symbolique { module_symlink } → { module_frontend_path } " )
70
91
os .symlink (module_frontend_path , module_symlink )
71
-
72
92
if (Path (module_path ) / "frontend" / "package-lock.json" ).is_file ():
73
93
click .echo ("Installation des dépendances frontend…" )
74
94
install_frontend_dependencies (module_frontend_path )
@@ -80,7 +100,6 @@ def install_gn_module(x_arg, module_path, module_code, build, upgrade_db):
80
100
click .echo ("Rebuild du frontend …" )
81
101
build_frontend ()
82
102
click .secho ("Rebuild du frontend terminé." , fg = "green" )
83
-
84
103
if upgrade_db :
85
104
click .echo ("Installation / mise à jour de la base de données…" )
86
105
if not module_db_upgrade (module_dist , x_arg = x_arg ):
0 commit comments