diff --git a/.gitignore b/.gitignore index 06d32f13..f977b96d 100644 --- a/.gitignore +++ b/.gitignore @@ -148,3 +148,6 @@ fabric.properties # Repo specific items tests/gin_test_config.json .pre-commit-config.yaml + +# Aider coding assistant +.aider* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 345fe75b..e3d93ccd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,7 @@ repos: args: - --convention=numpy - --add-ignore=D1 +- repo: https://github.com/numpy/numpydoc + rev: 881c0abf0a75c1b517c23a819f9365fbfc9cded7 + hooks: + - id: numpydoc-validation diff --git a/pyproject.toml b/pyproject.toml index b9b26627..70e36a83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,3 +19,21 @@ extend-exclude = ''' | dist )/ ''' + +[tool.numpydoc_validation] +checks = [ + "all", # report on all checks, except the below + "GL08", # Missing docstring + "EX01", # Missing Example section + "SA01", # Missing See Also section + "ES01", # Missing Extended Summary section + "GL01", # Missing newline at beginning of docstring + "RT02", # Return should only specify type NOT name +] +exclude = [ # don't report on objects that match any of these regex + 'test_', + 'check_', + 'assert_', +] +override_SS05 = [ # override SS05 to allow docstrings starting with these words +] diff --git a/src/roiextractors/testing.py b/src/roiextractors/testing.py index d1720898..cd603440 100644 --- a/src/roiextractors/testing.py +++ b/src/roiextractors/testing.py @@ -191,7 +191,10 @@ def generate_dummy_segmentation_extractor( def _assert_iterable_shape(iterable, shape): - """Assert that the iterable has the given shape. If the iterable is a numpy array, the shape is checked directly.""" + """Assert that the iterable has the given shape. + + If the iterable is a numpy array, the shape is checked directly. + """ ar = iterable if isinstance(iterable, np.ndarray) else np.array(iterable) for ar_shape, given_shape in zip(ar.shape, shape): if isinstance(given_shape, int): @@ -199,7 +202,8 @@ def _assert_iterable_shape(iterable, shape): def _assert_iterable_shape_max(iterable, shape_max): - """Assert that the iterable has a shape less than or equal to the given maximum shape.""" + """Assert that the iterable has a shape less than or equal to the given + maximum shape.""" ar = iterable if isinstance(iterable, np.ndarray) else np.array(iterable) for ar_shape, given_shape in zip(ar.shape, shape_max): if isinstance(given_shape, int): @@ -216,7 +220,8 @@ def _assert_iterable_element_dtypes(iterable, dtypes): def _assert_iterable_complete(iterable, dtypes=None, element_dtypes=None, shape=None, shape_max=None): - """Assert that the iterable is complete, i.e. it is not None and has the given dtypes, element_dtypes, shape and shape_max.""" + """Assert that the iterable is complete, i.e. it is not None and has the + given dtypes, element_dtypes, shape and shape_max.""" assert isinstance(iterable, dtypes), f"iterable {type(iterable)} is none of the types {dtypes}" if not isinstance(iterable, NoneType): if shape is not None: @@ -270,7 +275,8 @@ def check_segmentations_images( segmentation_extractor1: SegmentationExtractor, segmentation_extractor2: SegmentationExtractor, ): - """Check that the segmentation images are equal for the given segmentation extractors.""" + """Check that the segmentation images are equal for the given segmentation + extractors.""" images_in_extractor1 = segmentation_extractor1.get_images_dict() images_in_extractor2 = segmentation_extractor2.get_images_dict() @@ -287,7 +293,8 @@ def check_segmentations_images( def check_segmentation_return_types(seg: SegmentationExtractor): - """Check that the return types of the segmentation extractor are correct.""" + """Check that the return types of the segmentation extractor are + correct.""" assert isinstance(seg.get_num_rois(), int) assert isinstance(seg.get_num_frames(), int) assert isinstance(seg.get_num_channels(), int) @@ -378,9 +385,11 @@ def check_imaging_equal( def assert_get_frames_return_shape(imaging_extractor: ImagingExtractor): - """Check whether an ImagingExtractor get_frames function behaves as expected. + """Check whether an ImagingExtractor get_frames function behaves as + expected. - We aim for the function to behave as numpy slicing and indexing as much as possible. + We aim for the function to behave as numpy slicing and indexing as + much as possible. """ image_size = imaging_extractor.get_image_size()