diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..089b811 --- /dev/null +++ b/.flake8 @@ -0,0 +1,19 @@ +[flake8] +max-line-length = 89 + +exclude = + build + dist + docs + coverage.xml + cernopendata_client.egg-info + .*/ + env/ + .git + __pycache__ + +ignore = E203, E231, E266, E501, W503, F403, F401, W605 + +max-complexity = 18 + +select = B,C,E,F,W,T4,B9 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e9e1d37 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,137 @@ +name: CI + +on: + push: + branches: master + pull_request: + branches: master + +jobs: + Lint-black: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Check Python code formatting + run: | + pip install black + ./run-tests.sh --check-black + + Lint-pydocstyle: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Check compliance with Python docstring conventions + run: | + pip install pydocstyle + ./run-tests.sh --check-pydocstyle + + Lint-flake8: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Check compliance with pep8, pyflakes and circular complexity + run: | + pip install flake8 + ./run-tests.sh --check-flake8 + + Lint-check-manifest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Check Python manifest completeness + run: | + pip install check-manifest + ./run-tests.sh --check-manifest + + Docs-sphinx: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install system dependencies + run: | + sudo apt-get update -y + sudo apt install libcurl4-openssl-dev libssl-dev + sudo apt-get install libgnutls28-dev + + - name: Install Python dependencies + run: | + pip install --upgrade pip setuptools py + pip install -e .[all] + + - name: Run Sphinx documentation with doctests + run: ./run-tests.sh --check-sphinx + + Python-tests: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [2.7, 3.6, 3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install system dependencies + run: | + sudo apt-get update -y + sudo apt install libcurl4-openssl-dev libssl-dev + sudo apt-get install libgnutls28-dev + + - name: Install Python dependencies + run: | + pip install --upgrade pip setuptools py + pip install -e .[all] + + - name: Run pytest + run: ./run-tests.sh --pytest + + - name: Codecov Coverage + if: matrix.python-version == 3.8 + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage.xml + + Docker-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Build and Run + run: | + docker build -t cernopendata/cernopendata-client . + docker run --rm cernopendata/cernopendata-client version diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 34315b3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,45 +0,0 @@ -# This file is part of cernopendata-client. -# -# Copyright (C) 2019 CERN. -# -# cernopendata-client is free software; you can redistribute it and/or modify -# it under the terms of the GPLv3 license; see LICENSE file for more details. - -notifications: - email: false - -sudo: true - -services: - - docker - -language: python - -cache: - - pip - -matrix: - fast_finish: true - include: - - python: 2.7 - - python: 3.6 - - python: 3.7 - dist: xenial - - python: 3.8 - -before_install: - - travis_retry sudo apt-get update -y - - travis_retry sudo apt-get install libgnutls28-dev - - travis_retry pip install --upgrade pip setuptools py - - travis_retry pip install twine wheel coveralls - -install: - - travis_retry pip install -e .[all] - -script: - - ./run-tests.sh - - docker build -t cernopendata/cernopendata-client . - - docker run --rm cernopendata/cernopendata-client version - -after_success: - - coveralls diff --git a/MANIFEST.in b/MANIFEST.in index c79fa82..e3d677e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,7 @@ include *.rst include *.sh +include *.yml +include .flake8 include Dockerfile include LICENSE include docs/requirements.txt diff --git a/cernopendata_client/utils.py b/cernopendata_client/utils.py index 0ee19c7..9b2b091 100644 --- a/cernopendata_client/utils.py +++ b/cernopendata_client/utils.py @@ -23,5 +23,5 @@ def parse_parameters(filter_input): try: filters = " ".join(filter_input).split(",") return filters - except: + except Exception: raise click.BadParameter("Wrong input format \n") diff --git a/cernopendata_client/validator.py b/cernopendata_client/validator.py index 8dfb258..c028db6 100644 --- a/cernopendata_client/validator.py +++ b/cernopendata_client/validator.py @@ -63,7 +63,7 @@ def validate_range(range=None, count=None): param_hint=["--filter-range"], ) range_from, range_to = int(range.split("-")[0]), int(range.split("-")[-1]) - except: + except Exception: raise click.BadParameter( "Range should have start and end index(i-j)", param_hint=["--filter-range"], diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..ef4e732 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,20 @@ +codecov: + require_ci_to_pass: yes + +coverage: + precision: 2 + round: down + range: "80...100" + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no + +comment: + layout: "reach,diff,flags,tree" + behavior: default + require_changes: no diff --git a/pytest.ini b/pytest.ini index a9518ff..7384374 100644 --- a/pytest.ini +++ b/pytest.ini @@ -8,4 +8,4 @@ # it under the terms of the GPLv3 license; see LICENSE file for more details. [pytest] -addopts = --ignore=docs --cov=cernopendata_client --cov-report=term-missing +addopts = --ignore=docs --cov=cernopendata_client --cov-report xml diff --git a/run-tests.sh b/run-tests.sh index f2c6abd..f0646cf 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -13,22 +13,37 @@ set -o errexit # Quit on unbound symbols set -o nounset -# Check compliance with Python docstring conventions -pydocstyle cernopendata_client - -# Check Python code formatting -if which black; then - black --check . -fi - -# Check Python manifest completeness -check-manifest --ignore ".travis-*" - -# Check Sphinx documentation -sphinx-build -qnNW docs docs/_build/html - -# Run test suite -python setup.py test - -# Check Sphinx documentation with doctests -sphinx-build -qnNW -b doctest docs docs/_build/doctest +for arg in "$@" +do + case $arg in + --check-black) # Check Python code formatting + black --check . + ;; + --check-pydocstyle) # Check compliance with Python docstring conventions + pydocstyle cernopendata_client + ;; + --check-flake8) # Check compliance with pep8, pyflakes and circular complexity + flake8 . + ;; + --check-manifest) # Check Python manifest completeness + check-manifest + ;; + --check-sphinx) # Check Sphinx documentation with doctests + sphinx-build -qnNW docs docs/_build/html + sphinx-build -qnNW -b doctest docs docs/_build/doctest + ;; + --pytest) # Run test suite + python setup.py test + ;; + --all) # Run all tests locally + black --check . + pydocstyle cernopendata_client + flake8 . + check-manifest + sphinx-build -qnNW docs docs/_build/html + sphinx-build -qnNW -b doctest docs docs/_build/doctest + python setup.py test + ;; + *) + esac +done