From f023fb7979ec11a0c954f9778c474393e251efff Mon Sep 17 00:00:00 2001 From: Tristan Kuehn Date: Tue, 10 Jan 2023 11:48:53 -0500 Subject: [PATCH 1/2] Update quality workflow to check instead of modify --- .github/workflows/quality.yml | 8 ++++---- labelmerge/workflow/rules/label_harmonization.smk | 8 ++++++-- labelmerge/workflow/scripts/labelmerge.py | 7 +++++-- pyproject.toml | 13 ++++++++++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index e7b27c2..ac472f9 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -51,16 +51,16 @@ jobs: run: poetry install --no-interaction --no-root --with dev - name: yamlfix - run: poetry run poe yamlfix + run: poetry run poe yamlfix-check - name: isort - run: poetry run poe isort + run: poetry run poe isort-check - name: black - run: poetry run poe black + run: poetry run poe black-check - name: flake8 run: poetry run poe flake8 - name: snakefmt - run: poetry run poe snakefmt + run: poetry run poe snakefmt-check diff --git a/labelmerge/workflow/rules/label_harmonization.smk b/labelmerge/workflow/rules/label_harmonization.smk index 063f817..5564f6f 100644 --- a/labelmerge/workflow/rules/label_harmonization.smk +++ b/labelmerge/workflow/rules/label_harmonization.smk @@ -77,8 +77,12 @@ rule merge_labels: **base_inputs["labelmap"].input_wildcards, ), params: - base_exceptions=f"--base_exceptions {' '.join(config['base_exceptions'])}" if config.get("base_exceptions") else "", - overlay_exceptions=f"--overlay_exceptions {' '.join(config['overlay_exceptions'])}" if config.get("overlay_exceptions") else "", + base_exceptions=f"--base_exceptions {' '.join(config['base_exceptions'])}" + if config.get("base_exceptions") + else "", + overlay_exceptions=f"--overlay_exceptions {' '.join(config['overlay_exceptions'])}" + if config.get("overlay_exceptions") + else "", resources: script=str(Path(workflow.basedir) / "scripts" / "labelmerge.py"), shell: diff --git a/labelmerge/workflow/scripts/labelmerge.py b/labelmerge/workflow/scripts/labelmerge.py index dd3543e..45faabe 100644 --- a/labelmerge/workflow/scripts/labelmerge.py +++ b/labelmerge/workflow/scripts/labelmerge.py @@ -1,14 +1,15 @@ #!/usr/bin/env python from __future__ import annotations + from argparse import ArgumentParser from os import PathLike from pathlib import Path import nibabel as nib import numpy as np -from numpy.typing import ArrayLike import pandas as pd import xarray as xr +from numpy.typing import ArrayLike def load_atlas(atlas_path: PathLike): @@ -145,7 +146,9 @@ def main(): overlay_data, _, _ = load_atlas(Path(args.overlay_map)) overlay_metadata = pd.read_csv(args.overlay_metadata, sep="\t") base_exceptions = args.base_exceptions if args.base_exceptions else [] - overlay_exceptions = args.overlay_exceptions if args.overlay_exceptions else [] + overlay_exceptions = ( + args.overlay_exceptions if args.overlay_exceptions else [] + ) base_datasets = split_labels( base_data, base_metadata, diff --git a/pyproject.toml b/pyproject.toml index fb01673..b02f536 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,11 +40,22 @@ build-backend = "poetry.core.masonry.api" [tool.poe.tasks] setup = "pre-commit install" yamlfix = { shell = "find . -type f \\( -iname \\*.yaml -o -iname \\*.yml ! -iname snakemake* ! -iname snakebids* \\) -exec yamlfix {} \\;" } -isort = "isort labelmerge/*.py" +yamlfix-check = { shell = "find . -type f \\( -iname \\*.yaml -o -iname \\*.yml ! -iname snakemake* ! -iname snakebids* \\) -exec yamlfix --check {} \\;" } +isort = "isort labelmerge" +isort-check = "isort -c labelmerge" black = "black labelmerge" +black-check = "black --check labelmerge" flake8 = "flake8 labelmerge" snakefmt = "snakefmt labelmerge" +snakefmt-check = "snakefmt --check labelmerge" quality = ["yamlfix", "isort", "black", "flake8", "snakefmt"] +quality-check = [ + "yamlfix-check", + "isort-check", + "black-check", + "flake8", + "snakefmt-check", +] [tool.isort] profile = "black" From 7c544d59b6823657052d9a4988f8108467295fd1 Mon Sep 17 00:00:00 2001 From: Tristan Kuehn Date: Tue, 10 Jan 2023 12:02:00 -0500 Subject: [PATCH 2/2] Bring local flake8 in line and fix errors --- .flake8 | 2 ++ labelmerge/workflow/scripts/labelmerge.py | 10 ++++++---- pyproject.toml | 3 --- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..bfead2c --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 79 diff --git a/labelmerge/workflow/scripts/labelmerge.py b/labelmerge/workflow/scripts/labelmerge.py index 45faabe..1e8d150 100644 --- a/labelmerge/workflow/scripts/labelmerge.py +++ b/labelmerge/workflow/scripts/labelmerge.py @@ -36,7 +36,8 @@ def assemble_mask( name: str = metadata[metadata["index"] == label].name.iloc[0] except IndexError as err: raise MetadataError( - f"Label with index {label} from {prefix}atlas not found in metadata table." + f"Label with index {label} from {prefix}atlas not found in " + "metadata table." ) from err return ( f"{prefix}{name}", @@ -122,8 +123,8 @@ def gen_parser() -> ArgumentParser: "--base_exceptions", nargs="*", help=( - "Space separated list of integer labels from the base image to keep over " - "overlay labels at the same voxels." + "Space separated list of integer labels from the base image to " + "keep over overlay labels at the same voxels." ), type=int, ) @@ -131,7 +132,8 @@ def gen_parser() -> ArgumentParser: "--overlay_exceptions", nargs="*", help=( - "Space separated list of integer labels from the overlay image to discard." + "Space separated list of integer labels from the overlay image to " + "discard." ), type=int, ) diff --git a/pyproject.toml b/pyproject.toml index b02f536..3ce82e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,9 +64,6 @@ multi_line_output = 3 [tool.black] line-length = 79 -[tool.flake8] -ignore = 'E501' - [tool.snakefmt] line_length = 79 include = '\.smk$|^Snakefile'