cookiecutter-pip-click
A Python cookiecutter template for creating command-line tools.
Information
I love command line tools and open-source software, so I create this template for use with future projects. It creates a well-structured - but hopefully not too opinionated - project for developing command line tools using Click. This cookiecutter template should handle (nearly) all your project setup for you, using poetry.
Heads Up!
You need poetry and travis installed to complete the setup of this cookiecutter!
Using the template
When starting a new project, always create a new virtual environment. I use pyenv for all my env/venv control, so I would do:
pyenv virtualenv project_name
pyenv virtualenv activate project_name
pip install -U cookiecutter
Use whatever method is already part of your workflow. Now, we initialise the project:
cookiecutter https://github.com/rbpatt2019/cookiecutter-pip-click
You'll be walked through some prompts to provide the necessary information. And, viola! Your project is set-up!
Final Steps
Let's take a peek around. To do that, move into the directory and view it's contents.
cd project_name
ls
Poetry uses a pyproject.toml for all of its settings, so let's look at that.
cat pyproject.toml
Here is where you can modify any settings for the package that you'd like to. The eagle-eyed among you might have noticed that pytest does not have its own section. Currently, pytest does not parse pyproject.toml for settings, so all options are manually passed to pytest in the Makefile.
I think make
is the greatest thing since sliced bread, so let's check that out.
cat Makefile
Some useful commands here to handle everything from linting to version control to packaging. Since we are going to be developing this tool, run:
make develop
DO THIS BEFORE ANYTHING ELSE. I considered adding it to the post-generation hook, but elected not to. This was, you can create a venv however you want to, and I won't bork your python install if you forget to before creating a new project.
Now, create a repo on git hub, and push your new project there.
git remote add origin https://github.com/YOUR_USER/project_name
git push origin master
The project is designed to coordinate with Travis CI, codecov, and readthedocs. All the necessary files are there, so you just need to add your new project to their websites, and codecov and readthedocs should just work.
Travis needs to know your PyPi password and username to build and publish with poetry. To pass encrypt these and pass them to the .travis.yml
file, run:
travis encrypt PYPI_USER=your_user_name --add env.global
travis encrypt PYPI_PASS=your_pass_word --add env.global
Now, you should be able to build and stribute with travis, as long as you git tag
your versions.
Happy Coding!