compilation output to logs
This commit is contained in:
@@ -11,11 +11,14 @@ from PySide6.QtWidgets import QApplication, QMessageBox
|
|||||||
from bedit_core.models import Component
|
from bedit_core.models import Component
|
||||||
from bedit_gui.documents import Document
|
from bedit_gui.documents import Document
|
||||||
from bedit_gui.services import simulation_files
|
from bedit_gui.services import simulation_files
|
||||||
|
from bedit_gui.services.application_logging import get_logger
|
||||||
from bedit_gui.services.simulation_loader import component_choices
|
from bedit_gui.services.simulation_loader import component_choices
|
||||||
from bedit_gui.simulation_models import CompiledModel, SimulationRoot
|
from bedit_gui.simulation_models import CompiledModel, SimulationRoot
|
||||||
from bedit_gui.views.main_window import MainWindow
|
from bedit_gui.views.main_window import MainWindow
|
||||||
from bedit_simulation import ModelBuildResult, compile_component_sync
|
from bedit_simulation import ModelBuildResult, compile_component_sync
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
Compiler = Callable[[Component, str | Path], ModelBuildResult]
|
Compiler = Callable[[Component, str | Path], ModelBuildResult]
|
||||||
Launcher = Callable[[Path, CompiledModel], bool]
|
Launcher = Callable[[Path, CompiledModel], bool]
|
||||||
|
|
||||||
@@ -54,15 +57,17 @@ class SimulationController(QObject):
|
|||||||
build_directory = Path(tempfile.mkdtemp(prefix="bedit-compiled-"))
|
build_directory = Path(tempfile.mkdtemp(prefix="bedit-compiled-"))
|
||||||
QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor)
|
QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor)
|
||||||
self.window.statusBar().showMessage(f"Compiling {component_path}…")
|
self.window.statusBar().showMessage(f"Compiling {component_path}…")
|
||||||
|
logger.info("Compiling model: %s", component_path)
|
||||||
try:
|
try:
|
||||||
build = self.compiler(component, build_directory)
|
build = self.compiler(component, build_directory)
|
||||||
except (OSError, RuntimeError, ValueError) as exc:
|
except (OSError, RuntimeError, ValueError) as exc:
|
||||||
|
logger.exception("Could not compile model %s", component_path)
|
||||||
QMessageBox.critical(self.window, "Could not compile", str(exc))
|
QMessageBox.critical(self.window, "Could not compile", str(exc))
|
||||||
self.window.statusBar().showMessage("Compilation failed")
|
self.window.statusBar().showMessage("Compilation failed")
|
||||||
return None
|
return None
|
||||||
finally:
|
finally:
|
||||||
QApplication.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
self.compiled_model = CompiledModel(build.model_name, str(build.executable.resolve()), str(build.executable.parent.resolve()))
|
self.compiled_model = CompiledModel(build.model_name, str(build.executable.resolve()), str(build.executable.parent.resolve()), build.output, build.errors)
|
||||||
self.compiled_root = SimulationRoot(
|
self.compiled_root = SimulationRoot(
|
||||||
format_version=1,
|
format_version=1,
|
||||||
source_document=str(self.document.path.resolve()) if self.document.path is not None else None,
|
source_document=str(self.document.path.resolve()) if self.document.path is not None else None,
|
||||||
@@ -73,6 +78,11 @@ class SimulationController(QObject):
|
|||||||
settings=settings,
|
settings=settings,
|
||||||
)
|
)
|
||||||
self.window.statusBar().showMessage(f"Compiled {component_path}")
|
self.window.statusBar().showMessage(f"Compiled {component_path}")
|
||||||
|
logger.info("Compiled model %s: %s", build.model_name, self.compiled_model.executable)
|
||||||
|
if build.output.strip():
|
||||||
|
logger.info("Compiler output:\n%s", build.output.strip())
|
||||||
|
if build.errors.strip():
|
||||||
|
logger.warning("Compiler errors:\n%s", build.errors.strip())
|
||||||
return self.compiled_root
|
return self.compiled_root
|
||||||
|
|
||||||
def open_simulation(self) -> None:
|
def open_simulation(self) -> None:
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class SimulationFileController(QObject):
|
|||||||
except (OSError, RuntimeError, TypeError, ValueError):
|
except (OSError, RuntimeError, TypeError, ValueError):
|
||||||
logger.exception("Could not open simulation %s", file_path)
|
logger.exception("Could not open simulation %s", file_path)
|
||||||
raise
|
raise
|
||||||
|
self._log_compilation()
|
||||||
self._update_window()
|
self._update_window()
|
||||||
logger.info("Opened simulation: %s", file_path)
|
logger.info("Opened simulation: %s", file_path)
|
||||||
|
|
||||||
@@ -151,3 +152,12 @@ class SimulationFileController(QObject):
|
|||||||
self.window.statusBar().showMessage(f"{self.root.component_path} · {compiled}")
|
self.window.statusBar().showMessage(f"{self.root.component_path} · {compiled}")
|
||||||
self.window.ui.actionSave_Simulation_Run.setEnabled(True)
|
self.window.ui.actionSave_Simulation_Run.setEnabled(True)
|
||||||
self.window.ui.actionSimulation_Options.setEnabled(True)
|
self.window.ui.actionSimulation_Options.setEnabled(True)
|
||||||
|
|
||||||
|
def _log_compilation(self) -> None:
|
||||||
|
if self.compiled_model is None:
|
||||||
|
return
|
||||||
|
logger.info("Compiled model %s: %s", self.compiled_model.model_name, self.compiled_model.executable)
|
||||||
|
if self.compiled_model.output.strip():
|
||||||
|
logger.info("Compiler output:\n%s", self.compiled_model.output.strip())
|
||||||
|
if self.compiled_model.errors.strip():
|
||||||
|
logger.warning("Compiler errors:\n%s", self.compiled_model.errors.strip())
|
||||||
|
|||||||
@@ -92,4 +92,4 @@ def _default_settings(component_id: ComponentID) -> Simulation:
|
|||||||
|
|
||||||
def _compile(component: Component, working_directory: Path, omc_command: str) -> CompiledModel:
|
def _compile(component: Component, working_directory: Path, omc_command: str) -> CompiledModel:
|
||||||
build = compile_component_sync(component, working_directory, omc_command=omc_command)
|
build = compile_component_sync(component, working_directory, omc_command=omc_command)
|
||||||
return CompiledModel(build.model_name, str(build.executable.resolve()), str(build.executable.parent.resolve()))
|
return CompiledModel(build.model_name, str(build.executable.resolve()), str(build.executable.parent.resolve()), build.output, build.errors)
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ class CompiledModel:
|
|||||||
model_name: str
|
model_name: str
|
||||||
executable: str
|
executable: str
|
||||||
working_directory: str
|
working_directory: str
|
||||||
|
output: str = ""
|
||||||
|
errors: str = ""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_data(cls, data: Mapping[str, Any]) -> CompiledModel:
|
def from_data(cls, data: Mapping[str, Any]) -> CompiledModel:
|
||||||
return cls(model_name=str(data["model_name"]), executable=str(data["executable"]), working_directory=str(data["working_directory"]))
|
return cls(model_name=str(data["model_name"]), executable=str(data["executable"]), working_directory=str(data["working_directory"]), output=str(data.get("output", "")), errors=str(data.get("errors", "")))
|
||||||
|
|
||||||
def to_data(self) -> dict[str, Any]:
|
def to_data(self) -> dict[str, Any]:
|
||||||
return {"model_name": self.model_name, "executable": self.executable, "working_directory": self.working_directory}
|
return {"model_name": self.model_name, "executable": self.executable, "working_directory": self.working_directory, "output": self.output, "errors": self.errors}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user