ofek / pyapp

Runtime installer for Python applications
https://ofek.dev/pyapp/
1.1k stars 24 forks source link

Support for gui-scripts #107

Closed johannesloibl closed 2 months ago

johannesloibl commented 2 months ago

Hey Ofek,

really great job you're doing here! I'd really like to get PyApp running and got first promising results already.

I'm trying to bundle an app that both has scripts and gui-scripts defined. Unfortunately PyApp does not support selecting the GUI entrypoint in the binary target option scripts.

I can somehow workaround it and define my GUI entrypoints under [project.scripts], since luckily even like this no console window is shown, but that's no how it's supposed to be.

I tried setting the script option to an empty list and define the execution mode by setting one of PYAPP_EXEC_*, but this is not working, since "empty list" is considered as "default to all entries of [project.scripts]". So afaik there is currently no chance of defining a custom execution mode, or is it??

I just noticed it does not matter if i set PYAPP_IS_GUI to 0 or 1, the executable is always starting a pythonw.exe, contrary to your documentation here.

Just as a reference, this is part of my config:

[project.scripts]
myapp_cli = "myapp.cli:main"
myapp-cli = "myapp.cli:main"

[project.gui-scripts]
myapp-gui = "myapp.cli:main"

[tool.hatch.envs.default.env-vars]
PIP_INDEX_URL = "https://..."
# PYAPP
PYAPP_PIP_EXTRA_ARGS = "--index-url https://..."
PYAPP_IS_GUI = "0"
PYAPP_DISTRIBUTION_EMBED = "false"
PYAPP_FULL_ISOLATION  = "true"

[tool.hatch.build.targets.binary]
scripts = ["myapp-cli"]

Then i'm building with hatch build -t binary.

trappitsch commented 2 months ago

@johannesloibl I assume you are on Windows, correct?

I am not sure on any of the hatch configurations since I never used this, but I am very surprised you say that the executable (assuming you mean the PyApp created binary) always executes with pythonw.exe. This should only be the case if PYAPP_IS_GUI was set to 1 when packaging and is in fact the case on my system. I could see how it could always uses python.exe...

Anyway, I'll have a look at the hatch way of packaging a binary, sounds really interesting.

johannesloibl commented 2 months ago

@trappitsch Yes i'm on Windows. Right now i'm not even setting PYAPP_IS_GUI. I'm only setting PYAPP_DISTRIBUTION_EMBED=false,PYAPP_FULL_ISOLATION=true and PYAPP_PIP_EXTRA_ARGS before building the executable using hatch build -t app.

The resulting executable is executed using pythonw.exe

image

ofek commented 2 months ago

I can't reproduce and it appears impossible for that code path to be hit without the variable being enabled.

johannesloibl commented 2 months ago

I'll check again later. I know the code path and I'm equally puzzled :D

johannesloibl commented 2 months ago

Ok so i checked again and now i also cannot reproduce it. Maybe i f***ed up my environment variables when trying around and did not notice. Sorry for the confusion. PYAPP_IS_GUI=1 --> pythonw.exe, PYAPP_IS_GUI=0 --> python.exe.

For the other topic i'll create a feature request in the Hatch repo, to support more PyApp options in Hatch itself 👍🏻