Skip to content

Commit

Permalink
Add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
silentsokolov committed Oct 19, 2022
1 parent 49dfdf5 commit 69fade4
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 210 deletions.
44 changes: 26 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: "build"

on:
on: # yamllint disable-line rule:truthy
pull_request:
push:
branches: master
Expand Down Expand Up @@ -47,27 +48,34 @@ jobs:
flask-version: "1.1.*"
- python-version: 3.9
flask-version: "2.0.*"
coverage: true

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install Flask ${{ matrix.flask-version }}
run: |
pip install Flask==${{ matrix.flask-version }}
pip install pillow
pip install codecov
pip install mock
- name: Install Flask ${{ matrix.flask-version }}
run: |
pip install Flask==${{ matrix.flask-version }}
pip install pillow
pip install coverage
pip install mock
- name: Run tests
run: |
PYTHONPATH=".:tests:$PYTHONPATH" coverage run --omit='setup.py' --omit='tests/*' --source='.' setup.py test
- name: Run tests
run: |
make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
- if: ${{ matrix.coverage }}
run: |
make coverage
- if: ${{ matrix.coverage }}
name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: "Lint"

on: # yamllint disable-line rule:truthy
pull_request:
push:
branches: master

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Upgrade Setuptools
run: pip install --upgrade setuptools wheel

- name: Install requirements
run: pip install -r requirements-dev.txt

- name: Run lint
run: make lint
35 changes: 18 additions & 17 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: PyPI Release
---
name: "PyPI Release"

on:
on: # yamllint disable-line rule:truthy
push:
tags:
- 'v*'
Expand All @@ -11,22 +12,22 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Setup Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Upgrade Setuptools
run: pip install --upgrade setuptools wheel
- name: Upgrade Setuptools
run: pip install --upgrade setuptools wheel

- name: Build Distribution
run: python setup.py sdist bdist_wheel --universal
- name: Build Distribution
run: python setup.py sdist bdist_wheel --universal

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
10 changes: 10 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
extends: default

rules:
line-length: disable

ignore: |
*.venv/
*.mypy_cache/
*.eggs/
45 changes: 40 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
.PHONY: test sdist wheel release pre-release clean

test:
python setup.py test
.PHONY: check-black check-isort check-pylint static-analysis test sdist wheel release pre-release clean

sdist:
python setup.py sdist
Expand All @@ -19,4 +16,42 @@ clean:
find . | grep -E '(__pycache__|\.pyc|\.pyo$)' | xargs rm -rf
rm -rf build
rm -rf dist
rm -rf *.egg-info
rm -rf *.egg-info

check-black:
@echo "--> Running black checks"
@black --check --diff .

check-isort:
@echo "--> Running isort checks"
@isort --check-only .

check-pylint:
@echo "--> Running pylint checks"
@pylint `git ls-files '*.py'`

check-yamllint:
@echo "--> Running yamllint checks"
@yamllint .

lint: check-black check-isort check-pylint check-yamllint

# Format code
.PHONY: fmt

fmt:
@echo "--> Running isort"
@isort .
@echo "--> Running black"
@black .

# Test
.PHONY: test

test:
@echo "--> Running tests"
PYTHONPATH=".:tests:${PYTHONPATH}" python setup.py test

coverage:
@echo "--> Running coverage"
PYTHONPATH=".:tests:${PYTHONPATH}" coverage run --omit='setup.py' --omit='tests/*' --source='.' setup.py test
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ If you want to store the thumbnail in a folder other than the ``THUMBNAIL_MEDIA_
app.config['THUMBNAIL_MEDIA_THUMBNAIL_ROOT'] = '/home/www/media/cache'
app.config['THUMBNAIL_MEDIA_THUMBNAIL_URL'] = '/media/cache/'
app.config['THUMBNAIL_STORAGE_BACKEND'] = 'flask_thumbnails.storage_backends.FilesystemStorageBackend'
app.config['THUMBNAIL_DEFAUL_FORMAT'] = 'JPEG'
app.config['THUMBNAIL_DEFAULT_FORMAT'] = 'JPEG'
Migrate 0.X to 1.X
Expand Down
4 changes: 2 additions & 2 deletions flask_thumbnails/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import unicode_literals

__author__ = 'Dmitriy Sokolov'
__version__ = '1.1.0'
__author__ = "Dmitriy Sokolov"
__version__ = "1.1.0"

from .thumbnail import Thumbnail
14 changes: 7 additions & 7 deletions flask_thumbnails/storage_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BaseStorageBackend(object):
def __init__(self, app=None):
self.app = app

def read(self, filepath, **kwargs):
def read(self, filepath, mode="rb", **kwargs):
raise NotImplementedError

def exists(self, filepath):
Expand All @@ -21,12 +21,12 @@ def save(self, filepath, data):


class FilesystemStorageBackend(BaseStorageBackend):
def read(self, filepath, mode='rb'):
with open(filepath, mode) as f:
def read(self, filepath, mode="rb", **kwargs):
with open(filepath, mode) as f: # pylint: disable=unspecified-encoding
return f.read()

def exists(self, name):
return os.path.exists(name)
def exists(self, filepath):
return os.path.exists(filepath)

def save(self, filepath, data):
directory = os.path.dirname(filepath)
Expand All @@ -39,7 +39,7 @@ def save(self, filepath, data):
raise

if not os.path.isdir(directory):
raise IOError('{} is not a directory'.format(directory))
raise IOError("{} is not a directory".format(directory))

with open(filepath, 'wb') as f:
with open(filepath, "wb") as f:
f.write(data)
Loading

0 comments on commit 69fade4

Please sign in to comment.