From ef3ba042d489b2c4b85b487d7b5d3373d4dddf13 Mon Sep 17 00:00:00 2001 From: Hsiaoming Yang Date: Fri, 28 Jul 2023 23:51:55 +0900 Subject: [PATCH] chore: add github action, update readme --- .github/workflows/test.yml | 61 ++++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ MANIFEST.in | 3 ++ README.md | 58 ++++++++++++++++++++++++++++++++++++ README.rst | 43 ++++++--------------------- requirements.txt | 1 + src/captcha/image.py | 2 +- 7 files changed, 135 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 README.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5d9901d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,61 @@ +name: Test + +on: + push: + branches-ignore: + - 'wip-*' + paths-ignore: + - '.github/**' + - 'docs/**' + - '*.md' + - '*.rst' + pull_request: + branches-ignore: + - 'wip-*' + paths-ignore: + - '.github/**' + - 'docs/**' + - '*.md' + - '*.rst' + + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.8" + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: flake8 lint + run: flake8 src/captcha + + - name: mypy lint + run: mypy + + test: + needs: lint + runs-on: ubuntu-latest + + strategy: + fail-fast: false + max-parallel: 3 + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Report coverage + run: pytest --cov=captcha --cov-report=xml diff --git a/.gitignore b/.gitignore index c65e799..edf3c05 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ cover/ *.so venv/ .venv/ +.coverage +coverage.xml diff --git a/MANIFEST.in b/MANIFEST.in index 613fd93..fdfe22b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,3 +2,6 @@ include LICENSE include README.rst recursive-include src/captcha/data *.wav recursive-include src/captcha/data *.ttf + +graft docs +prune docs/_build diff --git a/README.md b/README.md new file mode 100644 index 0000000..a0546c6 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# Captcha + +A captcha library that generates audio and image CAPTCHAs. + + +[![GitHub Sponsor](https://badgen.net/badge/support/captcha/blue?icon=github)](https://github.com/sponsors/lepture) +[![Build Status](https://github.com/lepture/captcha/actions/workflows/test.yml/badge.svg)](https://github.com/lepture/captcha/actions) +[![PyPI](https://badgen.net/pypi/v/captcha)](https://pypi.org/project/captcha) +[![Code Coverage](https://codecov.io/gh/lepture/captcha/branch/main/graph/badge.svg?token=WCD9X8HKI1)](https://codecov.io/gh/lepture/captcha) + +## Install + +Install captcha with pip: + +``` +pip install captcha +``` + +## Features + +1. Audio CAPTCHAs +2. Image CAPTCHAs + +## Usage + +Audio and Image CAPTCHAs are in separated modules: + +```python +from captcha.audio import AudioCaptcha +from captcha.image import ImageCaptcha + +audio = AudioCaptcha(voicedir='/path/to/voices') +image = ImageCaptcha(fonts=['/path/A.ttf', '/path/B.ttf']) + +data = audio.generate('1234') +audio.write('1234', 'out.wav') + +data = image.generate('1234') +image.write('1234', 'out.png') +``` + +This is the APIs for your daily works. We do have built-in voice data and font +data. But it is suggested that you use your own voice and font data. + +## Useful Links + +1. GitHub: https://github.com/lepture/captcha +2. Docs: https://captcha.lepture.com/ + +## Demo + +Here are some demo results: + +1. Image: + + ![Image](https://cloud.githubusercontent.com/assets/290496/5213632/95e68768-764b-11e4-862f-d95a8f776cdd.png) + +2. Audio: [wav file](https://github.com/lepture/captcha/releases/download/v0.1-beta/out.wav) diff --git a/README.rst b/README.rst index cb7570e..700dded 100644 --- a/README.rst +++ b/README.rst @@ -3,27 +3,12 @@ Captcha A captcha library that generates audio and image CAPTCHAs. -.. image:: https://img.shields.io/badge/donate-lepture-ff69b4.svg - :target: https://lepture.com/donate - :alt: Donate lepture -.. image:: https://img.shields.io/badge/I0-patreon-f96854.svg - :target: https://patreon.com/lepture - :alt: Become a Patreon -.. image:: https://travis-ci.org/lepture/captcha.svg?branch=master - :target: https://travis-ci.org/lepture/captcha -.. image:: https://ci.appveyor.com/api/projects/status/amm21f13lx4wuura?svg=true - :target: https://ci.appveyor.com/project/lepture/captcha -.. image:: https://coveralls.io/repos/lepture/captcha/badge.svg?branch=master - :target: https://coveralls.io/r/lepture/captcha - Features -------- -1. Audio CAPTCHAs `DEMO `_ +1. Audio CAPTCHAs 2. Image CAPTCHAs -.. image:: https://cloud.githubusercontent.com/assets/290496/5213632/95e68768-764b-11e4-862f-d95a8f776cdd.png - Installation ------------ @@ -54,25 +39,15 @@ Audio and Image CAPTCHAs are in separated modules: This is the APIs for your daily works. We do have built-in voice data and font data. But it is suggested that you use your own voice and font data. -Voices ------- - -We can build our customized voice library with the help of espeak and ffmpeg:: - - export ESLANG=en - - mkdir $ESLANG - - for i in {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9}; do mkdir $ESLANG/$i; espeak -a 150 -s 100 -p 15 -v$ESLANG $i -w $ESLANG/$i/orig_default.wav; ffmpeg -i $ESLANG/$i/orig_default.wav -ar 8000 -ac 1 -acodec pcm_u8 $ESLANG/$i/default.wav; rm $ESLANG/$i/orig_default.wav; done - - -Contribution +Useful Links ------------ -We need voice wav files. The voice wav file should be in 8-bit, please keep it -as small as possible. Name your voice file as:: +1. GitHub: https://github.com/lepture/captcha +2. Docs: https://captcha.lepture.com/ - {{language}}-{{character}}-{{username}}.wav - # example: zh-1-lepture.wav -TODO: we need a place to upload voice files. +License +------- + +Licensed under BSD. Please see LICENSE for licensing details. + diff --git a/requirements.txt b/requirements.txt index 026ef54..707e8f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ Pillow types-Pillow pytest +pytest-cov flake8 mypy diff --git a/src/captcha/image.py b/src/captcha/image.py index 49c73a2..27b5549 100644 --- a/src/captcha/image.py +++ b/src/captcha/image.py @@ -213,7 +213,7 @@ class ImageCaptcha: def random_color( start: int, end: int, - opacity: t.Optional[int]=None) -> ColorTuple: + opacity: t.Optional[int] = None) -> ColorTuple: red = random.randint(start, end) green = random.randint(start, end) blue = random.randint(start, end)