Skip to content

Commit ed10679

Browse files
committed
docs creation
1 parent 032bbea commit ed10679

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

docs/how_to_create_a_bc_plugin.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
**Overview**
2+
BC plugins (BCASL) run before compilation. They are Python packages placed in `Plugins/`, discovered automatically, and executed through the `on_pre_compile` hook.
3+
4+
**Steps**
5+
1. Create a package folder in `Plugins/<plugin_name>/` with an `__init__.py`.
6+
2. Implement a subclass of `BcPluginBase` and decorate it with `@bc_register`.
7+
3. Define a `PluginMeta` with a unique `id`.
8+
4. Configure the plugin in `bcasl.yml` (optional but recommended for ordering and enable/disable).
9+
10+
**Minimal Plugin**
11+
```python
12+
from __future__ import annotations
13+
14+
from bcasl import bc_register
15+
from Plugins_SDK.BcPluginContext import BcPluginBase, PluginMeta, PreCompileContext
16+
from Plugins_SDK.GeneralContext import Dialog
17+
18+
log = Dialog()
19+
20+
META = PluginMeta(
21+
id="example.clean",
22+
name="Example Clean",
23+
version="0.1.0",
24+
description="Remove .pyc files before build",
25+
author="You",
26+
tags=("clean",),
27+
required_bcasl_version="2.0.0",
28+
required_core_version="1.0.0",
29+
required_plugins_sdk_version="1.0.0",
30+
required_bc_plugin_context_version="1.0.0",
31+
required_general_context_version="1.0.0",
32+
)
33+
34+
35+
@bc_register
36+
class ExampleClean(BcPluginBase):
37+
meta = META
38+
39+
def __init__(self):
40+
super().__init__(META)
41+
42+
def on_pre_compile(self, ctx: PreCompileContext) -> None:
43+
if not ctx.is_workspace_valid():
44+
log.log_warn("Workspace not valid or bcasl.yml missing")
45+
return
46+
for pyc in ctx.iter_files(["**/*.pyc"], ctx.get_exclude_patterns()):
47+
try:
48+
pyc.unlink()
49+
except Exception as exc:
50+
log.log_warn(f"Failed to remove {pyc}: {exc}")
51+
```
52+
53+
**Configuration**
54+
BCASL reads `bcasl.yml` or `.bcasl.yml` in the workspace root. Only the `.yml` extension is supported.
55+
```yaml
56+
required_files:
57+
- main.py
58+
file_patterns:
59+
- "**/*.py"
60+
exclude_patterns:
61+
- "**/__pycache__/**"
62+
- "**/*.pyc"
63+
options:
64+
enabled: true
65+
sandbox: true
66+
plugin_timeout_s: 5
67+
plugin_parallelism: 0
68+
iter_files_cache: true
69+
plugins:
70+
example.clean:
71+
enabled: true
72+
priority: 10
73+
plugin_order:
74+
- example.clean
75+
```
76+
77+
**Notes**
78+
- Plugin ids come from `PluginMeta.id`, and configuration uses those ids.
79+
- Plugins can also register via a legacy `bcasl_register(manager)` function, but `@bc_register` is preferred.
80+
- Use `Plugins_SDK.GeneralContext.Dialog` for UI interactions and logging. Direct Qt dialogs are blocked in sandboxed runs.
81+
- Timeouts can be controlled with `options.plugin_timeout_s` or the env var `PYCOMPILER_BCASL_PLUGIN_TIMEOUT`.
82+
- Parallelism can be controlled with `options.plugin_parallelism` or the env var `PYCOMPILER_BCASL_PARALLELISM`.

docs/how_to_create_an_engine.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)