Skip to content

Commit

Permalink
Merge pull request #284 from comic/fix_flake8
Browse files Browse the repository at this point in the history
Add flake8 checks
  • Loading branch information
jmsmkn authored Feb 12, 2020
2 parents 18d4002 + 2a5cab8 commit c76c810
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 145 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ repos:
hooks:
- id: black
language: python
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
language: python
additional_dependencies:
- flake8-bugbear
- flake8-import-order
- pep8-naming
# The following is disabled due to a runtime error
# - flake8-docstrings
- mccabe
- repo: https://github.com/mgedmin/check-manifest
rev: "0.40"
hooks:
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

sys.path.insert(0, os.path.abspath(".."))

import evalutils
import evalutils # noqa: E402

# -- General configuration ---------------------------------------------

Expand Down Expand Up @@ -83,6 +83,7 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# Always document the __init__ method
def skip(app, what, name, obj, skip, options):
if name == "__init__":
Expand Down
2 changes: 1 addition & 1 deletion evalutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .__version__ import __version__ as _version
from .evalutils import (
BaseAlgorithm,
ClassificationEvaluation,
DetectionEvaluation,
Evaluation,
BaseAlgorithm,
)

__author__ = """James Meakin"""
Expand Down
1 change: 0 additions & 1 deletion evalutils/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re

from pathlib import Path

import click
Expand Down
27 changes: 17 additions & 10 deletions evalutils/evalutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,38 @@
from abc import ABC, abstractmethod
from os import PathLike
from pathlib import Path
from typing import Tuple, Dict, Set, Callable, List, Union, Pattern
from typing import Callable, Dict, List, Pattern, Set, Tuple, Union
from warnings import warn

from pandas import DataFrame, merge, Series, concat
from pandas import DataFrame, Series, concat, merge

from .exceptions import FileLoaderError, ValidationError, ConfigurationError
from .io import first_int_in_filename_key, FileLoader, CSVLoader
from .exceptions import ConfigurationError, FileLoaderError, ValidationError
from .io import CSVLoader, FileLoader, first_int_in_filename_key
from .scorers import score_detection
from .validators import DataFrameValidator

logger = logging.getLogger(__name__)


DEFAULT_INPUT_PATH = Path("/input/")
DEFAULT_ALGORITHM_OUTPUT_IMAGES_PATH = Path("/output/images/")
DEFAULT_ALGORITHM_OUTPUT_FILE_PATH = Path("/output/results.json")
DEFAULT_GROUND_TRUTH_PATH = Path("/opt/evaluation/ground-truth/")
DEFAULT_EVALUATION_OUTPUT_FILE_PATH = Path("/output/metrics.json")


class BaseAlgorithm(ABC):
def __init__(
self,
*,
index_key: str,
file_loaders: Dict[str, FileLoader],
file_filters: Dict[str, Pattern[str]] = None,
input_path: Path = Path("/input/"),
output_path: Path = Path("/output/images/"),
input_path: Path = DEFAULT_INPUT_PATH,
output_path: Path = DEFAULT_ALGORITHM_OUTPUT_IMAGES_PATH,
file_sorter_key: Callable = None,
validators: Dict[str, Tuple[DataFrameValidator, ...]],
output_file: PathLike = Path("/output/results.json"),
output_file: PathLike = DEFAULT_ALGORITHM_OUTPUT_FILE_PATH,
):
"""
The base class for all algorithms. Sets the environment and controls
Expand Down Expand Up @@ -159,14 +166,14 @@ class BaseEvaluation(ABC):
def __init__(
self,
*,
ground_truth_path: Path = Path("/opt/evaluation/ground-truth/"),
predictions_path: Path = Path("/input/"),
ground_truth_path: Path = DEFAULT_GROUND_TRUTH_PATH,
predictions_path: Path = DEFAULT_INPUT_PATH,
file_sorter_key: Callable = first_int_in_filename_key,
file_loader: FileLoader,
validators: Tuple[DataFrameValidator, ...],
join_key: str = None,
aggregates: Set[str] = None,
output_file: PathLike = Path("/output/metrics.json"),
output_file: PathLike = DEFAULT_EVALUATION_OUTPUT_FILE_PATH,
):
"""
The base class for all evaluations. Sets the environment and controls
Expand Down
6 changes: 3 additions & 3 deletions evalutils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import re
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Union, Dict, List
from typing import Dict, List, Union

from SimpleITK import ReadImage, GetArrayFromImage
from SimpleITK import GetArrayFromImage, ReadImage
from imageio import imread
from pandas import read_csv
from pandas.errors import ParserError, EmptyDataError
from pandas.errors import EmptyDataError, ParserError

from .exceptions import FileLoaderError

Expand Down
2 changes: 1 addition & 1 deletion evalutils/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scipy.ndimage.morphology import binary_erosion, generate_binary_structure


def distance_transform_edt_float32(
def distance_transform_edt_float32( # noqa: C901
input,
sampling=None,
return_distances=True,
Expand Down
3 changes: 1 addition & 2 deletions evalutils/templates/algorithm/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import shutil
from pathlib import Path

from evalutils.utils import (
bootstrap_development_distribution,
convert_line_endings,
)


ALGORITHM_NAME = "{{ cookiecutter.algorithm_name }}"
IS_DEV_BUILD = int("{{ cookiecutter.dev_build }}") == 1

Expand All @@ -16,7 +16,6 @@
for f in templated_files:
shutil.move(f.name, f.stem)


convert_line_endings()

if IS_DEV_BUILD:
Expand Down
2 changes: 1 addition & 1 deletion evalutils/templates/evaluation/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import shutil
from pathlib import Path

from evalutils.utils import (
bootstrap_development_distribution,
convert_line_endings,
Expand Down Expand Up @@ -45,7 +46,6 @@ def remove_detection_files():
if CHALLENGE_KIND.lower() != "classification":
remove_classification_files()


convert_line_endings()

if IS_DEV_BUILD:
Expand Down
2 changes: 1 addition & 1 deletion evalutils/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
import shutil
from pathlib import Path

EOL_UNIX = b"\n"
EOL_WIN = b"\r\n"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ collect_ignore = ['setup.py']

[flake8]
application-import-names =
gcapi
evalutils
tests
import-order-style = pycharm
docstring-convention = numpy
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os

from setuptools import setup, find_packages
from setuptools import find_packages, setup

NAME = "evalutils"
REQUIRES_PYTHON = ">=3.6.0"
Expand Down Expand Up @@ -46,7 +46,10 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
description="evalutils helps challenge administrators easily create evaluation containers for grand-challenge.org.",
description=(
"evalutils helps challenge administrators easily create evaluation "
"containers for grand-challenge.org."
),
extras_require={"test": test_requirements},
install_requires=requirements,
license="MIT license",
Expand Down
12 changes: 7 additions & 5 deletions tests/test_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import json
import os
import re
import shutil
from pathlib import Path

import SimpleITK
import shutil
import numpy as np
from pandas import DataFrame
import re
import os
import json

from evalutils import BaseAlgorithm
from evalutils.io import SimpleITKLoader
from evalutils.validators import (
UniquePathIndicesValidator,
UniqueImagesValidator,
UniquePathIndicesValidator,
)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

from evalutils.exceptions import FileLoaderError
from evalutils.io import (
get_first_int_in,
ImageIOLoader,
CSVLoader,
ImageIOLoader,
SimpleITKLoader,
first_int_in_filename_key,
get_first_int_in,
)


Expand Down
Loading

0 comments on commit c76c810

Please sign in to comment.