You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,6 @@ Custom (python) import hooks are installed to support loading modules (both nati
16
16
17
17
Currently the exe just drops to an interactive loop. Modification to run a script or embed a file/module should be trivial.
18
18
19
-
-[ ] Support `onefile_python.exe script.py`
20
19
-[ ] Build option for embedding a python file/module and running that on launch
21
20
-[ ] Support other versions of python than `3.10.1` (autodetect?)
22
21
@@ -32,7 +31,7 @@ py2exe supports a diskless/"bundle" mode.
32
31
33
32
Both these projects are *much* more complex than this one and support lots of extra features, but sometimes you don't need that...
34
33
35
-
This project is (maybe) better if you want a single exe that can run any python script[or will be once that is supported], or just want an exe that gives a python REPL.
34
+
This project is (maybe) better if you want a single exe that can run any python script, or just want an exe that gives a python REPL.
36
35
Being simpler, this project should be easier to hack on or learn from.
37
36
38
37
@@ -42,7 +41,7 @@ There's not much to it...
42
41
43
42
0. Use nim's [staticRead](https://nim-lang.org/docs/system.html#staticRead%2Cstring) to include `python-*-embedded.zip` and `bootstrap.py` inside compiled exe itself.
44
43
1. Use [zippy](https://github.com/guzba/zippy) to access the contents of the archive at runtime.
45
-
2. Use [memlib](https://github.com/khchen/memlib) to perform reflective dll loading of the embedded `python*.dll`. Reflective dll loading allows for loading the dll from memory rather than from disk. Hook `LdrLoadDll` and `K32EnumProcessModules` so other code using the dll can find it.
44
+
2. Use [memlib](https://github.com/khchen/memlib) to perform reflective dll loading of the embedded `python*.dll`. Reflective dll loading allows for loading the dll from memory rather than from disk. Hook `LdrLoadDll` and `K32EnumProcessModules` so other code using the dll can find it. n.b. currently using a fork until https://github.com/khchen/memlib/pull/3 is merged.
46
45
3. Call various functions in the (reflectively) loaded dll to partially initialize python. Configure python to not try to load anything from disk (not absolutely required, but prevents conflicts and means the exe doesn't run any code in the current directory)
47
46
4. Use [nimpy](https://github.com/yglukhov/nimpy) to initialize a python extension exporting some nim functions that can read data out of the `python*.zip` standard library (contained within the `...-embedded.zip`).
48
47
5. Run the embedded `bootsrap.py` code to install an import hook. This import hook uses the functions from (4) to support importing python modules. If a `.pyc` can be found that matches an import, a loader that returns the unmarshalled `.pyc` is provided. If a `.pyd` can be found, the returned loader reflectively loads the `.pyd` and calls the module's initialization routine.
Copy file name to clipboardExpand all lines: onefile_python.nim
+66-10Lines changed: 66 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,10 @@ import std/strutils
7
7
import zippy/ziparchives
8
8
import minhook
9
9
import winim/lean
10
-
11
10
import memlib
12
11
import nimpy
13
12
import nimpy/py_types
13
+
import argparse
14
14
15
15
import cpython_types
16
16
@@ -19,6 +19,14 @@ const DEBUG = false # Print debug messages (in nim code, and in python loaders)
19
19
constEMBED_DLL=true# Use the .dll embedded in the zip archive. If false, will require python310.dll to be in the PATH. If true, debugging may be harder as the dll is reflectively loaded
20
20
21
21
22
+
let p =newParser("onefile_python"):
23
+
help("{prog}")
24
+
flag("-V", "--version")
25
+
option("-c", "--command", help="program passed in as string")
26
+
arg("file", default=some(""), help="program read from script file")
27
+
arg("arg", nargs=(-1), help="arguments passed to program in sys.argv[1:]")
0 commit comments