Nuitka / Nuitka-Action

Action to build with Nuitka on GitHub in your workflows
MIT License
111 stars 22 forks source link

Add --user-plugin #47

Closed JustRedTTG closed 3 months ago

JustRedTTG commented 3 months ago

I was wondering if it's possible to have the --user-plugin option added so I can pass a path and add custom plugins in my git repo for nuitka?

kayhayen commented 3 months ago

You are correct, that's missing absolutely. I added generation for the plugin options, which added user plugin as well as module parameters, which are kind of important as well, and other plugin related arguments. They should immediately work on main branch now.

JustRedTTG commented 3 months ago

I've tested this, both with my own fork which I did the same to add user-plugin and the new updated commit on the main nuitka-action and yet still I don't see any of the plugin log and results of the plugin aren't in effect, the executable doesn't get signed and no error is given of the signing process meaning it wasn't ran at all.

Thanks for the quick response but perhaps this is an issue in Nuitka or the action somehow breaks it I'm not sure myself.

I note: copying the exact command in the log yields the correct result with the plugin log and signed executable, I can't show that since I don't wanna rebuild it rn just to take a screenshot but here you can see in the action log that the plugin log is clearly missing despite other plugins (non-user) plugins are giving log, executable also I checked has not been signed, environment variables are set and should sign or give error and fail the command

image

JustRedTTG commented 3 months ago

Here's the complete log since I know you don't like screenshots very much, but one close eye is enough to find the user plugin missing:


Nuitka-Plugins:options-nanny: Note, when using 'pygame', consider using '--disable-console' option. Otherwise a terminal window will open. However for debugging, terminal output is the easiest way to see informative traceback and error information, so delay this until your program is working and remove once you find it non-working, and use '--enable-console' to make it explicit and not see this message.
Nuitka-Plugins:anti-bloat: Not including 'PIL.ImageQt' automatically in order to avoid bloat, but this may cause: PIL will not be able to create Qt image objects.
Nuitka: Completed Python level compilation and optimization.
Nuitka: Generating source code for C backend compiler.
Nuitka: Running data composer tool for optimal constant value handling.
Nuitka: Running C compilation via Scons.
Nuitka-Scons: Backend C compiler: cl (cl 14.3).
Nuitka-Scons: Backend linking program with 329 files (no progress information available for this stage).
Nuitka-Scons: Compiled 329 C files using clcache with 329 cache hits and 0 cache misses.
Nuitka-Postprocessing: Adding 6 icon(s) from icon file 'icon.ico'.
Nuitka-Options: Included 40 data files due to specified data dir 'data' on command line.
Nuitka-Options: Included 35 data files due to specified data dir 'assets' on command line.
Nuitka-Plugins:data-files: Included data file 'pygame\freesansbold.ttf' due to package data for 'pygame'.
Nuitka-Postprocessing: Creating single file from dist folder, this may take a while.
Nuitka-Onefile: Running bootstrap binary compilation via Scons.
Nuitka-Scons: Onefile C compiler: cl (cl 14.3).
Nuitka-Scons: Onefile linking program with 1 files (no progress information available for this stage).
Nuitka-Scons: Compiled 1 C files using clcache with 1 cache hits and 0 cache misses.
Nuitka-Postprocessing: Adding 6 icon(s) from icon file 'icon.ico'.
Nuitka-Onefile: Using compression for onefile payload.
Nuitka-Onefile: Onefile payload compression ratio (64.15%) size [249](https://github.com/JustRedTTG/rpg-demo/actions/runs/8214788384/job/22467582012#step:6:254)447458 to 160020349.
Nuitka-Onefile: Keeping onefile build directory 'build\main.onefile-build'.
Nuitka: Keeping dist folder 'build\main.dist' for inspection, no need to use it.
Nuitka: Keeping build directory 'build\main.build'.
Nuitka: Successfully created 'build\main.exe'.```
kayhayen commented 3 months ago

I indeed don't like them. It seems the line with the user plugin option didn't make it out of the screenshot to the text version, but I appreciate the effort done. 👍

Your plugin not doing what you want it to do could have many reasons, which could be Nuitka issues or your plugin issues. I just verified that user plugin tests are indeed running OK. In Nuitka commercial there is a code-signing plugin for Windows, that you might want to consider using instead.

JustRedTTG commented 3 months ago

The plugin doesn't run AT ALL, tested on my pc it works fine (and I mean the log is there Nuitka-Plugins:sign-Windows : Signing main.exe something like this, notice no such thing is present in the log above, assuming the plugin is not at being called, and here's the plugin, taken from one forum in github, works locally, not in the action, even when copy-pasting the action options it will work locally, but not in the action, here's the plugin so you can see:

import os
import subprocess

from nuitka.plugins.PluginBase import NuitkaPluginBase

# SOURCE: https://github.com/Nuitka/Nuitka/issues/1536#issuecomment-1741649391
# AUTHOR: https://github.com/whistmxl

"""
This plugin is used to sign the final executable with codesigntool.bat
"""

class SignPlugin(NuitkaPluginBase):
    plugin_name = 'user-internal:sign'

    def __init__(self, *args, **kwargs) -> None:
        pass

    def _sign(self, filename: str) -> None:
        if '.dist' in filename:
            return
        self.info(f'Signing {filename}')
        command = [
            'codesigntool.bat', 'sign', '-override',
            f'-credential_id={os.environ.get("CODESIGN_CRED_ID", "")}',
            f'-username={os.environ.get("CODESIGN_USERNAME", "")}',
            f'-password={os.environ.get("CODESIGN_PASSWORD", "")}',
            f'-totp_secret={os.environ.get("CODESIGN_TOTP", "")}',
            f'-input_file_path={filename}',
        ]
        p = subprocess.run(command, shell=True, capture_output=True)

        if p and p.stdout and b'Code signed successfully' in p.stdout:
            self.info(p.stdout.decode('utf-8'))
        else:
            self.info('Error signing executable!')
            self.sysexit(p.stdout.decode('utf-8') if p and p.stdout else 'No output from command')

    def onStandaloneBinary(self, filename: str) -> None:
        """this will sign the executable generated in app.dist"""
        return self._sign(filename)

    def onFinalResult(self, filename: str) -> None:
        """this will sign the final executable"""
        return self._sign(filename)

I'm not sure about the dist thing but I did that so it wouldn't sign both the standalone and onefile, notice: I tested codesigntool setup on the action and it worked perfectly, the plugin also has log info at the beginning as you can see, so it would show up in the log as long as onefile was run, which it was

kayhayen commented 3 months ago

You are very likely correct, I noticed that it is not defined as an "early" name, only the standard plugin option settings are, but later added, it's just ignored, since it can influence command line parsing itself, with its own options, this has to be the case.

JustRedTTG commented 3 months ago

Likewise, how do you suggest I fix it not running and signing my executable?

kayhayen commented 3 months ago

Thanks for your report, this is fixed on the factory branch, which is a development version under rapid development. You can try it out by going here: https://nuitka.net/doc/factory.html and use it inside of your Action.

Feedback if this is working is very welcome, just please do not share plans of doing it, but rather confirmations or denials of it working.

JustRedTTG commented 3 months ago

I can confirm, this fixes the issue! On the factory branch of nuitka + nuitka action here's partial log showing the user action working!


Nuitka: Keeping dist folder 'build\main.dist' for inspection, no need to use it.
Nuitka: Keeping build directory 'build\main.build'.
Nuitka-Plugins:user-internal:sign: Signing build\main.exe
Nuitka-Plugins:user-internal:sign: Code signed successfully: D:\a\rpg-demo\rpg-demo\build\main.exe
Nuitka: Successfully created 'build\main.exe'.```