From 7d1755b44afba591c56e3588baca32490982b104 Mon Sep 17 00:00:00 2001 From: Mike Geppert Date: Fri, 8 Aug 2025 22:50:48 -0500 Subject: [PATCH] Build: add pyproject.toml (PEP 621) with setuptools backend and console script; Docs: explain what it takes to make pyproject.toml and how to build/install. --- README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 30 ++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 pyproject.toml diff --git a/README.md b/README.md index b899fe3..016d18b 100644 --- a/README.md +++ b/README.md @@ -315,3 +315,61 @@ That’s all that has to happen to publish a Python script on GitHub: have a loc - Prefer a modern pyproject.toml with a build backend (e.g., setuptools, hatchling, poetry). - Legacy projects can use setup.py/setup.cfg. - Reference: Packaging Python Projects (Python Packaging User Guide) https://packaging.python.org/en/latest/tutorials/packaging-projects/ + + +## What does it take to make a pyproject.toml? + +To package this project so it can be installed with pip (and optionally published to PyPI), you need a pyproject.toml that: + +- Declares a build backend in [build-system] (e.g., setuptools) +- Provides PEP 621 project metadata in [project] +- Tells the backend what to include (for a single-module project like this, use py-modules) +- Optionally defines a console script entry point so users can run a command after installation + +A minimal, working pyproject.toml for this repository looks like this: + +```toml +[build-system] +requires = [ + "setuptools>=64", + "wheel" +] +build-backend = "setuptools.build_meta" + +[project] +name = "tasmota-manager" +version = "0.1.0" +description = "Discover, monitor, and manage Tasmota devices via UniFi Controller." +readme = "README.md" +requires-python = ">=3.6" +license = { text = "MIT" } +authors = [ + { name = "TasmotaManager Contributors" } +] +dependencies = [ + "requests", + "urllib3" +] + +[project.scripts] +# After installation, users can run `tasmota-manager` +# which calls main() inside TasmotaManager.py +"tasmota-manager" = "TasmotaManager:main" + +[tool.setuptools] +# This project is a single-module distribution (TasmotaManager.py) +py-modules = ["TasmotaManager"] +``` + +Build and install locally: +- Install the build tool (once): `pip install build` +- Build the distribution: `python -m build` + - Artifacts will be placed in `dist/` (a .whl and a .tar.gz) +- Install the wheel: `pip install dist/tasmota_manager-0.1.0-py3-none-any.whl` + - After install, run: `tasmota-manager --help` + +Optional: publish to PyPI +- `pip install twine` +- `twine upload dist/*` + +That’s all it takes: choose a backend, declare metadata, and include your module(s). For larger projects with packages (src layouts), you would adjust the setuptools configuration accordingly. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cf92fe6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,30 @@ +[build-system] +requires = [ + "setuptools>=64", + "wheel" +] +build-backend = "setuptools.build_meta" + +[project] +name = "tasmota-manager" +version = "0.1.0" +description = "Discover, monitor, and manage Tasmota devices via UniFi Controller." +readme = "README.md" +requires-python = ">=3.6" +license = { text = "MIT" } +authors = [ + { name = "TasmotaManager Contributors" } +] +dependencies = [ + "requests", + "urllib3" +] + +[project.scripts] +# After installation, users can run `tasmota-manager` from the shell +# which calls the main() function inside TasmotaManager.py +"tasmota-manager" = "TasmotaManager:main" + +[tool.setuptools] +# This project is a single-module distribution (TasmotaManager.py) +py-modules = ["TasmotaManager"]