Skip to content

Commit

Permalink
ci: add hadolint and flake8 linters
Browse files Browse the repository at this point in the history
  • Loading branch information
audrium committed Nov 18, 2020
1 parent d4d2b5e commit 55c80cb
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 13 deletions.
20 changes: 20 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[flake8]
max-line-length = 89

exclude =
build
modules
dist
docs
coverage.xml
reana_job_controller.egg-info
.*/
env/
.git
__pycache__

ignore = E203, E231, E266, E501, W503, F403, F401

max-complexity = 18

select = B,C,E,F,W,T4,B9
42 changes: 34 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on: [push, pull_request]

jobs:
lint-shellcheck:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -21,7 +21,7 @@ jobs:
./run-tests.sh --check-shellscript
lint-black:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -37,8 +37,25 @@ jobs:
pip install black==19.10b0
./run-tests.sh --check-black
lint-flake8:
runs-on: ubuntu-20.04
steps:
- name: Checkout
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 --upgrade pip
pip install flake8
./run-tests.sh --check-flake8
lint-pydocstyle:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -55,7 +72,7 @@ jobs:
./run-tests.sh --check-pydocstyle
lint-check-manifest:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -72,7 +89,7 @@ jobs:
./run-tests.sh --check-manifest
docs-sphinx:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -96,7 +113,7 @@ jobs:
run: ./run-tests.sh --check-sphinx

python-tests:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
Expand Down Expand Up @@ -131,11 +148,20 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml

lint-dockerfile:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Check Dockerfile compliance
run: ./run-tests.sh --check-dockerfile

docker-build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build docker image
- name: Build Docker image
run: ./run-tests.sh --check-docker-build
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Install base image and its dependencies
FROM python:3.8-slim
# hadolint ignore=DL3008, DL3013, DL3015
RUN apt-get update && \
apt-get install -y \
autoconf \
Expand All @@ -21,6 +22,8 @@ RUN apt-get update && \
python-pip \
unzip \
vim-tiny && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
pip install --upgrade pip

# Install dependencies
Expand All @@ -36,6 +39,7 @@ ARG DEBUG=0
RUN if [ "${DEBUG}" -gt 0 ]; then pip install -e ".[debug]"; else pip install .; fi;

# Are we building with locally-checked-out shared modules?
# hadolint ignore=SC2102
RUN if test -e modules/reana-commons; then pip install -e modules/reana-commons[kubernetes] --upgrade; fi

# Check if there are broken requirements
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ include *.rst
include *.sh
include *.in
include *.txt
include .flake8
include pytest.ini
recursive-include docs *.py
recursive-include docs *.png
Expand Down
2 changes: 1 addition & 1 deletion reana_workflow_engine_yadage/externalbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self):

self._fail_info = None

def submit(self, spec, parameters, state, metadata):
def submit(self, spec, parameters, state, metadata): # noqa: C901
"""Submit a yadage packtivity to RJC."""
parameters, state = finalize_inputs(parameters, state)
job = build_job(spec["process"], parameters, state, self.config)
Expand Down
4 changes: 1 addition & 3 deletions reana_workflow_engine_yadage/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

def analyze_progress(adageobj):
"""Analyze the workflow progress."""
dag, rules, applied = adageobj.dag, adageobj.rules, adageobj.applied_rules
successful, failed, running, unsubmittable = 0, 0, 0, 0

dag = adageobj.dag
nodestates = []
for node in nx.topological_sort(dag):
nodeobj = dag.getNode(node)
Expand Down
12 changes: 12 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ check_black () {
black --check .
}

check_flake8 () {
flake8 .
}

check_manifest () {
check-manifest
}
Expand All @@ -36,6 +40,10 @@ check_pytest () {
python setup.py test
}

check_dockerfile () {
docker run -i --rm hadolint/hadolint < Dockerfile
}

check_docker_build () {
docker build -t reanahub/reana-workflow-engine-yadage .
}
Expand All @@ -44,9 +52,11 @@ check_all () {
check_script
check_pydocstyle
check_black
check_flake8
check_manifest
check_sphinx
check_pytest
check_dockerfile
check_docker_build
}

Expand All @@ -61,9 +71,11 @@ do
--check-shellscript) check_script;;
--check-pydocstyle) check_pydocstyle;;
--check-black) check_black;;
--check-flake8) check_flake8;;
--check-manifest) check_manifest;;
--check-sphinx) check_sphinx;;
--check-pytest) check_pytest;;
--check-dockerfile) check_dockerfile;;
--check-docker-build) check_docker_build;;
*)
esac
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

# Get the version string. Cannot be done with import!
with open(os.path.join("reana_workflow_engine_yadage", "version.py"), "rt") as f:
version = re.search('__version__\s*=\s*"(?P<version>.*)"\n', f.read()).group(
version = re.search(r'__version__\s*=\s*"(?P<version>.*)"\n', f.read()).group(
"version"
)

Expand Down

0 comments on commit 55c80cb

Please sign in to comment.