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 e68fb9f commit 2ea9df3
Show file tree
Hide file tree
Showing 11 changed files with 57 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
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}


Expand Down
6 changes: 3 additions & 3 deletions reana_client/cli/cwl_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ 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

json_output = json.dumps(ast.literal_eval(str(out)))
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)
Expand All @@ -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())


Expand Down
4 changes: 2 additions & 2 deletions reana_client/cli/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ", ".")))
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion reana_client/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
10 changes: 4 additions & 6 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ check_black () {
black --check .
}

check_flake8 () {
flake8 .
}

check_pydocstyle () {
pydocstyle reana_client
}
Expand Down Expand Up @@ -55,6 +59,7 @@ check_pytest () {
check_all() {
check_script
check_black
check_flake8
check_pydocstyle
check_manifest
check_cli_cmds
Expand All @@ -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;;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<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_cli_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2ea9df3

Please sign in to comment.