Test for entry points and optional dependencies for nicegui
Project description
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,
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file niceguitest-0.1.0.tar.gz.
File metadata
- Download URL: niceguitest-0.1.0.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9859b1794a1573473dc65b5f6244425c53e5bdbacd3040b0d79395c50741d4e2
|
|
| MD5 |
22ff763c1c4e109e0da9277223755b10
|
|
| BLAKE2b-256 |
2da1dc5134116af9ba7bbace79e84dbb9638e0c24ae5cbd627f1cd20984f3e5b
|
File details
Details for the file niceguitest-0.1.0-py3-none-any.whl.
File metadata
- Download URL: niceguitest-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd529638993fa0ea29c5dddfb93f3f256e049fb884ed66cd677fcd59dfe538ac
|
|
| MD5 |
37dcc8e9b296eac355cd907aa170dec4
|
|
| BLAKE2b-256 |
f2a1b513d76330b00e1f2df10b3a35862427ffbcf9cf280744334c1ba7f4126e
|