Use our python-cli-tool cookiecutter project. Get an python cli project up and running in a few steps. In my previous speedup-event-driven-projects blog. I wrote how you could use cookiecutter to spin up an event driven project for AWS. In this blog post I will show you how you could do this for python cli projects.
For this blog post I assume that you have the following installed:
- python3
- cookiecutter
- poetry
Lets create an cli project
We will begin with executing the cookiecutter command:
cookiecutter gh:binxio/python-cli-tool
Cookiecutter will create a folder based on the project_name
. In this folder you now only need to install the dependencies. You can use the following command:
make install
The install
target of the Makefile will:
- Perform a
poetry init
, this will create thepyproject.toml
file. - Create git repository and install the pre-commit hooks.
- Perform a
poetry install
. This will install all project dependencies based on thepyproject.toml
file. - Adds extra configuration to the
pyproject.toml
file. - Commits everything to the git repository.
You will end up with something like this:
The project itself has unit testing in-place:
And you can test your cli tool as well by executing the commands through poetry:
Now it’s time to configure your remote GitHub repository:
git remote add origin git@github.com:binxio/my-example-cli.git
git branch -M main
git push -u origin main
git checkout -b develop
git push --set-upstream origin develop
We pushed the main
branch to the remote and created a develop
branch as a working branch.
The project itself contains the following workflows:
- Continuous Integration, checks when you push to
main
or open a pull request todevelop
. - Create Release, creates an release for you when you merge to
main
and uploads it to PyPi.org. (You need to configure aPYPI_API_TOKEN
secret in GitHub for this to work) - Release Notes, creates a proposal for your release notes. This is based on your merged pull requests. So make sure you use correct messages.
Conclusion
By using the python-cli-tool cookiecutter project you will speedup your python cli project!
And you can focus on what matters! Your business logic!
Photo by Ekaterina Belinskaya