Demonstration of nicegui failure to be called by Entry Points.
Steps to perform:
mkdir niceguitest
cd niceguitest
uv init --package
Create files in src/niceguitest:
logic.py
class myTestAdd:
def __init__(self, a, b):
self.a = a
self.b = b
def add(self):
return self.a + self.b
cli.py
from niceguitest import logic
def main() -> None:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(f"Result: {logic.myTestAdd(a, b).add()}")
if __name__ == "__main__":
main()
gui.py
# This file is the main entry point for the GUI version of the niceguitest package. It defines a simple NiceGUI application that allows users to input two numbers and see their sum. The logic for the addition is defined in the logic.py module, and this file focuses on setting up the GUI and handling user interactions.
from niceguitest.logic import myTestAdd
def main() -> None:
# This entry point is used when the user runs the command "niceguitest-gui" after installing the package with the "gui" extra.
try:
from nicegui import ui
run_gui_app(ui)
except ImportError:
print("NiceGUI is not installed. Please install the 'gui' extra to use the GUI features with 'pip install niceguitest[gui]' .")
from niceguitest.cli import main as cli_main
cli_main()
def run_gui_app(ui) -> None:
from niceguitest import logic
ui.label("Please enter two numbers to add:")
a_input = ui.input(label="First number")
b_input = ui.input(label="Second number")
result_label = ui.label("Result will be shown here.")
ui.button("Calculate", on_click=lambda: calculate_sum(a_input, b_input, result_label))
ui.run()
def calculate_sum(a_input, b_input, result_label) -> None:
try:
a = int(a_input.value)
b = int(b_input.value)
result = myTestAdd(a, b).add()
result_label.set_text(f"Result: {result}")
except ValueError:
result_label.set_text("Please enter valid integers.")
if __name__ in {"__main__", "__mp_main__"}:
main()
Adjust pyproject.toml:
[project]
name = "niceguitest"
version = "0.1.0"
description = "Test for entry points and optional dependencies for nicegui"
readme = "README.md"
authors = [
{ name = "Carsten Engelke", email = "carsten.engelke@gmail.com" }
]
requires-python = ">=3.13"
dependencies = []
[project.scripts]
niceguitest = "niceguitest.cli:main"
niceguitest-gui = "niceguitest.gui:main"
[project.optional-dependencies]
gui = [
"nicegui>=3.10.0",
]
[build-system]
requires = ["uv_build>=0.10.2,<0.11.0"]
build-backend = "uv_build"
Things that work:
- Call: niceguitest -> calls the CLI Version which runs fine.
- Call: python -m niceguitest.cli -> calls the CLI Version which runs fine.
- Call python -m niceguitest.gui -> calls the GUI Version which runs fine.
Things that do not work:
-
Call niceguitest-gui -> fails due to
RunTimeError: You must call ui.run() to start the server. If ui.run() is behind a main guard if name == "main": remove the guard or replace it with if name in {"main", "mp_main"}: to allow for multiprocessing.
As the main guard is already altered for multiprocessing this advice seems not helpful. Where is my error? Shouldn't nicegui come up with a more helpful advice? I do think this needs some clarification as this setup seems pretty standard but does not work with nicegui.
PS: Love it anyway,
Metadata
Release files for niceguitest 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| niceguitest-0.1.0.tar.gz | 2.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| niceguitest-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.7 kB
Release files / niceguitest-0.1.0.tar.gz
| Download URL | niceguitest-0.1.0.tar.gz |
|---|---|
| Size | 2.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9859b1794a1573473dc65b5f6244425c53e5bdbacd3040b0d79395c50741d4e2
|
|
BLAKE2b-256 checksum How to use checksums |
2da1dc5134116af9ba7bbace79e84dbb9638e0c24ae5cbd627f1cd20984f3e5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / niceguitest-0.1.0-py3-none-any.whl
| Download URL | niceguitest-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd529638993fa0ea29c5dddfb93f3f256e049fb884ed66cd677fcd59dfe538ac
|
|
BLAKE2b-256 checksum How to use checksums |
f2a1b513d76330b00e1f2df10b3a35862427ffbcf9cf280744334c1ba7f4126e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|