
.flake8_template:
  stage: build
  before_script: ${PYTHON_VERSION} -m pip -q install flake8
  script: ${PYTHON_VERSION} -m flake8 --max-line-length 120 --statistics --show-source .


.flake8_extended_template:
  stage: .post
  before_script:
    - ${PYTHON_VERSION} -m pip install flake8 flake8-isort flake8-builtins
    # The following flake8 extensions only work on python3
    - ${PYTHON_VERSION} -m pip install flake8-eradicate flake8-functions-names flake8-return flake8-functions || true
  script: ${PYTHON_VERSION} -m flake8 --max-line-length 120 --statistics --show-source .
  allow_failure: true

.security_template:
  stage: .post
  before_script:
    - ${PYTHON_VERSION} -m pip install bandit safety
  script:
    - bandit -r . || RET=1
    - safety check || RET=1
    - exit $RET
  allow_failure: true

.py3_template:
  image: python:3-alpine
  variables:
    PYTHON_VERSION: python3

.py2_template:
  image: python:2-alpine
  variables:
    PYTHON_VERSION: python2

.py3-flake8:
  extends:
    - .flake8_template
    - .py3_template

.py2-flake8:
  extends:
    - .flake8_template
    - .py2_template

.py3-flake8_extended:
  extends:
    - .flake8_extended_template
    - .py3_template

.py2-flake8_extended:
  extends:
    - .flake8_extended_template
    - .py2_template

.py3-security:
  extends:
    - .security_template
    - .py3_template
