Skip to content

Commit

Permalink
Add black, isort and flake8
Browse files Browse the repository at this point in the history
Add .pre-commit-config.yaml to automatically test the files
  • Loading branch information
bulv1ne committed Aug 6, 2020
1 parent d134bdc commit 1d6b0a1
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 14 deletions.
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:

- repo: local
hooks:
- id: black
name: Black
entry: pipenv run black .
language: system
types: [python]
- id: isort
name: Isort
entry: pipenv run isort .
language: system
types: [python]
- id: flake8
name: Flake8
entry: pipenv run flake8
language: system
types: [python]
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
black = "==19.10b0"
flake8 = "*"
isort = "*"

[packages]
"aiohttp[speedups]" = "*"
Expand Down
157 changes: 155 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import asyncio
import io
from urllib.parse import parse_qsl, urlparse

import aiohttp
from aiohttp import web
from PIL import Image
from validation import schema
from voluptuous import MultipleInvalid

from validation import schema


def main(host, port):
app = web.Application()
Expand Down Expand Up @@ -69,5 +69,5 @@ async def stream_from_image(img, request):
HOST = "0.0.0.0"
PORT = 8000

if __name__ == '__main__':
if __name__ == "__main__":
main(HOST, PORT)
12 changes: 3 additions & 9 deletions validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

from voluptuous import Invalid, Schema

resize_validator = re.compile(r'^([1-9]\d*)x([1-9]\d*)$')
resize_validator = re.compile(r"^([1-9]\d*)x([1-9]\d*)$")


def is_resize(s):
result = resize_validator.match(s)
if result is None:
raise Invalid('Invalid resize')
raise Invalid("Invalid resize")
return [int(size) for size in result.groups()]


schema = Schema(
{
'source': str,
'resize': is_resize,
},
required=True
)
schema = Schema({"source": str, "resize": is_resize}, required=True)

0 comments on commit 1d6b0a1

Please sign in to comment.