Skip to content

Commit

Permalink
ci: added flake8 linter
Browse files Browse the repository at this point in the history
  • Loading branch information
audrium committed Nov 19, 2020
1 parent cbfc143 commit a48dcd8
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 12 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
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ 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-20.04
steps:
Expand Down Expand Up @@ -94,7 +111,7 @@ jobs:
run: ./run-tests.sh --check-sphinx

python-tests:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [2.7, 3.6, 3.7, 3.8]
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include *.rst
include *.sh
include *.yaml
include *.yml
include .flake8
include pytest.ini
prune docs/_build
recursive-include reana_commons *.py
Expand Down
5 changes: 3 additions & 2 deletions reana_commons/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def __init__(self, missing_secrets_list=None):

def __str__(self):
"""Represent REANA secret does not exist exception as a string."""
return "Operation cancelled. Secrets {} "
"do not exist.".format(self.missing_secrets_list)
return "Operation cancelled. Secrets {} do not exist.".format(
self.missing_secrets_list
)


class REANASecretAlreadyExists(Exception):
Expand Down
6 changes: 3 additions & 3 deletions reana_commons/k8s/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _initialise_user_secrets_store(self):
REANA_RUNTIME_KUBERNETES_NAMESPACE, empty_k8s_secret
)
return empty_k8s_secret
except ApiException as api_e:
except ApiException:
log.error(
"Something went wrong while creating "
"Kubernetes secret for user {0}.".format(
Expand Down Expand Up @@ -113,12 +113,12 @@ def _load_json_annotation_from_k8s_object(self, k8s_object, annotation_key):
"""Load string annotations from Kubernetes object."""
try:
return json.loads(k8s_object.metadata.annotations[annotation_key])
except ValueError as e:
except ValueError:
log.error(
"Annotations for user {} secret store could not be"
"loaded as json.".format(annotation_key)
)
except KeyError as e:
except KeyError:
log.error(
"Annotation key {annotation_key} does not exist for"
" user {user} secret store, so it can not be loaded".format(
Expand Down
2 changes: 1 addition & 1 deletion reana_commons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def check_htcondor_max_runtime(specification):
htcondor_max_runtime = step["htcondor_max_runtime"]
if (
not str.isdigit(htcondor_max_runtime)
and not htcondor_max_runtime in HTCONDOR_JOB_FLAVOURS
and htcondor_max_runtime not in HTCONDOR_JOB_FLAVOURS
):
check_pass = False
click.secho(
Expand Down
6 changes: 6 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ check_black () {
black --check .
}

check_flake8 () {
flake8 .
}

check_pydocstyle () {
pydocstyle reana_commons
}
Expand All @@ -39,6 +43,7 @@ check_pytest () {
check_all () {
check_script
check_black
check_flake8
check_pydocstyle
check_manifest
check_sphinx
Expand All @@ -55,6 +60,7 @@ do
case $arg in
--check-shellscript) check_script;;
--check-black) check_black;;
--check-flake8) check_flake8;;
--check-pydocstyle) check_pydocstyle;;
--check-manifest) check_manifest;;
--check-sphinx) check_sphinx;;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

# Get the version string. Cannot be done with import!
with open(os.path.join("reana_commons", "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
4 changes: 2 additions & 2 deletions tests/test_secrets_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_create_existing_secrets_fail(
) as api_client:
secrets_store = REANAUserSecretsStore(no_db_user)
with pytest.raises(REANASecretAlreadyExists):
secrets_list = secrets_store.add_secrets(user_secrets)
secrets_store.add_secrets(user_secrets)
api_client.replace_namespaced_secret.assert_not_called()


Expand All @@ -55,7 +55,7 @@ def test_overwrite_secret(
corev1_api_client_with_user_secrets(user_secrets),
) as api_client:
secrets_store = REANAUserSecretsStore(no_db_user.id_)
secrets_list = secrets_store.add_secrets(user_secrets, overwrite=True)
secrets_store.add_secrets(user_secrets, overwrite=True)
api_client.replace_namespaced_secret.assert_called()


Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_click_table_printer_filter_wrong_header(capsys):
assert out == "\n\n\n"


def test_calculate_hash_of_dir(sample_workflow_workspace):
def test_calculate_hash_of_dir(sample_workflow_workspace): # noqa: F811
"""Test calculate_hash_of_dir."""
non_existing_dir_hash = calculate_hash_of_dir("a/b/c")
assert non_existing_dir_hash == -1
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_calculate_job_input_hash():
) == calculate_job_input_hash(job_spec_2, workflow_json)


def test_calculate_file_access_time(sample_workflow_workspace):
def test_calculate_file_access_time(sample_workflow_workspace): # noqa: F811
"""Test calculate_file_access_time."""
sample_workflow_workspace_path = next(sample_workflow_workspace("sample"))
access_times = calculate_file_access_time(sample_workflow_workspace_path)
Expand Down

0 comments on commit a48dcd8

Please sign in to comment.