This repository provides a cookiecutter template that allows you to set up a Python project from scratch.
- Linux based system (... sorry for all Windows users)
- cookiecutter
-
Create new project by running:
cookiecutter gh:milost/cookiecutter-python
After cookiecutter
has successfully set up the project, you can run make
in the root folder of the generated project directory to get a list of supported targets.
make install env=dev
ormake install
for installing without development dependencies.- After the successful installation of the environment it can be activated by running the target
make activate
. - Next, it is advisable to put the newly created project into a version control system. Currently only this template supports only GitHub. To set up a repository, use the
repo
target and executemake repo
. If you also want to create a remote repository on GitHub runmake repo create-remote=true
. This only creates a remote repository on GitHub but doesn't push your inital codebase, to do that, runmake repo create-remote=true push=true
. Remember for this target to work properly, you need to set a GitHub access token in the.env
file.
NOTE!
To use the following targets, you need to provide the corresponding tokens in the .env
file:
make repo create-remote=true
- requires a GITHUB_ACCESS_TOKENmake publish
- requires a PYPI_TOKENmake docker-publish
- requires a DOCKER_TOKENmake test-publish
- requires a CODECOV_TOKEN
Target | Description |
---|---|
install-pyenv |
Install pyenv and pyenv-virtualenv |
install [env=dev] |
Setup virtual environment and install project dependencies |
activate |
Activate the current project environment |
flush-env |
Delete the virtual environment for this project |
reinstall |
Deletes and recreates the virtual environment |
repo [create-remote=true] [remote=URL] [push=true] |
Create a git repository for the project |
Target | Description |
---|---|
run |
Execute main method of python project |
lint |
Run linter (flake8) over project files |
update |
Update project dependencies |
release [part=[major,minor,patch]] |
Increment package version |
Target | Description |
---|---|
test [coverage=true] [show=true] |
Run tests quickly with the default Python |
test-upload |
Upload test results to online services (codecov) |
Target | Description |
---|---|
build |
Build sdist and wheel distributions |
sdist |
Build sdist distribution |
wheel |
Build wheel distribution |
publish |
Build distribution using build target and upload it to PyPi |
Target | Description |
---|---|
clean |
Clean build, python, and test artifacts |
clean-build |
Clean build artifacts |
clean-pyc |
Clean python artifacts |
clean-test |
Clean test artifacts |
Target | Description |
---|---|
docs [show=true] |
Generate Sphinx HTML documentation, including API docs |
import-docs |
Import the current project to ReadTheDocs |
Target | Description |
---|---|
docker-image |
Build docker image |
docker-rebuild |
Rebuild docker image |
docker-remove |
Remove docker image |
docker-publish |
Push docker image to docker hub |
docker-run |
Execute the latest docker image |
docker-service |
Run Docker image as a service |
docker-shell |
Run Docker image as service and attach to it |
The unique repository upload token is found on the settings page of your project. You need write access to view this token.
The unique repository upload token is found on the settings page of your project. You need write access to view this token.
To be able to push your image to docker hub you need an access token. Instructions on how to generate an access token can be found here. Once you have an access token, you can set the DOCKER_TOKEN
environment variable in the .env
file which is located in the projects root directory.
After the project has been created with cookiecutter
, everything is already configured so that the documentation can be generated by ReadTheDocs. Once the repository has been is published on, say, GitHub, it can be imported into your ReadTheDocs account. To do this you can proceed as follows:
- Login to ReadTheDocs using your GitHub account
- Go to the ReadTheDocs dashboard
- Click on Import a project
- Choose the project for which you want the generate the documentation (the
+
button next to the project name) - On the next page, simply press the
Next
button and your project will be imported into ReadTheDocs.
From now on ReadTheDocs will keep track and generate a new project documentation for every new release.
To be able to create a new GitHub repository for your project a personal access token is
needed to access your GitHub account. Instructions on how to create a personal access token
can be found here.
Once the token has been created you can either set it as env variable yourself or set
the GITHUB_ACCESS_TOKEN
variable in the .env
file. After that you can use the repo
target to create a repository on GitHub over the command line by exexcuing make repo create-remote=true
. If you want to immediately push your initial project setup to GitHub use make repo create-remote=true push=true
.