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.
This commit is contained in:
parent
44c9042eee
commit
7d1755b44a
58
README.md
58
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.
|
||||
|
||||
30
pyproject.toml
Normal file
30
pyproject.toml
Normal file
@ -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"]
|
||||
Loading…
Reference in New Issue
Block a user