From 382c824ccabfbf2f5c40a08808612b93ca903523 Mon Sep 17 00:00:00 2001 From: Sebastien Corbin Date: Mon, 17 Jan 2022 13:44:27 +0100 Subject: [PATCH] Flake8 --- .github/workflows/actions.yml | 16 ++++++++-------- jsignature/forms.py | 20 ++++++++++---------- jsignature/utils.py | 14 +++++++++----- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 87d3ff2..9af3f26 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -11,7 +11,7 @@ jobs: - '2.2' - '3.2' - '4.0' - python_version: + python-version: - 3.6 - 3.7 - 3.8 @@ -19,13 +19,13 @@ jobs: - "3.10" exclude: - django_version: '2.2' - python_version: '3.10' + python-version: '3.10' - django_version: '4.0' - python_version: '3.6' + python-version: '3.6' - django_version: '4.0' - python_version: '3.7' + python-version: '3.7' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -33,17 +33,17 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python_version }} + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: - python_version: ${{ matrix.python_version }} + python-version: ${{ matrix.python-version }} - name: Cache pip uses: actions/cache@v2 with: # This path is specific to Ubuntu path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ matrix.python_version }}-${{ matrix.django_version }} + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.django_version }} - name: Install dependencies run: | @@ -58,7 +58,7 @@ jobs: - name: Test Django run: | python -W error::DeprecationWarning -W error::PendingDeprecationWarning \ - -m coverage run runtests.py + -m coverage run ./runtests.py - name: Coverage if: ${{ success() }} diff --git a/jsignature/forms.py b/jsignature/forms.py index 5b488d2..426c7c8 100644 --- a/jsignature/forms.py +++ b/jsignature/forms.py @@ -18,13 +18,13 @@ class JSignatureField(Field): widget = JSignatureWidget() def to_python(self, value): - """ - Validates that the input can be red as a JSON object. - Returns a Python list (JSON object unserialized). - """ - if value in JSIGNATURE_EMPTY_VALUES: - return None - try: - return json.loads(value) - except ValueError: - raise ValidationError('Invalid JSON format.') + """ + Validates that the input can be red as a JSON object. + Returns a Python list (JSON object unserialized). + """ + if value in JSIGNATURE_EMPTY_VALUES: + return None + try: + return json.loads(value) + except ValueError: + raise ValidationError('Invalid JSON format.') diff --git a/jsignature/utils.py b/jsignature/utils.py index e5af10a..eb3dc9a 100644 --- a/jsignature/utils.py +++ b/jsignature/utils.py @@ -14,9 +14,13 @@ def draw_signature(data, as_file=False): `data` can be a json object (list in fact) or a json string if `as_file` is True, a temp file is returned instead of Image instance """ + def _remove_empty_pts(pt): - return {'x': list(filter(lambda n: n is not None, pt['x'])), 'y': list(filter(lambda n: n is not None, pt['y']))} - + return { + 'x': list(filter(lambda n: n is not None, pt['x'])), + 'y': list(filter(lambda n: n is not None, pt['y'])) + } + if type(data) is str: drawing = json.loads(data, object_hook=_remove_empty_pts) elif type(data) is list: @@ -29,13 +33,13 @@ def draw_signature(data, as_file=False): height = int(round(max(chain(*[d['y'] for d in drawing])))) + 10 # Draw image - im = Image.new("RGBA", (width*AA, height*AA)) + im = Image.new("RGBA", (width * AA, height * AA)) draw = ImageDraw.Draw(im) for line in drawing: len_line = len(line['x']) - points = [(line['x'][i]*AA, line['y'][i]*AA) + points = [(line['x'][i] * AA, line['y'][i] * AA) for i in range(0, len_line)] - draw.line(points, fill="#000", width=2*AA) + draw.line(points, fill="#000", width=2 * AA) im = ImageOps.expand(im) # Smart crop bbox = im.getbbox()