How about adding .pyi file support to work with Cython compiled .so/.pyd modules?
#9239
Replies: 2 comments
I really don't want to support or endorse this. If you think that the dependency finding is the hard part of using Cython with PyInstaller then you're probably only thinking that because you're blissfully unaware of the woes of ABI compatibility (which PyInstaller can do nothing to help you with). The last obfuscation feature we had misled a lot of users into doing things that are impossible to do like hiding API keys in an application. To that end, I don't think it's safe for PyInstaller to have any built in obfuscation support. |
|
As of #9084 the analysis is supposed to pick up and analyze .pyi (or .py) files found next to extension modules. If that is not happening in your case, we might need to investigate as to why. While I suppose we could look into automatic cythonization as an extension of the |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Recently I've been fiddling with Cython compilation to protected source code, one problem left is PyInstaller can not analyze compiled
.so/.pydto get imported dependencies, so we need to manually specify those direct dependencis with--hiddenimport.I also noticed that mypy have a tool
stubgenwhich can generate.pyifile from.pysource code, the.pyifiles only include the import and type declarations.Example:
It just like C/C++ header files with forward declarations, which is perfect for PyInstaller to do analysis, we could get a perfect workflow to protect source code with Cython:
.py-> cython ->.so/.pyd.py-> stubgen ->.pyi.pyi+.so/.pyd-> PyInstaller -> bundleEDIT: I just found out that PyInstaller can actually specify multiple entry scripts and '.pyi' file is also supported, so this basic workflow just works! Wooo Hooo!
We could go one step further, that PyInstaller directly integrate Cython and stubgen to automatically pack compiled bundles?
I don't know, but it looks very promising.
In this area Nuitka is also a great tool, but it requires compiling ALL the dependencies to machine code, in real life a small-to-medium FastAPI project could easily cost 30+ minutes to build (even with cache). PyInstaller have the flexibility to selectively compile only main program and keep external dependencies in Python form, where we can get the best of both worlds: fast packing + protected source code.
All reactions