Nuitka
Nuitka copied to clipboard
Question: Is there a way to skip nuitka compilation?
For example, say I have some code that I want to use with CPython but don't want nuitka to see. How do I avoid code blocks? Is there a decorator or a special comment? For example, something like:
@nuitka_skip
def my_cpython_func():
...
# if not nuitka
cpython_variable = 42
# endif
This is a valid request, and Nuitka doesn't support it yet. For a whole module, you can do a --nofollow-module
and then it won't include it. You have to make it available in the PYTHONPATH
which is the normal one, or through the trick that is intended for test packages, via special environment variables.
Per function decorations that would e.g. preserve bytecode for them, that's not there.
You can check the __compiled__
attribute though, and branch dependent on that, that way, you can make the variable different. Of course that is horrible, and you better ought not ask our support, if the nuitka compiled program behaves differently, as we won't debug these differences and their effects.
Yeah, I am mostly looking for the ability to skip some globals-modifying state code that I have for CPython performance improvement. Namely, I would like to make lazyasd skip all of its actual behavior under nuitka
I've found a way how to build static linked binary portable python app using Nuitka. Docker example you can find in https://github.com/xxh/xxh-portable . The main feature is avoiding using glibc and use static linked musl libc instead. It works on many linux.
If anybody can suggest workaround for the lazyasd exception I'll be happy to try build xonsh using this technique.
@anki-code, that's awesome! Yeah. Let's try to find a way to work around lazyasd. I think would could probably try to find a way to strip it out of the code base entirely. We probably also don't need to use amalgamate either, but it may or may not make the result of Nuitka faster. We should figure that out.
There is a bit of an improvement in sight here, Nuitka now can do it based on decorator names. The code is still experimental, and has only been applied for the pyQtslot
decorator so far, still rough, but should pave a way to this feature request to eventually become true. Setting this to a 1.8 milestone, but not sure I can make it in time. Most difficult part is to decide how to name it and where to put it. Will need a new package on PyPI to provide tools like this one. I am tempted to use nuitka_hints
or something like that as a package name.
I am shifting this to 2.2 release, as it really needs a different solution than what we did for PyQt5/6 there really, as that's causing issues long term, the solution needs to happen at code generation time, and not at tree building I now believe, such that the code does still get analysed properly and can have effects, like following imports, metadata versions, etc.