From ae8cd4cf4db1667f44441beed86a27dd8cd1e9ba Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 7 Feb 2023 12:03:18 +0000 Subject: [PATCH 1/4] Add standard pre-commit config --- .pre-commit-config.yaml | 22 +++++++--------------- pyproject.toml | 32 ++++++++------------------------ 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8ac164e1..0dfba3bf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,6 @@ repos: - - repo: https://github.com/pycqa/isort - rev: 5.10.1 - hooks: - - id: isort - types: [text] - types_or: [python, cython] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: check-docstring-first - id: check-executables-have-shebangs @@ -17,20 +11,18 @@ repos: args: [--fix=lf] - id: requirements-txt-fixer - id: trailing-whitespace - # bump2version produces whitespace in setup.cfg, so exclude to - # not inferfere with versioning - exclude: setup.cfg - - repo: https://github.com/pycqa/flake8 - rev: 5.0.4 + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.240 hooks: - - id: flake8 + - id: ruff - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 23.1.0 hooks: - id: black - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.990 + rev: v0.991 hooks: - id: mypy additional_dependencies: - types-setuptools + - types-requests diff --git a/pyproject.toml b/pyproject.toml index 4b7fce80..bc0d4764 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,32 +2,16 @@ requires = ['setuptools', 'wheel', 'cython'] build-backend = 'setuptools.build_meta' +[tool.cibuildwheel] +build = "cp38-* cp39-* cp310-*" + [tool.black] target-version = ['py38', 'py39', 'py310'] skip-string-normalization = false line-length = 79 -exclude = ''' -( - /( - \.eggs - | \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - | examples - )/ -) -''' - -[tool.isort] -profile = "black" -line_length = 79 - -[tool.cibuildwheel] -build = "cp38-* cp39-* cp310-*" +[tool.ruff] +line-length = 79 +exclude = ["__init__.py","build",".eggs"] +select = ["I", "E", "F"] +fix = true From 461a51a06b641e391ce2c2f8748993fd9dd0571b Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 7 Feb 2023 12:09:19 +0000 Subject: [PATCH 2/4] Add known-first-party config --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index bc0d4764..ba67707f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,3 +15,6 @@ line-length = 79 exclude = ["__init__.py","build",".eggs"] select = ["I", "E", "F"] fix = true + +[tool.ruff.isort] +known-first-party = ["cellfinder_core"] From 6b0b0e3af083ca7c3abbfc8a4f28ad8e38a790e0 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 7 Feb 2023 12:09:33 +0000 Subject: [PATCH 3/4] Add automatic pre-commit fixes --- setup.cfg | 6 +++--- src/cellfinder_core/classify/augment.py | 1 - src/cellfinder_core/classify/resnet.py | 2 -- src/cellfinder_core/classify/tools.py | 1 - src/cellfinder_core/detect/filters/setup_filters.py | 1 - src/cellfinder_core/train/train_yml.py | 1 - tests/tests/test_integration/test_detection.py | 1 - 7 files changed, 3 insertions(+), 10 deletions(-) diff --git a/setup.cfg b/setup.cfg index e2e70c16..8f1fed7e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,12 +4,12 @@ commit = True tag = True tag_name = {new_version} parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? -serialize = +serialize = {major}.{minor}.{patch}-{release}{rc} {major}.{minor}.{patch} [options] -package_dir = +package_dir = =src packages = find: @@ -19,7 +19,7 @@ where = src [bumpversion:part:release] optional_value = prod first_value = rc -values = +values = rc prod diff --git a/src/cellfinder_core/classify/augment.py b/src/cellfinder_core/classify/augment.py index 391e930b..8b5f68b5 100644 --- a/src/cellfinder_core/classify/augment.py +++ b/src/cellfinder_core/classify/augment.py @@ -51,7 +51,6 @@ def augment(augmentation_parameters, image, scale_back=True): def rescale_to_isotropic(image, relative_pixel_sizes, interpolation_order): - if not all_elements_equal(relative_pixel_sizes): min_pixel_size = min(relative_pixel_sizes) normalised_pixel_sizes = [] diff --git a/src/cellfinder_core/classify/resnet.py b/src/cellfinder_core/classify/resnet.py index 7b389388..0a1af00d 100644 --- a/src/cellfinder_core/classify/resnet.py +++ b/src/cellfinder_core/classify/resnet.py @@ -171,7 +171,6 @@ def residual_block( bn_epsilon=1e-5, axis=3, ): - """ Residual unit from He et al. (2015) @@ -314,7 +313,6 @@ def get_shortcut( bn_epsilon=1e-5, axis=3, ): - """ Create shortcut. For none-bottleneck residual units, this is just the identity. Otherwise, the input is reshaped to match the output of the diff --git a/src/cellfinder_core/classify/tools.py b/src/cellfinder_core/classify/tools.py index 73fc7c22..bd6e25e8 100644 --- a/src/cellfinder_core/classify/tools.py +++ b/src/cellfinder_core/classify/tools.py @@ -48,7 +48,6 @@ def get_model( def make_lists(tiff_files, train=True): - signal_list = [] background_list = [] if train: diff --git a/src/cellfinder_core/detect/filters/setup_filters.py b/src/cellfinder_core/detect/filters/setup_filters.py index baf1de53..b27137ea 100644 --- a/src/cellfinder_core/detect/filters/setup_filters.py +++ b/src/cellfinder_core/detect/filters/setup_filters.py @@ -42,7 +42,6 @@ def setup( def setup_tile_filtering(plane): - max_value = get_max_value(plane) clipping_value = max_value - 2 thrsh_val = max_value - 1 diff --git a/src/cellfinder_core/train/train_yml.py b/src/cellfinder_core/train/train_yml.py index 2a99bc09..2e8c18af 100644 --- a/src/cellfinder_core/train/train_yml.py +++ b/src/cellfinder_core/train/train_yml.py @@ -313,7 +313,6 @@ def run( save_progress=False, epochs=100, ): - from cellfinder_core.main import suppress_tf_logging suppress_tf_logging(tf_suppress_log_messages) diff --git a/tests/tests/test_integration/test_detection.py b/tests/tests/test_integration/test_detection.py index 1ffee532..98297985 100644 --- a/tests/tests/test_integration/test_detection.py +++ b/tests/tests/test_integration/test_detection.py @@ -32,7 +32,6 @@ def background_array(): # FIXME: This isn't a very good example @pytest.mark.slow def test_detection_full(signal_array, background_array): - cells_test = main( signal_array, background_array, From 8bd39111e9a0914abf66b103b305f576d9ef7728 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 19 Feb 2023 19:18:05 +0000 Subject: [PATCH 4/4] Fix deprecated bool alias --- tests/tests/test_unit/test_tools/test_geometry.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/tests/test_unit/test_tools/test_geometry.py b/tests/tests/test_unit/test_tools/test_geometry.py index 68c4e469..3d196f3a 100644 --- a/tests/tests/test_unit/test_tools/test_geometry.py +++ b/tests/tests/test_unit/test_tools/test_geometry.py @@ -8,7 +8,7 @@ def test_make_sphere(): def test_four_connected_kernel(): - assert ( - (np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]], dtype=np.bool)) - == geometry.four_connected_kernel() - ).all() + np.testing.assert_array_equal( + geometry.four_connected_kernel(), + np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]], dtype=bool), + )