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 0b8c40a commit b78d62d
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 15 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
41 changes: 33 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 @@ -97,7 +114,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 @@ -130,12 +147,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: 3 additions & 1 deletion 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, DL3009, DL3013, DL3015
RUN apt-get update && \
apt-get install -y \
gcc \
Expand All @@ -27,6 +28,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
RUN if test -e modules/reana-db; then pip install -e modules/reana-db --upgrade; fi

Expand All @@ -41,4 +43,4 @@ ENV TERM=xterm \
EXPOSE 5000

# Run server
CMD uwsgi --ini uwsgi.ini
CMD ["uwsgi --ini uwsgi.ini"]
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include LICENSE
include *.rst
include *.sh
include *.txt
include .flake8
include pytest.ini
include docs/*.json
include scripts/*
Expand Down
2 changes: 1 addition & 1 deletion reana_server/reana_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def token_grant(admin_access_token, id_, email):
)
send_email(user.email, email_subject, email_body)

except click.exceptions.Abort as e:
except click.exceptions.Abort:
click.echo("Grant token aborted.")
except REANAEmailNotificationError as e:
click.secho(
Expand Down
4 changes: 2 additions & 2 deletions reana_server/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_workflows(**kwargs): # noqa
except HTTPError as e:
logging.error(traceback.format_exc())
return jsonify(e.response.json()), e.response.status_code
except json.JSONDecodeError as e:
except json.JSONDecodeError:
logging.error(traceback.format_exc())
return jsonify({"message": "Your request contains not valid JSON."}), 400
except ValueError as e:
Expand Down Expand Up @@ -1733,7 +1733,7 @@ def get_workflow_diff(workflow_id_or_name_a, workflow_id_or_name_b): # noqa
except HTTPError as e:
logging.error(traceback.format_exc())
return jsonify(e.response.json()), e.response.status_code
except json.JSONDecodeError as e:
except json.JSONDecodeError:
logging.error(traceback.format_exc())
return jsonify({"message": "Your request contains not valid JSON."}), 400
except ValueError as e:
Expand Down
2 changes: 1 addition & 1 deletion reana_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _create_user(email, user_access_token, admin_access_token):
user = User(**user_parameters)
Session.add(user)
Session.commit()
except (InvalidRequestError, IntegrityError) as e:
except (InvalidRequestError, IntegrityError):
Session.rollback()
raise ValueError("Could not create user, " "possible constraint violation")
return user
Expand Down
12 changes: 12 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ check_black () {
black --check .
}

check_flake8 () {
flake8 .
}

check_openapi_spec () {
FLASK_APP=reana_server/app.py python ./scripts/generate_openapi_spec.py
diff -q -w temp_openapi.json docs/openapi.json
Expand All @@ -85,6 +89,10 @@ check_pytest () {
stop_db_container
}

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

check_docker_build () {
docker build -t reanahub/reana-server .
}
Expand All @@ -93,10 +101,12 @@ check_all () {
check_script
check_pydocstyle
check_black
check_flake8
check_openapi_spec
check_manifest
check_sphinx
check_pytest
check_dockerfile
check_docker_build
}

Expand All @@ -111,10 +121,12 @@ do
--check-shellscript) check_script;;
--check-pydocstyle) check_pydocstyle;;
--check-black) check_black;;
--check-flake8) check_flake8;;
--check-openapi-spec) check_openapi_spec;;
--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 @@ -86,7 +86,7 @@

# Get the version string. Cannot be done with import!
with open(os.path.join("reana_server", "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
2 changes: 1 addition & 1 deletion tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

def test_create_app():
"""Test create_app() method."""
app = create_app()
create_app()

0 comments on commit b78d62d

Please sign in to comment.