diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..5b9686af --- /dev/null +++ b/.flake8 @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85fcdc88..3922e2c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,23 @@ jobs: - name: Check Python code formatting run: ./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: diff --git a/MANIFEST.in b/MANIFEST.in index 90aef00f..93e85a0f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -12,6 +12,7 @@ include *.sh include *.txt include *.yaml include *.yml +include .flake8 include pytest.ini include docs/requirements.txt include docs/cmd_list.txt diff --git a/reana_client/api/client.py b/reana_client/api/client.py index 830512bf..49c56272 100644 --- a/reana_client/api/client.py +++ b/reana_client/api/client.py @@ -58,7 +58,7 @@ def ping(access_token): if e.response.status_code == 403: return {"status": "ERROR: INVALID ACCESS TOKEN", "error": True} raise Exception(e.response) - except Exception as e: + except Exception: return {"status": "ERROR: INVALID SERVER", "error": True} diff --git a/reana_client/cli/cwl_runner.py b/reana_client/cli/cwl_runner.py index 25dc1339..999211a9 100644 --- a/reana_client/cli/cwl_runner.py +++ b/reana_client/cli/cwl_runner.py @@ -157,7 +157,7 @@ def cwl_runner(ctx, quiet, outdir, basedir, processfile, jobfile, access_token): # click.echo(response['status']) break try: - out = re.search("success{[\S\s]*", logs).group().replace("success", "") + out = re.search(r"success{[\S\s]*", logs).group().replace("success", "") import ast import json @@ -165,7 +165,7 @@ def cwl_runner(ctx, quiet, outdir, basedir, processfile, jobfile, access_token): except AttributeError: logging.error("Workflow execution failed") sys.exit(1) - except Exception as e: + except Exception: logging.error(traceback.format_exc()) sys.exit(1) sys.stdout.write(json_output) @@ -175,7 +175,7 @@ def cwl_runner(ctx, quiet, outdir, basedir, processfile, jobfile, access_token): except HTTPServerError as e: logging.error(traceback.print_exc()) logging.error(e) - except Exception as e: + except Exception: logging.error(traceback.print_exc()) diff --git a/reana_client/cli/files.py b/reana_client/cli/files.py index 2eb91bb0..61b929b5 100644 --- a/reana_client/cli/files.py +++ b/reana_client/cli/files.py @@ -352,7 +352,7 @@ def delete_files(ctx, workflow, filenames, access_token): # noqa: D301 Examples:\n \t $ reana-client rm -w myanalysis.42 data/mydata.csv \n \t $ reana-client rm -w myanalysis.42 'code/\*' - """ + """ # noqa: W605 from reana_client.api.client import delete_file logging.debug("command: {}".format(ctx.command_path.replace(" ", "."))) @@ -450,7 +450,7 @@ def move_files(ctx, source, target, workflow, access_token): # noqa: D301 err=True, ) sys.exit(1) - response = mv_files(source, target, workflow, access_token) + mv_files(source, target, workflow, access_token) click.echo( click.style( "{} was successfully moved to {}.".format(source, target), diff --git a/reana_client/cli/utils.py b/reana_client/cli/utils.py index 71e4b3e3..a77d5af3 100644 --- a/reana_client/cli/utils.py +++ b/reana_client/cli/utils.py @@ -177,7 +177,7 @@ def key_value_to_dict(ctx, param, value): """ try: return dict(op.split("=") for op in value) - except ValueError as err: + except ValueError: click.secho( '==> ERROR: Input parameter "{0}" is not valid. ' 'It must follow format "param=value".'.format(" ".join(value)), diff --git a/reana_client/cli/workflow.py b/reana_client/cli/workflow.py index 44ecd4a8..45c3f4d3 100644 --- a/reana_client/cli/workflow.py +++ b/reana_client/cli/workflow.py @@ -111,7 +111,7 @@ def workflow_execution_group(ctx): @add_pagination_options @check_connection @click.pass_context -def workflow_workflows( +def workflow_workflows( # noqa: C901 ctx, sessions, _filter, @@ -587,7 +587,7 @@ def workflow_restart( @check_connection @click.option("-v", "--verbose", count=True, help="Set status information verbosity.") @click.pass_context -def workflow_status( +def workflow_status( # noqa: C901 ctx, workflow, _filter, output_format, access_token, verbose ): # noqa: D301 """Get status of a workflow. @@ -945,7 +945,7 @@ def workflow_stop(ctx, workflow, force_stop, access_token): # noqa: D301 if workflow: try: logging.info("Sending a request to stop workflow {}".format(workflow)) - response = stop_workflow(workflow, force_stop, access_token) + stop_workflow(workflow, force_stop, access_token) click.secho(get_workflow_status_change_msg(workflow, "stopped"), fg="green") except Exception as e: logging.debug(traceback.format_exc()) @@ -1097,9 +1097,7 @@ def workflow_delete( if workflow: try: logging.info("Connecting to {0}".format(get_api_url())) - response = delete_workflow( - workflow, all_runs, hard_delete, workspace, access_token - ) + delete_workflow(workflow, all_runs, hard_delete, workspace, access_token) if all_runs: message = "All workflows named '{}' have been deleted.".format( workflow.split(".")[0] diff --git a/run-tests.sh b/run-tests.sh index de731b73..f69bd458 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -21,6 +21,10 @@ check_black () { black --check . } +check_flake8 () { + flake8 . +} + check_pydocstyle () { pydocstyle reana_client } @@ -55,6 +59,7 @@ check_pytest () { check_all() { check_script check_black + check_flake8 check_pydocstyle check_manifest check_cli_cmds @@ -73,6 +78,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-cli-cmds) check_cli_cmds;; diff --git a/setup.py b/setup.py index 0ea2a8d5..564a414f 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ # Get the version string. Cannot be done with import! with open(os.path.join("reana_client", "version.py"), "rt") as f: - version = re.search('__version__\s*=\s*"(?P.*)"\n', f.read()).group( + version = re.search(r'__version__\s*=\s*"(?P.*)"\n', f.read()).group( "version" ) diff --git a/tests/test_cli_workflows.py b/tests/test_cli_workflows.py index 3568e763..5d0cc037 100644 --- a/tests/test_cli_workflows.py +++ b/tests/test_cli_workflows.py @@ -487,7 +487,7 @@ def test_run( with runner.isolated_filesystem(): with open(reana_workflow_schema, "w") as f: f.write(create_yaml_workflow_schema) - result = runner.invoke( + runner.invoke( cli, ["run", "-t", reana_token, "-f", reana_workflow_schema], ) assert workflow_create_mock.called is True