Generate shell completions and man page when building a python package.
Add this package to your build requires:
[build-system]
requires = [ "setuptools-generate >= 0.0.6",]
build-backend = "setuptools.build_meta"
[project]
name = "demo"
version = "0.0.1"
[project.scripts]
demo = "demo:main"
[tool.setuptools.data-files]
"share/application" = [ "assets/desktop/demo.desktop",]
"share/icons/hicolor/256x256/apps" = [ "src/demo/assets/images/demo.png",]
"share/man/man1" = [ "sdist/demo.1",]
"share/bash-completion/completions" = [ "sdist/demo",]
"share/zsh/site-functions" = [ "sdist/_demo",]
Build your package:
python -m build
$ tree sdist
sdist
├── _demo # zsh completion script
├── demo # bash completion script
├── demo.1 # man page
└── demo.fish # fish completion script
$ tree dist
dist
├── demo-0.0.1-py3-none-any.whl # wheel file
└── demo-0.0.1.tar.gz # source distribution file
You got them.
Now pip install --prefix=/the/root/of/usr dist/*.whl
, you will see:
$ tree /the/root/of/usr
/the/root/of/usr
├── bin
│ └── trans
├── lib
│ └── python3.10
│ └── site-packages
│ ├── foo
│ │ └── ...
│ └── foo-0.0.1.dist-info
│ └── ...
└── share
~ ├── application
~ │ └── foo.desktop
~ ├── bash-completion
~ │ └── completions
~ │ └── foo
~ ├── icons
~ │ └── hicolor
~ │ └── 256x256
~ │ └── apps
~ │ └── foo.png
~ ├── man
~ │ └── man1
~ │ └── foo.1
~ └── zsh
~ └── site-functions
~ └── _foo
For linux package (deb
, rpm
, pkg.zst
, ...), it will be very easy.
Example projects:
- demo for click
- demo for shtab
- See more on wiki.
See document to know more.