Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial for packaging command line applications? #562

Open
hmltn-0 opened this issue Dec 12, 2021 · 1 comment
Open

Tutorial for packaging command line applications? #562

hmltn-0 opened this issue Dec 12, 2021 · 1 comment

Comments

@hmltn-0
Copy link

hmltn-0 commented Dec 12, 2021

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

@bhrutledge
Copy link
Contributor

There isn't a PyPA tutorial, but there is an open issue to create one: pypa/packaging.python.org#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants