Tips for Command Line Project
Posted by Vova____@reddit | Python | View on Reddit | 10 comments
Hello! I'm making a short project to have a little experience creating a command line tool, as well as getting a project onto PyPI. Mainly, I'm doing this because I think it's cool, and it would be awesome if a friend could pip3 install my project and just have a CLI tool off the install, similar to how the `qrcode` Python library comes with the `qr` CLI tool when installed. If you have any tips **AT ALL** for anything you see, like project organization, overall Python usage, or too many commits (is that possible), please tell me, I'm a sponge for info!
Off a google search, I understand there is already a PyPI project [Jonathan Löfgren](https://github.com/jonathanlofgren/running/blob/master/.gitignore) made some time ago for converting paces into different distance paces. The purpose of my project here is to get a little experience creating a CLI tool I could use along with the overall process of getting something onto PyPI that works. If what I'm doing is majorly wrong, however, please tell me, I don't know!
PyPI Page: https://pypi.org/project/paces-calc/
GitHub Source Code link: https://github.com/Vladimir-Herdman/Pace-Calculator
graduallydecember@reddit
Some suggestions: - standardize your commit messages, look into conventional commits. One standard is to use present tense "feat: add feature xxx" instead of "added feature xxx", in the sense of "this commit when merged will add feature xxx" - add pre-commits for linting (ruff for example) - add typing so it's easier to understand your code when you come back to it
Vova____@reddit (OP)
Thank you!
violentlymickey@reddit
I encourage you to look into the python standard library argparse. It is very powerful and can certainly do most of what you want. Click is another popular library, but I find it's a bit overkill unless you have a lot of modules that you want to create nested cli for.
jivesishungry@reddit
I disagree that click is overkill. I find click much more intuitive even for simple cases than argparse.
durable-racoon@reddit
As for installing a script in $PATH, this is done through the console_scripts entry point. Assuming your package is just the script MyUtility.py and it contains a main() function, and assuming you’re using setuptools, you would write the following in your setup.cfg:
[options.entry_points] console_scripts = MyUtility = MyUtility:main
https://discuss.python.org/t/creating-a-setup-process-for-a-python-command-line-utility/9600
durable-racoon@reddit
use 'click' I love that package.
keldrin_@reddit
doing it only just "because it's cool" is the wrong intention. Downvote, sorry!
Vova____@reddit (OP)
Why is it the wrong intention?
ftmprstsaaimol2@reddit
I found this helpful.
Broadly speaking, look into the click package.
Vova____@reddit (OP)
Thank you!