Skip to content

Commit 5ad2622

Browse files
committed
feat: ajout de la gestion globale de l'activation BCASL via ark.yml
- Ajout d'une case à cocher 'Activer BCASL' dans le dialogue du pipeline. - Déplacement de la source de vérité de l'activation de bcasl.yml vers ark.yml (plugins.bcasl_enabled). - Mise à jour du chargeur BCASL pour respecter la configuration ark.yml. - Nettoyage automatique du champ 'enabled' dans bcasl.yml. - Mise à jour de la documentation technique.
1 parent 100aaea commit 5ad2622

4 files changed

Lines changed: 71 additions & 20 deletions

File tree

Ui/Gui/Dialogs/BcaslDialog.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import yaml
3535

36+
from Core.Configs import load_ark_config, save_ark_config
37+
3638
from PySide6.QtCore import Qt, Signal, QMimeData, QByteArray, QObject, QThread, Slot
3739
from PySide6.QtGui import QColor, QShortcut, QKeySequence, QPalette
3840
from PySide6.QtWidgets import (
@@ -488,6 +490,12 @@ def __init__(
488490
self._cfg = cfg
489491
self._plugin_instances = plugin_instances
490492

493+
# Charger la configuration ark.yml pour l'état d'activation global
494+
try:
495+
self._ark_cfg = load_ark_config(workspace_root)
496+
except Exception:
497+
self._ark_cfg = {}
498+
491499
# Expert mode : liste mutable partagée avec les rows
492500
self._expert: list[bool] = [False]
493501

@@ -521,6 +529,15 @@ def _build_ui(self) -> None:
521529
lbl.setTextFormat(Qt.RichText)
522530
title_row.addWidget(lbl)
523531
title_row.addStretch(1)
532+
533+
# Case à cocher pour l'activation globale (gérée par ark.yml)
534+
self._chk_bcasl_enabled = QCheckBox(self._gui.tr("Activer BCASL", "Enable BCASL"))
535+
self._chk_bcasl_enabled.setStyleSheet("font-weight: bold;")
536+
bcasl_active = self._ark_cfg.get("plugins", {}).get("bcasl_enabled", True)
537+
self._chk_bcasl_enabled.setChecked(bool(bcasl_active))
538+
self._chk_bcasl_enabled.toggled.connect(self._on_bcasl_enabled_toggled)
539+
title_row.addWidget(self._chk_bcasl_enabled)
540+
524541
main.addLayout(title_row)
525542

526543
# Tabs : Pipeline + onglets plugins
@@ -577,6 +594,17 @@ def _build_ui(self) -> None:
577594

578595
main.addLayout(bottom)
579596

597+
# Initialiser l'état des onglets en fonction de l'activation
598+
self._on_bcasl_enabled_toggled(self._chk_bcasl_enabled.isChecked())
599+
600+
def _on_bcasl_enabled_toggled(self, checked: bool) -> None:
601+
"""Active ou désactive les onglets de configuration selon l'état global."""
602+
self._tabs.setEnabled(checked)
603+
if not checked:
604+
self._tabs.setToolTip(self._gui.tr("BCASL est désactivé dans ark.yml", "BCASL is disabled in ark.yml"))
605+
else:
606+
self._tabs.setToolTip("")
607+
580608
def _populate_sections(self) -> None:
581609
"""Grouper les plugins par section et les insérer."""
582610
plugins_raw = self._cfg.get("plugins", {}) if isinstance(self._cfg, dict) else {}
@@ -772,7 +800,20 @@ def _collect_plugin_configs(self) -> dict[str, dict]:
772800
def _do_save(self) -> None:
773801
plugin_configs = self._collect_plugin_configs()
774802

775-
# Construire la liste ordonnée de plugins
803+
# 1) Sauvegarder l'état d'activation global dans ark.yml
804+
try:
805+
if "plugins" not in self._ark_cfg:
806+
self._ark_cfg["plugins"] = {}
807+
self._ark_cfg["plugins"]["bcasl_enabled"] = self._chk_bcasl_enabled.isChecked()
808+
save_ark_config(str(self._workspace_root), self._ark_cfg)
809+
except Exception as e:
810+
QMessageBox.warning(
811+
self,
812+
self._gui.tr("Avertissement", "Warning"),
813+
f"Impossible de mettre à jour ark.yml: {e}"
814+
)
815+
816+
# 2) Construire la liste ordonnée de plugins pour bcasl.yml
776817
ordered: list[dict[str, Any]] = []
777818
for section in self._sections:
778819
for row in section.rows:
@@ -784,11 +825,15 @@ def _do_save(self) -> None:
784825
"config": cfg_for_row,
785826
})
786827

787-
# Construire la config de sortie
828+
# Construire la config de sortie pour bcasl.yml
788829
cfg_out: dict[str, Any] = dict(self._cfg) if isinstance(self._cfg, dict) else {}
789830
cfg_out["plugins"] = _plugins_list_to_yaml(ordered)
790831
# plugin_order maintient la compatibilité avec l'ancien loader
791832
cfg_out["plugin_order"] = [e["name"] for e in ordered]
833+
834+
# S'assurer que 'enabled' ne pollue plus bcasl.yml
835+
if "options" in cfg_out and isinstance(cfg_out["options"], dict):
836+
cfg_out["options"].pop("enabled", None)
792837

793838
target = self._workspace_root / "bcasl.yml"
794839
try:

bcasl/Loader.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from typing import Any, Optional
3434
import yaml
3535

36+
from Core.Configs import load_ark_config
3637
from .executor import BCASL
3738

3839
from .Base import BcPluginBase, PreCompileContext
@@ -228,11 +229,11 @@ def _resolve_plugin_timeout(cfg: dict[str, Any]) -> float:
228229
return float(plugin_timeout) if plugin_timeout and plugin_timeout > 0 else 0.0
229230

230231

231-
def _is_bcasl_enabled(cfg: dict[str, Any]) -> bool:
232-
"""Return True si BCASL est activé dans la config."""
232+
def _is_bcasl_enabled(workspace_root: Path) -> bool:
233+
"""Consulte ark.yml pour savoir si le BCASL est activé globalement."""
233234
try:
234-
opt = cfg.get("options", {}) if isinstance(cfg, dict) else {}
235-
return bool(opt.get("enabled", True)) if isinstance(opt, dict) else True
235+
ark_cfg = load_ark_config(workspace_root)
236+
return bool(ark_cfg.get("plugins", {}).get("bcasl_enabled", True))
236237
except Exception:
237238
return True
238239

@@ -420,7 +421,6 @@ def _read_yml(p: Path) -> dict[str, Any]:
420421
"venv/**",
421422
".venv/**",
422423
]
423-
bcasl_enabled = True
424424
plugin_timeout = 0.0
425425

426426
try:
@@ -435,8 +435,6 @@ def _read_yml(p: Path) -> dict[str, Any]:
435435
exclude_patterns = ark_config["exclusion_patterns"]
436436

437437
plugin_opts = ark_config.get("plugins", {})
438-
if "bcasl_enabled" in plugin_opts:
439-
bcasl_enabled = plugin_opts["bcasl_enabled"]
440438
if "plugin_timeout" in plugin_opts:
441439
plugin_timeout = float(plugin_opts["plugin_timeout"])
442440
except Exception:
@@ -446,7 +444,6 @@ def _read_yml(p: Path) -> dict[str, Any]:
446444
"file_patterns": file_patterns,
447445
"exclude_patterns": exclude_patterns,
448446
"options": {
449-
"enabled": bcasl_enabled,
450447
"plugin_timeout_s": plugin_timeout,
451448
"sandbox": True,
452449
"plugin_parallelism": 0,
@@ -623,15 +620,14 @@ def run_pre_compile_async(self, on_done: Optional[callable] = None) -> None:
623620
cfg = _load_workspace_config(workspace_root)
624621
plugin_timeout = _resolve_plugin_timeout(cfg)
625622

626-
# Respect global enabled flag: skip BCASL when disabled
627-
bcasl_enabled = _is_bcasl_enabled(cfg)
628-
if not bcasl_enabled:
623+
# Vérifier si BCASL est activé globalement via ark.yml
624+
if not _is_bcasl_enabled(workspace_root):
629625
try:
630626
if hasattr(self, "log") and self.log is not None:
631627
self.log.append(
632628
self.tr(
633-
"BCASL désactivé dans la configuration. Exécution ignorée\n",
634-
"BCASL disabled in configuration. Skipping execution\n",
629+
"BCASL désactivé dans ark.yml. Exécution ignorée\n",
630+
"BCASL disabled in ark.yml. Skipping execution\n",
635631
)
636632
)
637633
except Exception:
@@ -717,13 +713,12 @@ def run_pre_compile(self) -> Optional[object]:
717713
cfg = _load_workspace_config(workspace_root)
718714
plugin_timeout = _resolve_plugin_timeout(cfg)
719715

720-
# Respect global enabled flag: skip BCASL when disabled
721-
bcasl_enabled = _is_bcasl_enabled(cfg)
722-
if not bcasl_enabled:
716+
# Vérifier si BCASL est activé globalement via ark.yml
717+
if not _is_bcasl_enabled(workspace_root):
723718
try:
724719
if hasattr(self, "log") and self.log is not None:
725720
self.log.append(
726-
"BCASL désactivé dans la configuration. Exécution ignorée\n"
721+
"BCASL désactivé dans ark.yml. Exécution ignorée\n"
727722
)
728723
except Exception:
729724
pass

docs/ark_main_config.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ The fields in `ark.yml` are mapped directly to the `BuildContext` data structure
5454
| `build.data` | `data_mappings` |
5555
| `build.icon` | `icon` |
5656

57+
## Plugins Configuration
58+
59+
`ark.yml` controls the global activation of the **BCASL** (Before-Compilation Actions System) pipeline.
60+
61+
```yaml
62+
plugins:
63+
bcasl_enabled: true # Global toggle for the BCASL pipeline
64+
```
65+
66+
If `bcasl_enabled` is set to `false`, the entire pipeline is skipped during compilation. This setting is also manageable via the **BCASL Pipeline** dialog in the GUI.
67+
5768
## Advanced Config Editor (GUI)
5869

5970
The main GUI has a **Configurations avancées** button that opens a dedicated editor for `ark.yml`, `bcasl.yml`, and other configuration files.

docs/how_to_create_a_bc_plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ exclude_patterns:
101101
- "**/__pycache__/**"
102102
- "**/*.pyc"
103103
options:
104-
enabled: true
105104
sandbox: true
106105
plugin_timeout_s: 5
107106
plugin_parallelism: 0
@@ -120,6 +119,7 @@ plugin_order:
120119
```
121120
122121
Important notes.
122+
- Global BCASL activation is managed by **`ark.yml`** (`plugins.bcasl_enabled`).
123123
- Keys in `plugins` are the `PluginMeta.id` values.
124124
- `plugin_order` forces ordering and adjusts priority.
125125
- If `bcasl.yml` is missing, a default file is generated.

0 commit comments

Comments
 (0)