Skip to content

Commit

Permalink
Merge pull request #31 from khanlab/fix-flake8
Browse files Browse the repository at this point in the history
Update quality workflow to check instead of modify
  • Loading branch information
tkkuehn authored Jan 10, 2023
2 parents a10eb84 + 7c544d5 commit 965183f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 79
8 changes: 4 additions & 4 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions labelmerge/workflow/rules/label_harmonization.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 11 additions & 6 deletions labelmerge/workflow/scripts/labelmerge.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -35,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}",
Expand Down Expand Up @@ -121,16 +123,17 @@ 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,
)
parser.add_argument(
"--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,
)
Expand All @@ -145,7 +148,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,
Expand Down
16 changes: 12 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -53,9 +64,6 @@ multi_line_output = 3
[tool.black]
line-length = 79

[tool.flake8]
ignore = 'E501'

[tool.snakefmt]
line_length = 79
include = '\.smk$|^Snakefile'

0 comments on commit 965183f

Please sign in to comment.