Commit 8d12806a authored by inkhey's avatar inkhey
Browse files

ci(pre-commit): add precommit hooks and support for commitizen

parent dc1500e3
Pipeline #352748 passed with stages
in 46 seconds
......@@ -10,3 +10,4 @@ __pycache__
/build
/dist
.mypy_cache/
.current_commit_message
......@@ -2,7 +2,7 @@
image: python:latest
before_script:
- python -V # Print out python version for debugging
- python -V # Print out python version for debugging
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
......@@ -13,12 +13,10 @@ before_script:
- pip install -e ".[testing]"
- pytest
stages:
- test
- publish
pytest_latest:
image: python:latest
<<: *pytest
......
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: check-json
- id: check-yaml
- id: debug-statements
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-merge-conflict
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.770'
hooks:
- id: mypy
args: [--ignore-missing-imports]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.17.0
hooks:
- id: yamllint
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
files: 'pioupiou'
additional_dependencies: [
'flake8-builtins',
'flake8-bugbear',
'flake8-comprehensions',
'flake8_tuple',
'flake8-bandit'
]
- id: flake8
files: 'tests'
additional_dependencies: [
'flake8-bugbear',
'flake8-comprehensions',
'flake8_tuple',
'flake8-builtins'
]
- repo: https://github.com/asottile/seed-isort-config
rev: v1.8.0
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: 'v4.3.18'
hooks:
- id: isort
files: 'pioupiou/(.*)/*.py'
- id: isort
files: 'tests/(.*)/*.py'
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
args: [-l 100]
files: 'pioupiou'
- id: black
args: [-l 100]
files: 'tests'
# Dependencies
- repo: https://github.com/jazzband/pip-tools
rev: 5.0.0
hooks:
- id: pip-compile
- repo: https://github.com/twu/skjold
rev: v0.1.6
hooks:
- id: skjold
# Import
- repo: https://github.com/asottile/seed-isort-config
rev: v1.8.0
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: "v4.3.18"
hooks:
- id: isort
files: "pioupiou/(.*)/*.py"
- id: isort
files: "tests/(.*)/*.py"
# type-checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.770"
hooks:
- id: mypy
args: [--ignore-missing-imports]
# Few check
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
files: "pioupiou"
additional_dependencies:
[
"flake8-builtins",
"flake8-bugbear",
"flake8-comprehensions",
"flake8_tuple",
"flake8-bandit",
]
- id: flake8
files: "tests"
additional_dependencies:
["flake8-bugbear", "flake8-comprehensions", "flake8_tuple", "flake8-builtins"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
# format check
- id: check-json
- id: check-yaml
- id: check-toml
- id: check-xml
- id: check-symlinks
- id: trailing-whitespace
- id: end-of-file-fixer
- id: mixed-line-ending
# content check
- id: check-vcs-permalinks
- id: check-case-conflict
- id: check-executables-have-shebangs
# python check
- id: debug-statements
- id: name-tests-test
args: [--django]
- id: check-ast
# VCS
- id: check-added-large-files
- id: check-merge-conflict
- id: forbid-new-submodules
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.4
hooks:
- id: script-must-have-extension
- id: script-must-not-have-extension
- id: shellcheck
- id: shfmt
# Formatting
- repo: https://github.com/asottile/blacken-docs
rev: v1.8.0
hooks:
- id: blacken-docs
additional_dependencies: [black==20.8b1]
- repo: https://github.com/ambv/black
rev: 20.8b1
hooks:
- id: black
args: [-l 100]
files: "pioupiou"
- id: black
args: [-l 100]
files: "tests"
- repo: https://github.com/prettier/prettier
rev: "2.1.2"
hooks:
- id: prettier
args: [--print-width=100]
stages: [commit]
# Commit
- repo: https://github.com/commitizen-tools/commitizen
rev: master
hooks:
- id: commitizen
stages: [commit-msg]
Version 0.6
------------
## Unreleased
## 0.6 (2020-09-28)
- Add high level api with AvatarGenerator class
- remove python 3.5 support
Version 0.5.1
-------------
## 0.5.2 (2020-04-01)
## 0.5.1 (2020-03-31)
- Breaking change ! Avatar generation use seed per layer now to be sure to not obtain same result from different layer.
Version 0.5
------------
## 0.5.0 (2020-03-31)
- add Chooser mecanism to choose mecanism for choosing layer from a hash method of hashlib
Version 0.4
------------
## 0.4.0 (2019-07-06)
- fix issue related to predictibility/reproductibility of result with FolderAvatarTheme.
PiouPiou for the same entry given, should return exactly same result in layers choosen.
Pillow configuration may cause some difference in
image file, but this case hasn't been reproduced yet. This is tested an you
can verify the behavior on your system by running TestFolderAvatarTheme test
https://framagit.org/inkhey/pioupiou/commit/067af0a7800f51a1b3a4e172f9ab47e3737d473d
PiouPiou for the same entry given, should return exactly same result in layers choosen.
Pillow configuration may cause some difference in
image file, but this case hasn't been reproduced yet. This is tested an you
can verify the behavior on your system by running TestFolderAvatarTheme test
https://framagit.org/inkhey/pioupiou/commit/067af0a7800f51a1b3a4e172f9ab47e3737d473d
- AvatarTheme rely on specific Random() instead of random to avoid side-effect :
https://framagit.org/inkhey/pioupiou/commit/8f9535324adf85bc62dc19cd5cd3ab8a3b063862
https://framagit.org/inkhey/pioupiou/commit/8f9535324adf85bc62dc19cd5cd3ab8a3b063862
- minors changes around README.txt
Version 0.3
-------------
## 0.3.1 (2019-07-06)
## 0.3.0 (2019-07-04)
- Initial Feature
- First Pypi release
### Tests
- clone this repository
- `pip install -e ".[dev]"`
### Pre-commit
---
To enforce most required guidelines, please use the precommit mechanism.
This will perform some automatic checks before committing.
To use it, you need the `pre-commit` Python
you can then install hooks with:
```shell script
pre-commit install
pre-commit install --hook-type commit-msg
```
Then, you will be able to notice the automatic checks when running `git commit`.
To run pre-commit on all files:
```shell script
cz changelog --incremental
```
## Commit and Changelog
This software do use commitizen. So you should make valid commit message.
to do so, we recommand you to type :
```shell script
cz commit --dry-run > .current_commit_message
git commit -eF .current_commit_message
```
you can also use cz check : see https://commitizen-tools.github.io/commitizen/check/
To update the changelog:
```shell script
cz changelog --incremental
```
# PiouPiou
![logo](pioupiou.png)
![pipeline_build_status](https://framagit.org/inkhey/pioupiou/badges/master/pipeline.svg)
......@@ -8,22 +9,20 @@ # PiouPiou
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
![mypy](https://img.shields.io/badge/mypy-checked-blueviolet)
An avatar generator optimised for generating random avatars based on multiple image layers, able to return same image from a string "seed".
Heavily inspired by [David Revoy](http://www.peppercarrot.com)'s [cat avatar generator](https://framagit.org/Deevad/cat-avatar-generator/) and [MonsterID by Andreas Gohr's](https://www.splitbrain.org/blog/2007-01/20_monsterid_as_gravatar_fallback).
This generator relies on the Pillow library to do image processing.
See a [Demo](https://pioupiou.inkey-art.net/) (running [pioupiouweb from buxx](https://github.com/buxx/pioupiouweb)).
## Install
### From pypi
~~~sh
```sh
$ pip install pioupiou
~~~
```
### From source
......@@ -36,57 +35,67 @@ ## High Level Api
The high level Api will help you choose avatar between multiples themes, according to installed themes.
~~~python
```python
from pioupiou import AvatarGenerator
# check sample/example.py for code to build default sample themes
from sample.example import generate_default_themes
themes = generate_default_themes(sample_dir_path="./sample")
avatar_generator = AvatarGenerator(themes)
# note: you can override default theme list and/or theme chooser (mecanism to randomly choose a theme according to token)
avatar = avatar_generator.generate_avatar(token="just a random string")
avatar_generator.save_on_disk(avatar, path="/tmp/saved_file.png")
# note: you can choose a specific theme according to activate theme
avatar = avatar_generator.generate_avatar(theme_name='cat_revoy', token="just a random string")
avatar = avatar_generator.generate_avatar(
theme_name="cat_revoy", token="just a random string"
)
avatar_generator.save_on_disk(avatar, path="/tmp/saved_file_2.png")
~~~
```
## Low Level Api (AvatarTheme)
The easy way to use it is to be based on FolderAvatarTheme. To do this, you should create many .png file of same image, all
with transparency. You should follow a similar naming pattern as in the following example.
To test it, you can, for instance, use a cat avatar [by David Revoy](http://www.peppercarrot.com):
~~~python
```python
from pioupiou import FolderAvatarTheme
theme = FolderAvatarTheme(folder_path="sample/cat_revoy", layers_name=["body", "fur","eyes","mouth","accessorie"])
theme = FolderAvatarTheme(
folder_path="sample/cat_revoy",
layers_name=["body", "fur", "eyes", "mouth", "accessorie"],
)
avatar = theme.generate_avatar(token="just a random string")
theme.save_on_disk(avatar, path="/tmp/saved_file.png")
~~~
```
Or a bird avatar [by David Revoy](http://www.peppercarrot.com):
~~~python
```python
from pioupiou import FolderAvatarTheme
theme = FolderAvatarTheme(
"sample/bird_revoy",
layers_name=["tail", "hoop", "body", "wing", "eyes", "bec", "accessorie"],
)
avatar = theme.generate_avatar(token="just a random string")
theme.save_on_disk(avatar, path="/tmp/saved_file.png")
~~~
```
Or a Monster avatar [by Andreas Gohr's](https://www.splitbrain.org/blog/2007-01/20_monsterid_as_gravatar_fallback):
~~~python
```python
from pioupiou import FolderAvatarTheme
theme = FolderAvatarTheme(
"sample/monster_id",
layers_name=["legs", "hair", "arms", "body", "eyes", "mouth"],
)
avatar = theme.generate_avatar(token="just a random string")
theme.save_on_disk(avatar, path="/tmp/saved_file.png")
~~~
```
## Configure Chooser
......@@ -94,28 +103,32 @@ ## Configure Chooser
The default behaviour is to rely on `random.Random()`, but pioupiou is made to support any type of chooser.
To do this, you just need to configure the chooser with your `AvatarTheme`:
~~~python
```python
from pioupiou import FolderAvatarTheme
from random import Random
theme = FolderAvatarTheme(
folder_path="sample/cat_revoy",
layers_name=["body", "fur","eyes","mouth","accessorie"],
chooser=Random() # same as default, don't change anything
folder_path="sample/cat_revoy",
layers_name=["body", "fur", "eyes", "mouth", "accessorie"],
chooser=Random(), # same as default, don't change anything
)
~~~
```
You can use any hashlib algorithm you want from `hashlib`, using `pioupiou.chooser.HashLibChooser`.
It will make choices using a modulo.
~~~python
```python
from pioupiou import FolderAvatarTheme
import hashlib
from pioupiou.chooser import HashLibChooser
theme = FolderAvatarTheme(
folder_path="sample/cat_revoy",
layers_name=["body", "fur","eyes","mouth","accessorie"],
chooser=HashLibChooser(hashlib.sha256()) # hashlib.sha256() is just an example, hashlib.md5() should also work for example.
folder_path="sample/cat_revoy",
layers_name=["body", "fur", "eyes", "mouth", "accessorie"],
chooser=HashLibChooser(
hashlib.sha256()
), # hashlib.sha256() is just an example, hashlib.md5() should also work for example.
)
~~~
```
You can also implement `pioupiou.chooser.Chooser` and use a custom chooser.
[build-system]
requires = ["setuptools>=30.3.0", "wheel", "setuptools_scm"]
[tool.skjold]
sources = ["gemnasium"]
......@@ -6,4 +6,4 @@
#
dataclasses==0.6 # via pioupiou (setup.py)
name-me==0.1.0 # via pioupiou (setup.py)
pillow==3.1.0 # via pioupiou (setup.py)
pillow==8.0.0 # via pioupiou (setup.py)
File mode changed from 100755 to 100644
Cat avatar Generator
====================
# Cat avatar Generator
Source code and graphics CC-By [1] David Revoy [2] ( artworks of Cats and open-raster file )
Originally inspired of the code for "MonsterID" by Andreas Gohr [3].
If you use this software and/or graphics please link back to http://www.splitbrain.org/go/monsterid, http://www.peppercarrot.com
How to edit:
============
# How to edit:
1. Open img/00_SRC.ora with Krita. Do your edit/draw/paint, respect layer naming, save.
2. Open it again in Gimp, with the 'export layer plugin' [4]
3. Scale the image down to the result you want (eg. 256px x 256px as on the demo )
3. File > Export layer. Allow invisible layer to be exported, check 'image size', PNG
4. Done. PNG files of 'parts' extracted.
4. File > Export layer. Allow invisible layer to be exported, check 'image size', PNG
5. Done. PNG files of 'parts' extracted.
[1] http://creativecommons.org/licenses/by/4.0/
[2] http://www.peppercarrot.com
......
......@@ -18,7 +18,7 @@
"name-me"
]
tests_require = ["pytest"]
devtools_require = ["flake8", "isort", "mypy", "pre-commit"]
devtools_require = ["flake8", "isort", "mypy", "pre-commit", "commitizen"]
if sys.version_info.major == 3 and sys.version_info.minor >= 6:
devtools_require.append("black")
install_requires.append("dataclasses")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment