From 10ed1b1bbf3e2ae40c32acf5f6fdba2c7c5e0790 Mon Sep 17 00:00:00 2001 From: Steffen Allner Date: Thu, 28 Jan 2021 14:44:59 +0100 Subject: [PATCH 1/2] Use pre-commit for linting. And improve the repo to current convention. --- .coveragerc | 15 +++++++++ .github/workflows/lint.yml | 43 ++++++++++++++++++++++++++ .github/workflows/tests.yml | 47 +++++++++++++++++++++++++++++ .gitignore | 12 ++++++++ .pre-commit-config.yaml | 38 +++++++++++++++++++++++ js/__init__.py | 2 +- js/tableselect/__init__.py | 7 +++-- js/tableselect/test_tableselect.rst | 11 +++++++ setup.cfg | 10 ++++++ setup.py | 4 ++- tox.ini | 28 +++++++++++++++++ 11 files changed, 213 insertions(+), 4 deletions(-) create mode 100644 .coveragerc create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 js/tableselect/test_tableselect.rst create mode 100644 setup.cfg create mode 100644 tox.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..046d7fa --- /dev/null +++ b/.coveragerc @@ -0,0 +1,15 @@ +[run] +branch = True +source = js.tableselect + +[report] +precision = 2 +fail_under = 100 + +[html] +directory = coverage-report + +[paths] +source = + js/tableselect + .tox/*/lib/python*/site-packages/js/tableselect diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..05632a9 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,43 @@ +name: Lint + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + type: [ "opened", "reopened", "synchronize" ] + +env: + FORCE_COLOR: 1 + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/pip + ~/.cache/pre-commit + key: + lint-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/.pre-commit-config.yaml') }} + restore-keys: | + lint-v1- + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install -U pip + python -m pip install pre-commit + - name: Lint + run: | + pre-commit run --all-files --show-diff-on-failure + env: + PRE_COMMIT_COLOR: always diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..4c269ac --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,47 @@ +name: tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + type: [ "opened", "reopened", "synchronize" ] + schedule: + - cron: '0 12 * * 0' # run once a week on Sunday +jobs: + tests: + strategy: + matrix: + config: + # [Python version, tox env] + - ["2.7", "py27"] + - ["3.8", "py38"] + - ["3.8", "coverage"] + runs-on: ubuntu-latest + name: ${{ matrix.config[1] }} + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.config[0] }} + - name: Pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('setup.*', 'tox.ini') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox + - name: Test + run: tox -e ${{ matrix.config[1] }} + - name: Coverage + if: matrix.config[1] == 'coverage' + run: | + pip install coveralls coverage-python-version + coveralls --service=github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c23b68a --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +*.egg-info +*.pyc +*~ +.*.swp +.coverage +.installed.cfg +.tox +bin +coverage-report +develop-eggs +dist +parts diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b805888 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,38 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + - id: trailing-whitespace + exclude: resources/ + - id: end-of-file-fixer + exclude: resources/ + - id: fix-encoding-pragma + args: [--remove] + - id: check-yaml + - id: debug-statements + language_version: python3 + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 + language_version: python3 + additional_dependencies: [flake8-typing-imports==1.9.0] + - repo: https://github.com/pre-commit/mirrors-autopep8 + rev: v1.5.4 + hooks: + - id: autopep8 + - repo: https://github.com/timothycrosley/isort + rev: 5.7.0 + hooks: + - id: isort + args: [--filter-files] + files: \.py$ + - repo: local + hooks: + - id: rst + name: rst + entry: rst-lint --encoding utf-8 + files: .rst + language: python + additional_dependencies: [pygments, restructuredtext_lint] diff --git a/js/__init__.py b/js/__init__.py index b0d6433..2a6ee8d 100644 --- a/js/__init__.py +++ b/js/__init__.py @@ -1 +1 @@ -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file +__import__('pkg_resources').declare_namespace(__name__) # pragma: nocover diff --git a/js/tableselect/__init__.py b/js/tableselect/__init__.py index 133b9f8..91d12e0 100644 --- a/js/tableselect/__init__.py +++ b/js/tableselect/__init__.py @@ -1,6 +1,9 @@ -from fanstatic import Library, Resource +from fanstatic import Library +from fanstatic import Resource from js.jquery import jquery -from js.jquery_datatables import jquery_datatables, fixed_header +from js.jquery_datatables import fixed_header +from js.jquery_datatables import jquery_datatables + library = Library('namespace', 'resources') diff --git a/js/tableselect/test_tableselect.rst b/js/tableselect/test_tableselect.rst new file mode 100644 index 0000000..8d562c5 --- /dev/null +++ b/js/tableselect/test_tableselect.rst @@ -0,0 +1,11 @@ +How to use? +=========== + +You can import tableselect from ``js.tableselect`` and ``need`` it where you +want these resources to be included on a page:: + + >>> from js.tableselect import tableselect + >>> tableselect.need() + +This already includes the respective css files. + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8ed3068 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,10 @@ +[bdist_wheel] +universal = 1 + +[isort] +lines_between_sections = 0 +lines_after_imports = 2 +no_sections = True +from_first = True +lines_between_types = 0 +force_single_line = True diff --git a/setup.py b/setup.py index 948a47c..9d290ea 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,8 @@ -from setuptools import setup, find_packages +from setuptools import find_packages +from setuptools import setup import os + version = '0.4.dev0' diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..653363c --- /dev/null +++ b/tox.ini @@ -0,0 +1,28 @@ +[tox] +envlist = + flake8, + py27, + py38, + coverage, +minversion = 1.6 + +[testenv] +usedevelop = True +extras = test +deps = pytest +commands = py.test [] + +[testenv:coverage] +deps = + {[testenv]deps} + pytest-cov +commands = py.test --cov=js --cov-report=html --cov-report=term-missing [] + +[testenv:flake8] +basepython = python3 +skip_install = true +deps = flake8 +commands = flake8 js setup.py --doctests + +[pytest] +addopts = --doctest-glob="*.rst" From 2bfa2e787c15a8aae66b32e254cd895bcfbfbcf4 Mon Sep 17 00:00:00 2001 From: Steffen Allner Date: Thu, 28 Jan 2021 15:33:56 +0100 Subject: [PATCH 2/2] Delete empty line. --- js/tableselect/test_tableselect.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/js/tableselect/test_tableselect.rst b/js/tableselect/test_tableselect.rst index 8d562c5..38af70d 100644 --- a/js/tableselect/test_tableselect.rst +++ b/js/tableselect/test_tableselect.rst @@ -8,4 +8,3 @@ want these resources to be included on a page:: >>> tableselect.need() This already includes the respective css files. -