|
| 1 | +**Overview** |
| 2 | +PyCompiler_ARK engines are Python packages loaded from `ENGINES/` at startup. Each engine registers itself with `@engine_register` and provides a `CompilerEngine` subclass that builds the command used to compile a file. |
| 3 | + |
| 4 | +**Steps** |
| 5 | +1. Create a package folder in `ENGINES/<engine_id>/` with an `__init__.py`. |
| 6 | +2. Implement a subclass of `CompilerEngine` in that `__init__.py`. |
| 7 | +3. Decorate the class with `@engine_register` and set the required attributes. |
| 8 | +4. Restart the app so the loader auto-discovers the package. |
| 9 | + |
| 10 | +**Minimal Example** |
| 11 | +```python |
| 12 | +from __future__ import annotations |
| 13 | + |
| 14 | +import sys |
| 15 | +from engine_sdk import CompilerEngine, engine_register |
| 16 | + |
| 17 | + |
| 18 | +@engine_register |
| 19 | +class MyEngine(CompilerEngine): |
| 20 | + id = "my_engine" |
| 21 | + name = "My Engine" |
| 22 | + version = "0.1.0" |
| 23 | + required_core_version = "1.0.0" |
| 24 | + required_sdk_version = "1.0.0" |
| 25 | + |
| 26 | + @property |
| 27 | + def required_tools(self): |
| 28 | + return {"python": ["mytool"], "system": []} |
| 29 | + |
| 30 | + def build_command(self, gui, file): |
| 31 | + return [sys.executable, "-m", "mytool", file] |
| 32 | +``` |
| 33 | + |
| 34 | +**Required API** |
| 35 | +- `id`: Unique engine id (string). |
| 36 | +- `name`: Display name. |
| 37 | +- `version`: Engine version. |
| 38 | +- `required_core_version` and `required_sdk_version`: Compatibility info. |
| 39 | +- `build_command(self, gui, file) -> list[str]`: Full command list with the program at index 0. |
| 40 | + |
| 41 | +**Optional API** |
| 42 | +- `preflight(self, gui, file) -> bool`: Return False to abort. |
| 43 | +- `program_and_args(self, gui, file)`: Override if you need custom program/args separation. |
| 44 | +- `environment(self) -> dict[str, str] | None`: Inject environment variables. |
| 45 | +- `on_success(self, gui, file)`: Post-build hook. |
| 46 | +- `required_tools` property: Python and system tools that should be installed. |
| 47 | +- `create_tab(self, gui)`: Provide a custom settings tab for your engine. |
| 48 | +- `apply_i18n(self, gui, tr)`: Update text when language changes. Provide `languages/<code>.json` in your engine package if you want translations. |
| 49 | + |
| 50 | +**Notes** |
| 51 | +- The loader only imports packages under `ENGINES/` that contain `__init__.py`. Plain `.py` files are ignored. |
| 52 | +- Keep engines stateless. GUI state is passed in `gui`. |
0 commit comments