Skip to content

Commit 44218bf

Browse files
author
Kevin Barre
committed
feat: add pyoxidizer and docker containerization
1 parent 4daf0b7 commit 44218bf

5 files changed

Lines changed: 89 additions & 4 deletions

File tree

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM scratch
2+
3+
COPY ./dist/simui_static /simui_static
4+
5+
ENTRYPOINT ["/simui_static"]
6+
CMD [ ""]

pyoxidizer.bzl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def make_exe():
2+
# 1. Get the default Python distribution (standard Python library)
3+
policy = dist.make_python_packaging_policy()
4+
policy.resources_location_fallback = "filesystem-relative:lib"
5+
dist = default_python_distribution()
6+
7+
# 2. Configure the interpreter startup
8+
# This tells the app to import 'main.py' and run the 'run()' function inside it
9+
python_config = dist.make_python_interpreter_config()
10+
python_config.run_command = "import simui; simui.run()"
11+
12+
# 3. Define the executable wrapper
13+
exe = dist.to_python_executable(
14+
name="simui",
15+
config=python_config,
16+
packaging_policy=policy,
17+
)
18+
19+
# 4. Add your Python source code
20+
# Scans the current directory (".") for the "main" module (main.py)
21+
exe.add_python_resources(exe.read_package_root(
22+
path=".",
23+
packages=["simui"]
24+
))
25+
26+
# exe.add_python_resources(exe.pip_install(["."]))
27+
28+
return exe
29+
30+
# 5. Register the build target so PyOxidizer knows what to build
31+
register_target("exe", make_exe)
32+
33+
# 6. Finalize targets (Standard boilerplate)
34+
resolve_targets()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies = [
88
"imgui-bundle[full]>=1.92.5",
99
"numpy>=2.4.0",
1010
"pyinstaller>=6.17.0",
11+
"pyoxidizer>=0.24.0",
1112
"staticx>=0.14.1",
1213
]
1314

readme.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ source .venv/bin/activate
5959
export PATH=$PATH:$PWD/.venv/bin/
6060

6161
imgui_bundle_asset_path=`python -c "import imgui_bundle, os; print(os.path.join(os.path.dirname(imgui_bundle.__file__), 'assets'))"`
62+
PYTHONOPTIMIZE=3
6263

63-
pyinstaller --onefile --noconsole \
64+
pyinstaller \
65+
--onefile \
66+
--noconsole \
67+
--windowed \
6468
--add-data "${imgui_bundle_asset_path}:imgui_bundle/assets" \
6569
--name "simui" \
6670
simui.py
@@ -112,6 +116,40 @@ ldd ./dist/simui_static
112116
./simui_static
113117
```
114118

119+
### Docker
120+
121+
```bash
122+
xhost +local:docker
123+
124+
docker build . -t simui:latest
125+
```
126+
127+
X11 forwarding
128+
129+
```bash
130+
docker run -it --rm \
131+
--net=host \
132+
-e DISPLAY=$DISPLAY \
133+
-v /tmp/.X11-unix:/tmp/.X11-unix \
134+
-v $HOME/.Xauthority:/root/.Xauthority \
135+
simui:latest
136+
```
137+
138+
Wayland forwarding
139+
140+
```bash
141+
docker run -it --rm \
142+
-e XDG_RUNTIME_DIR=/tmp \
143+
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
144+
-e DISPLAY=$DISPLAY \
145+
-v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/tmp/$WAYLAND_DISPLAY \
146+
-e QT_QPA_PLATFORM=wayland \
147+
-e GDK_BACKEND=wayland \
148+
simui:latest
149+
```
150+
151+
Adapt with `--device /dev/...`
152+
115153
## Pyiodide for web
116154

117155
source: https://pyodide.com/
@@ -144,10 +182,16 @@ Use [Fiatlight](pthom.github.io/fiatlight_doc/flgt/intro.html) for faster UI dev
144182

145183
### Packages
146184

147-
[PyInstaller](https://pyinstaller.org/en/stable/) and/or [Nuitka](https://nuitka.net/) or [PyOxidizer](https://github.com/indygreg/PyOxidizer) can be used to compile the python code into a single executable file.
185+
[PyInstaller](https://pyinstaller.org/en/stable/) or [PyOxidizer](https://github.com/indygreg/PyOxidizer) can be used to compile the python code into a single executable file.
148186

149187
Shaders (GLSL) can be used to use gpu acceleration, also interoperability with vulkan, metal, dx12, OpenCV, and CUDA is Possible.
150188

189+
## Possible Performance Improvements
190+
191+
[cythonizer](https://github.com/TechLearnersInc/cythonizer) and [pyoxidizer](https://github.com/indygreg/PyOxidizer) can be used to compile the python code into a single executable file.
192+
193+
Write the code in cython and compile it to c code.
194+
151195
### ImGui
152196

153197
- [imgui_bundle_playground](https://traineq.org/imgui_bundle_online/projects/imgui_bundle_playground/)

simui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def gui_right_panel() -> None:
123123
implot.end_plot()
124124

125125

126-
def main() -> None:
126+
def simui() -> None:
127127
runner_params = hello_imgui.RunnerParams()
128128

129129
# runner_params.app_window_params.borderless = True
@@ -169,4 +169,4 @@ def main() -> None:
169169

170170

171171
if __name__ == "__main__":
172-
main()
172+
simui()

0 commit comments

Comments
 (0)