packaging-problems icon indicating copy to clipboard operation
packaging-problems copied to clipboard

Tutorial for packaging command line applications?

Open hmltn-0 opened this issue 4 years ago • 1 comments

OS version

Ubuntu 20.04

Python version

Python 3

Pip version

pip 3

Guide link

No response

Problem description

I was wondering if there is a tutorial which discusses packaging a command line application rather than an importable module. I would like to pip install application and from then on to invoke it by name only from the command line, like: “application”.

I know how to make a module executable by having a “main” file and using python3 -m module but not how to make it so that it’s runnable upon installation by just its name.

Thanks

Error message

No response

hmltn-0 avatar Dec 12 '21 20:12 hmltn-0

There isn't a PyPA tutorial, but there is an open issue to create one: https://github.com/pypa/packaging.python.org/issues/615.

In short, assuming you're using setuptools as your build backend, you need to add a console_scripts entry to setup.cfg.

Relatively recently, I went through an exercise of turning a personal Python script into an installable command-line utility, attempting to follow best-practices, while not going overboard. The result is up at https://github.com/bhrutledge/zkeys. The initial commit is just the script; the first release adds a minimal packaging layout to enable pip install (or pipx install) and publishing to PyPI. From there, I added all of the dev tools that I like to use, plus some documentation for my own reference.

Someday, I'd like to extract a cookiecutter, so that the next time I want to write such a tool, I can start with everything already set up.

bhrutledge avatar Dec 12 '21 22:12 bhrutledge