Skip to content

Freed-Wu/setuptools-generate

Repository files navigation

setuptools-generate

pre-commit.ci status github/workflow codecov readthedocs

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

pypi/status pypi/v pypi/downloads pypi/format pypi/implementation pypi/pyversions

Generate shell completions and man page when building a python package.

Usage

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:

See document to know more.