Skip to content

Commit

Permalink
Merge branch 'main' into feature/update-boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
Basti Tee committed Aug 19, 2023
2 parents e2ca065 + 722a9d5 commit c1f6de5
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 27 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: "${{ matrix.python-version }}"
architecture: "x64"

- name: CI checks
run: |
python3 -m pip install wheel poetry
python -m pip install wheel poetry
make
76 changes: 76 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Changelog

## 0.2.0

* Added a script installer for fast CLI access
* Improved readability and infos in README

[#10](https://github.com/BastiTee/python-boilerplate/pull/10)

## 0.1.0

* Removed all explicit calls for Python 3 and assuming it everywhere (including project name) [#8](https://github.com/BastiTee/python-boilerplate/pull/8)
* Added a changelog [#9](https://github.com/BastiTee/python-boilerplate/pull/9)

## 0.0.9

* Added support for Python 3.9-3.11
* Updated dependencies

[#6](https://github.com/BastiTee/python-boilerplate/pull/6)
[#7](https://github.com/BastiTee/python-boilerplate/pull/7)

## 0.0.8

* Removed a lot of remaining boilerplate
* Reduced dependencies
* Improved Makefile
* Improve rename script

[#5](https://github.com/BastiTee/python-boilerplate/pull/5)

## 0.0.7

* Introduced black code formatting
* Cleaned up README.md

[#4](https://github.com/BastiTee/python-boilerplate/pull/4)

## 0.0.6

* Migrated from pipenv to poetry
* Introduced matrix testing via Github actions
* Updated configuration files

[#3](https://github.com/BastiTee/python-boilerplate/pull/3)

## 0.0.5

* Add mypy support
* Fix test discovery in VSCode
* Add PyLance support

## 0.0.4

* Fix Intellisense for VScode
* Integrate configuration files

## 0.0.3

* Update boilerplate tooling to 2020

## 0.0.2

First release. Contains support for:

* Flask-based dummy application running on http://localhost:9690
* Basic project/module organization according to https://packaging.python.org
* Makefile-like management script
* pipenv virtual environments
* setup.py-based installer script
* Unit testing with pyTest
* Multicore/-interpreter testing with detox
* Linting (flake8) and code formatting (autopep8) support
* vscode editor configuration including debugging support, unit test discovery and on-save formatting
* Dockerized builds and run with nginx/uwsgi
* Publishing to PyPi.org at https://pypi.org/project/python3-boilerplate/
45 changes: 30 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ export LANG = C.UTF-8
PY_FILES := my_module tests
VERSION := $(shell poetry version --short)

# Bundle tasks

all: clean venv build
@echo Executed default build pipeline

# Clean up and set up

clean:
@echo Clean project base
Expand All @@ -28,20 +33,33 @@ clean:
-name "dist" \
|xargs rm -rfv

clear-cache:
@echo Clear poetry cache
$(POETRY_CMD) cache clear pypi --all --no-interaction

venv: clean
@echo Initialize virtualenv, i.e., install required packages etc.
$(POETRY_CMD) config virtualenvs.in-project true --local
$(POETRY_CMD) env use python3
$(POETRY_CMD) install

shell:
@echo Open a new shell using virtualenv
$(POETRY_CMD) shell

# Building software

build: test mypy isort black lint
@echo Run build process to package application
$(POETRY_CMD) build

test:
@echo Run all tests suites
$(POETRY_CMD) run py.test tests

mypy:
@echo Run static code checks against source code base
$(POETRY_CMD) run mypy $(PY_FILES)

isort:
@echo Check for incorrectly sorted imports
$(POETRY_CMD) run isort --check-only $(PY_FILES)
Expand All @@ -50,10 +68,6 @@ isort-apply:
@echo Check and correct incorrectly sorted imports
$(POETRY_CMD) run isort $(PY_FILES)

mypy:
@echo Run static code checks against source code base
$(POETRY_CMD) run mypy $(PY_FILES)

black:
@echo Run code formatting using black
$(POETRY_CMD) run black $(PY_FILES)
Expand All @@ -62,24 +76,25 @@ lint:
@echo Run code formatting checks against source code base
$(POETRY_CMD) run flake8 $(PY_FILES)

build: test mypy isort black lint
@echo Run build process to package application
$(POETRY_CMD) build
# Executing and publishing

run:
@echo Execute package directly
run-venv:
@echo Execute package directly in virtual environment
$(POETRY_CMD) run python -m my_module

clear-cache:
@echo Clear poetry cache
$(POETRY_CMD) cache clear pypi --all --no-interaction
install-run:
@echo Install and run package via CLI using the activated Python env
python -m pip install --upgrade .
@echo --- Note: The next command might fail before you reload your shell
my_module_cli

outdated:
@echo Show outdated dependencies
$(POETRY_CMD) show --outdated

publish:
@echo Release version $(VERSION) to pypi.org and create git tag
$(POETRY_CMD) publish
@echo Release version $(VERSION)
git tag -a $(VERSION) -m "Version $(VERSION)"
git push --tags
# Uncomment the following line to integrate with pypi publishing
# $(POETRY_CMD) publish
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# python3-boilerplate ![CI](https://github.com/BastiTee/python3-boilerplate/workflows/CI/badge.svg)
# python-boilerplate ![CI](https://github.com/BastiTee/python-boilerplate/workflows/CI/badge.svg)

> A best-practices template project for Python modules
## Setup

- [Use this template.](https://github.com/BastiTee/python3-boilerplate/generate)
- Make sure that `python` and [`poetry`](https://python-poetry.org/) has been properly installed (Python 2 is not supported – :skull:) which is usually a simple `python -m pip install poetry`
- On first checkout run `make` to initialize the project configuration and build everything
- Refer to [the Makefile](Makefile) to learn about the various operations available. Most of them are just facades for `poetry`
- To rename the project you can use [the provided script](rename_template.sh): `./rename_template.sh`
- Create a new repository [using this template](https://github.com/BastiTee/python-boilerplate/generate).
- Make sure that `python` is installed and available on system path. I recommend using [`pyenv`](https://github.com/pyenv/pyenv). Note that Python 2 is _not_ supported. It's end of life was on January 1st, 2020.
- Make sure [`poetry`](https://python-poetry.org/) is installed. This usually just means `python -m pip install poetry`.
- Rename the project using [the provided script](rename_template.sh): `./rename_template.sh`.
- Run `make` to initialize the project configuration and build everything.
- Refer to [the Makefile](Makefile) to learn about the various operations available. Most of them are just facades for `poetry`.

## Features

Expand All @@ -22,7 +23,8 @@
- [mpyp](https://pypi.org/project/mypy/) support for type checking
- Publishing to PyPi.org
- [vscode](https://code.visualstudio.com/) editor configuration including plugin recommendations, debugging support, unit test discovery and on-save formatting
- [Github actions](https://github.com/BastiTee/python3-boilerplate/actions) continuous integration with multi-python testing
- [Github actions](https://github.com/BastiTee/python-boilerplate/actions) continuous integration with multi-python testing
- Executable script so after package installation you can run from the CLI using `my_module_cli`

## Resources

Expand All @@ -37,9 +39,9 @@

## Future ideas and todos

- Introduce Python 3.10 to test matrix
- Embed flake8 config into `pyproject.toml` once they support it ([see](https://github.com/PyCQA/flake8/issues/234))
- Use cookiecutter instead of [shell script](./rename_template.sh) (it does work fine at the moment though)

## Licensing

This project is licensed under [Apache License 2.0](LICENSE.txt)
This project is licensed under [Apache License 2.0](LICENSE.txt).
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "my_module"
version = "0.0.8"
version = "0.2.0"
description = ""
license = "Apache 2.0"
authors = ["Basti Tee <basti.tee@posteo.de>"]
Expand Down Expand Up @@ -38,6 +38,9 @@ typing-extensions = "^4"
black = "^23"
pipdeptree = "^2"

[tool.poetry.scripts]
my_module_cli = 'my_module.__main__:main'

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Expand Down

0 comments on commit c1f6de5

Please sign in to comment.