diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml new file mode 100644 index 0000000..63ee7e7 --- /dev/null +++ b/.github/workflows/code_checks.yml @@ -0,0 +1,32 @@ +name: Code checks + +on: push + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - name: Run pycodestyle + run: | + pip install pycodestyle + ./pycodestyle.sh + if [[ $? -ne 0 ]]; then + echo "Linting failed, please reformat your code" + exit 1 + fi + + test: + runs-on: ubuntu-latest + needs: lint + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - name: Install test dependencies + run: | + pip install -r requirements.txt + pip install coverage + - name: Run tests + run: | + LANGUAGE=en_GB:en coverage run --source=flask_table setup.py test \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 837b086..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: python -python: - - "2.7" - - "3.5" - - "3.6" -install: - - "pip install pep8 coverage coveralls" - - "pip install -r requirements.txt" -before_script: - "./pep8.sh" -script: - "LANGUAGE=en_GB:en coverage run --source=flask_table setup.py test" -after_success: - coveralls diff --git a/examples/attr_list.py b/examples/attr_list.py index 17c63b3..6c2c7a8 100644 --- a/examples/attr_list.py +++ b/examples/attr_list.py @@ -35,5 +35,6 @@ def main(): tab = ItemTable(items) print(tab.__html__()) + if __name__ == '__main__': main() diff --git a/examples/column_html_attrs.py b/examples/column_html_attrs.py index 881e015..c2e49dc 100644 --- a/examples/column_html_attrs.py +++ b/examples/column_html_attrs.py @@ -92,5 +92,6 @@ def main(): Except it doesn't bother to prettify the output. """ + if __name__ == '__main__': main() diff --git a/examples/csrf.py b/examples/csrf.py index e13ba1c..f180d89 100644 --- a/examples/csrf.py +++ b/examples/csrf.py @@ -37,6 +37,7 @@ def single_item(id): def get_table_class(): csrf_token = get_csrf_token() + class ItemTable(Table): name = Col('Name') description = Col('Description') @@ -67,6 +68,7 @@ def get_elements(cls): def get_element_by_id(cls, id): return [i for i in cls.get_elements() if i.id == id][0] + def main(): app.run(debug=True) diff --git a/examples/datetimecol.py b/examples/datetimecol.py index 4a1d2fc..2ff03d6 100644 --- a/examples/datetimecol.py +++ b/examples/datetimecol.py @@ -34,5 +34,6 @@ def main(): # or {{ table }} in jinja print(table.__html__()) + if __name__ == '__main__': main() diff --git a/examples/external_url_col.py b/examples/external_url_col.py index e120a19..3a5140f 100644 --- a/examples/external_url_col.py +++ b/examples/external_url_col.py @@ -32,5 +32,6 @@ def main(): tab = ItemTable(items) print(tab.__html__()) + if __name__ == '__main__': main() diff --git a/examples/simple.py b/examples/simple.py index 8a50019..5fdcf97 100644 --- a/examples/simple.py +++ b/examples/simple.py @@ -57,5 +57,6 @@ def main(): Except it doesn't bother to prettify the output. """ + if __name__ == '__main__': main() diff --git a/examples/simple_nested.py b/examples/simple_nested.py index e47c33d..609781d 100644 --- a/examples/simple_nested.py +++ b/examples/simple_nested.py @@ -77,5 +77,6 @@ def main(): Except it doesn't bother to prettify the output. """ + if __name__ == '__main__': main() diff --git a/examples/simple_sqlalchemy.py b/examples/simple_sqlalchemy.py index 4bf82f4..ef348a3 100644 --- a/examples/simple_sqlalchemy.py +++ b/examples/simple_sqlalchemy.py @@ -46,5 +46,6 @@ class UserTable(Table): username = Col('Username') email = Col('Email') + users = User.query.all() print(UserTable(items=users).__html__()) diff --git a/examples/sortable.py b/examples/sortable.py index e94d7ba..fca2233 100644 --- a/examples/sortable.py +++ b/examples/sortable.py @@ -66,5 +66,6 @@ def get_sorted_by(cls, sort, reverse=False): def get_element_by_id(cls, id): return [i for i in cls.get_elements() if i.id == id][0] + if __name__ == '__main__': app.run(debug=True) diff --git a/examples/subclassing.py b/examples/subclassing.py index 941f849..7615a3c 100644 --- a/examples/subclassing.py +++ b/examples/subclassing.py @@ -35,5 +35,6 @@ def main(): # or {{ tab }} in jinja print(tab.__html__()) + if __name__ == '__main__': main() diff --git a/examples/subclassing2.py b/examples/subclassing2.py index 902e127..76624f3 100644 --- a/examples/subclassing2.py +++ b/examples/subclassing2.py @@ -24,5 +24,6 @@ def main(): # or {{ tab }} in jinja print(tab.__html__()) + if __name__ == '__main__': main() diff --git a/flask_table/columns.py b/flask_table/columns.py index fc74d24..5ae1558 100644 --- a/flask_table/columns.py +++ b/flask_table/columns.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals -from flask import Markup, url_for +from flask import url_for +from markupsafe import Markup from babel.dates import format_date, format_datetime from flask_babel import gettext as _ diff --git a/flask_table/html.py b/flask_table/html.py index f9ca78b..ec8ec62 100644 --- a/flask_table/html.py +++ b/flask_table/html.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from functools import partial -from flask import Markup +from markupsafe import Markup def element(element, attrs=None, content='', diff --git a/flask_table/table.py b/flask_table/table.py index 9495e6e..a70324e 100644 --- a/flask_table/table.py +++ b/flask_table/table.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from collections import OrderedDict -from flask import Markup +from markupsafe import Markup from flask_babel import gettext as _ from .columns import Col diff --git a/pep8.sh b/pep8.sh deleted file mode 100755 index 5e6ec15..0000000 --- a/pep8.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -pep8 flask_table/*.py examples/*.py tests/*.py setup.py diff --git a/pycodestyle.sh b/pycodestyle.sh new file mode 100755 index 0000000..76e4d08 --- /dev/null +++ b/pycodestyle.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +pycodestyle flask_table/*.py examples/*.py tests/*.py setup.py diff --git a/requirements.txt b/requirements.txt index 68d15ec..8c5315f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Flask Flask-Babel Flask-Testing +MarkupSafe \ No newline at end of file diff --git a/setup.py b/setup.py index acecd83..8b22b4c 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ install_requires = [ 'Flask', 'Flask-Babel', + 'MarkupSafe', ] if os.path.exists('README'): diff --git a/tests/__init__.py b/tests/__init__.py index 93d4457..4e738b6 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -30,7 +30,7 @@ class Subitem(Item): def html_reduce(s): - return ''.join(l.strip() for l in s.split('\n')) + return ''.join(x.strip() for x in s.split('\n')) class TableTest(unittest.TestCase):