Skip to content

Commit d81a335

Browse files
authored
Merge pull request #13 from jluethi/update_template
Update template & switch to Pydantic V2
2 parents 4fc3c85 + 1f6a4a4 commit d81a335

10 files changed

+88
-77
lines changed

.copier-answers.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Do not edit - changes here will be overwritten by Copier
2-
_commit: v0.1.3
2+
_commit: v0.3.0
33
_src_path: gh:fractal-analytics-platform/fractal-tasks-template
44
author_email: [email protected]
55
author_name: Joel Luethi
66
package_name: fractal_helper_tasks
77
project_name: fractal-helper-tasks
88
project_short_description: Collection of Fractal helper tasks
9-
project_url: ''
9+
project_url: https://github.com/jluethi/fractal-helper-tasks
1010

.pre-commit-config.yaml

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
# enable pre-commit.ci at https://pre-commit.ci/
2-
# it adds:
3-
# 1. auto fixing pull requests
4-
# 2. auto updating the pre-commit configuration
5-
ci:
6-
autoupdate_schedule: monthly
7-
autofix_commit_msg: "style(pre-commit.ci): auto fixes [...]"
8-
autoupdate_commit_msg: "ci(pre-commit.ci): autoupdate"
92

103
repos:
114
- repo: https://github.com/abravalheri/validate-pyproject
@@ -14,12 +7,8 @@ repos:
147
- id: validate-pyproject
158

169
- repo: https://github.com/charliermarsh/ruff-pre-commit
17-
rev: v0.1.3
10+
rev: v0.5.0
1811
hooks:
1912
- id: ruff
2013
args: [--fix]
21-
22-
- repo: https://github.com/psf/black
23-
rev: 23.10.1
24-
hooks:
25-
- id: black
14+
- id: ruff-format

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](LICENSE)
44
![Python version](https://img.shields.io/badge/python-%3E%3D3.9-blue)
5-
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jluethi/fractal-helper-tasks/your-workflow-file.yml?branch=main)
5+
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jluethi/fractal-helper-tasks/ci_pip.yml?branch=main)
66
[![codecov](https://codecov.io/gh/jluethi/fractal-helper-tasks/graph/badge.svg?token=ednmg2GzOw)](https://codecov.io/gh/jluethi/fractal-helper-tasks)
77

88
Collection of Fractal helper tasks

pyproject.toml

+40-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1+
# https://peps.python.org/pep-0517/
2+
[build-system]
3+
requires = ["hatchling", "hatch-vcs"]
4+
build-backend = "hatchling.build"
5+
6+
# https://hatch.pypa.io/latest/config/metadata/
7+
[tool.hatch.version]
8+
#path = "src/fractal_helper_tasks/__init__.py"
9+
source = "vcs"
10+
11+
# read more about configuring hatch at:
12+
# https://hatch.pypa.io/latest/config/build/
13+
[tool.hatch.build.targets.wheel]
14+
only-include = ["src"]
15+
sources = ["src"]
16+
17+
# Always include the __FRACTAL_MANIFEST__.json file in the package
18+
[tool.hatch.build]
19+
include = ["__FRACTAL_MANIFEST__.json"]
20+
21+
122
# Project metadata (see https://peps.python.org/pep-0621)
223
[project]
324
name = "fractal-helper-tasks"
4-
version = "0.1.0"
25+
dynamic = ["version"]
526
description = "Collection of Fractal helper tasks"
627
readme = "README.md"
728
license = { text = "BSD-3-Clause" }
@@ -12,39 +33,30 @@ authors = [
1233
# Required Python version and dependencies
1334
requires-python = ">=3.9"
1435
dependencies = [
15-
"fractal-tasks-core==1.0.0"
36+
"fractal-tasks-core==1.2.0"
1637
]
1738

1839
# Optional dependencies (e.g. for `pip install -e ".[dev]"`, see
1940
# https://peps.python.org/pep-0621/#dependencies-optional-dependencies)
2041
[project.optional-dependencies]
21-
dev = ["devtools", "pytest", "requests", "build", "jsonschema", "pooch"]
42+
dev = ["devtools", "hatch", "pytest", "requests", "jsonschema", "ruff", "pre-commit", "pooch"]
2243
test = ["pytest", "pytest-cov"]
2344

24-
# Build options (see https://peps.python.org/pep-0517)
25-
[build-system]
26-
requires = ["setuptools"]
27-
build-backend = "setuptools.build_meta"
28-
29-
[tool.setuptools.packages.find]
30-
where = ["src"]
31-
include = ["fractal_helper_tasks"]
32-
33-
# Always include the __FRACTAL_MANIFEST__.json file in the package
34-
[tool.setuptools.package-data]
35-
"*" = ["__FRACTAL_MANIFEST__.json"]
36-
3745
# https://docs.astral.sh/ruff
3846
[tool.ruff]
3947
line-length = 88
40-
target-version = "py38"
48+
target-version = "py39"
4149
src = ["src"]
50+
4251
# https://docs.astral.sh/ruff/rules
52+
[tool.ruff.lint]
53+
pydocstyle = { convention = "google" }
4354
select = [
4455
"E", # style errors
4556
"W", # style warnings
4657
"F", # flakes
4758
"D", # pydocstyle
59+
"D417", # Missing argument descriptions in Docstrings
4860
"I", # isort
4961
"UP", # pyupgrade
5062
"C4", # flake8-comprehensions
@@ -54,20 +66,24 @@ select = [
5466
"TCH", # flake8-type-checking
5567
"TID", # flake8-tidy-imports
5668
]
57-
58-
[tool.ruff.lint]
59-
pydocstyle = { convention = "numpy" }
6069
extend-select = [
6170
"D417", # Missing argument descriptions in Docstrings
6271
]
63-
extend-ignore = [
72+
ignore = [
6473
"D401", # First line should be in imperative mood (remove to opt in)
6574
"C408", # Unnecessary `dict` call
75+
"D415", # First line should end with a period (remove to opt in)
76+
"UP022" # Used in validate_command test, waiting for template fix
6677
]
6778

68-
[tool.ruff.per-file-ignores]
79+
[tool.ruff.lint.per-file-ignores]
6980
"tests/*.py" = ["D", "S"]
70-
"setup.py" = ["D"]
81+
82+
# https://docs.astral.sh/ruff/formatter/
83+
[tool.ruff.format]
84+
docstring-code-format = true
85+
docstring-code-line-length = 89
86+
skip-magic-trailing-comma = false # default is false
7187

7288
[tool.coverage.run]
7389
# Include only the specific package directories for coverage, exclude tests
@@ -78,4 +94,4 @@ omit = [
7894
"*/tests/*",
7995
"*_test.py",
8096
"setup.py"
81-
]
97+
]

src/fractal_helper_tasks/__FRACTAL_MANIFEST__.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@
1212
"mem": 8000
1313
},
1414
"args_schema_non_parallel": {
15-
"title": "DropTDimension",
16-
"type": "object",
15+
"additionalProperties": false,
1716
"properties": {
1817
"zarr_url": {
1918
"title": "Zarr Url",
2019
"type": "string",
2120
"description": "Path or url to the individual OME-Zarr image to be processed. (standard argument for Fractal tasks, managed by Fractal server)."
2221
},
2322
"suffix": {
24-
"title": "Suffix",
2523
"default": "no_T",
24+
"title": "Suffix",
2625
"type": "string",
2726
"description": "Suffix to be used for the new Zarr image. If overwrite_input is True, this file is only temporary."
2827
},
2928
"overwrite_input": {
30-
"title": "Overwrite Input",
3129
"default": false,
30+
"title": "Overwrite Input",
3231
"type": "boolean",
3332
"description": "Whether"
3433
}
3534
},
3635
"required": [
3736
"zarr_url"
3837
],
39-
"additionalProperties": false
38+
"type": "object",
39+
"title": "DropTDimension"
4040
},
4141
"docs_info": "## drop_t_dimension\nDrops singleton t dimension.\n"
4242
},
@@ -51,8 +51,7 @@
5151
"mem": 8000
5252
},
5353
"args_schema_parallel": {
54-
"title": "Convert2dSegmentationTo3d",
55-
"type": "object",
54+
"additionalProperties": false,
5655
"properties": {
5756
"zarr_url": {
5857
"title": "Zarr Url",
@@ -65,17 +64,17 @@
6564
"description": "Name of the label to copy from 2D OME-Zarr to 3D OME-Zarr"
6665
},
6766
"level": {
68-
"title": "Level",
6967
"default": 0,
68+
"title": "Level",
7069
"type": "integer",
7170
"description": "Level of the 2D OME-Zarr label to copy from"
7271
},
7372
"ROI_tables_to_copy": {
74-
"title": "Roi Tables To Copy",
75-
"type": "array",
7673
"items": {
7774
"type": "string"
7875
},
76+
"title": "Roi Tables To Copy",
77+
"type": "array",
7978
"description": "List of ROI table names to copy from 2D OME-Zarr to 3D OME-Zarr"
8079
},
8180
"new_label_name": {
@@ -84,14 +83,14 @@
8483
"description": "Optionally overwriting the name of the label in the 3D OME-Zarr"
8584
},
8685
"new_table_names": {
86+
"items": {},
8787
"title": "New Table Names",
8888
"type": "array",
89-
"items": {},
9089
"description": "Optionally overwriting the names of the ROI tables in the 3D OME-Zarr"
9190
},
9291
"plate_suffix": {
93-
"title": "Plate Suffix",
9492
"default": "_mip",
93+
"title": "Plate Suffix",
9594
"type": "string",
9695
"description": "Suffix of the 2D OME-Zarr that needs to be removed to generate the path to the 3D OME-Zarr. If the 2D OME-Zarr is \"/path/to/my_plate_mip.zarr/B/03/0\" and the 3D OME-Zarr is located in \"/path/to/my_plate.zarr/B/03/0\", the correct suffix is \"_mip\"."
9796
},
@@ -106,8 +105,8 @@
106105
"description": "If the image name between 2D & 3D don't match, this is the suffix that should be added to the 3D image. If the 2D image is in \"/path/to/my_plate_mip.zarr/B/03/0\" and the 3D image is in \"/path/to/my_plate.zarr/B/03/0_illum_corr\", the value should be \"_illum_corr\"."
107106
},
108107
"overwrite": {
109-
"title": "Overwrite",
110108
"default": false,
109+
"title": "Overwrite",
111110
"type": "boolean",
112111
"description": "If `True`, overwrite existing label and ROI tables in the 3D OME-Zarr"
113112
}
@@ -116,11 +115,12 @@
116115
"zarr_url",
117116
"label_name"
118117
],
119-
"additionalProperties": false
118+
"type": "object",
119+
"title": "Convert2dSegmentationTo3d"
120120
},
121121
"docs_info": "## convert_2D_segmentation_to_3D\nConvert 2D segmentation to 3D segmentation.\n\nThis task loads the 2D segmentation, replicates it along the Z slice and\nstores it back into the 3D OME-Zarr image.\n\nThis is a temporary workaround task, as long as we store 2D data in\na separate OME-Zarr file from the 3D data. If the 2D & 3D OME-Zarr images\nhave different suffixes in their name, use `image_suffix_2D_to_remove` &\n`image_suffix_3D_to_add`. If their base names are different, this task\ndoes not support processing them at the moment.\n\nIt makes the assumption that the 3D OME-Zarrs are stored in the same place\nas the 2D OME-Zarrs (same based folder).\n"
122122
}
123123
],
124124
"has_args_schemas": true,
125-
"args_schema_version": "pydantic_v1"
125+
"args_schema_version": "pydantic_v2"
126126
}

src/fractal_helper_tasks/__init__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
"""
2-
Collection of Fractal helper tasks
3-
"""
1+
"""Collection of Fractal helper tasks"""
2+
3+
from importlib.metadata import PackageNotFoundError, version
4+
5+
try:
6+
__version__ = version("fractal-helper-tasks")
7+
except PackageNotFoundError:
8+
__version__ = "uninstalled"

src/fractal_helper_tasks/convert_2D_segmentation_to_3D.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Fractal task to convert 2D segmentations into 3D segmentations."""
2+
23
import logging
34
from typing import Optional
45

@@ -10,7 +11,7 @@
1011
from fractal_tasks_core.ngff.zarr_utils import load_NgffImageMeta
1112
from fractal_tasks_core.pyramids import build_pyramid
1213
from fractal_tasks_core.tables import write_table
13-
from pydantic.decorator import validate_arguments
14+
from pydantic import validate_call
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -38,8 +39,7 @@ def get_zattrs(zarr_url):
3839

3940

4041
def make_zattrs_3D(attrs, z_pixel_size, new_label_name):
41-
"""
42-
Creates 3D zattrs based on 2D attrs.
42+
"""Creates 3D zattrs based on 2D attrs.
4343
4444
Performs the following checks:
4545
1) If the label image has 2 axes, add a Z axis and updadte the
@@ -88,7 +88,7 @@ def check_table_validity(new_table_names, old_table_names):
8888
)
8989

9090

91-
@validate_arguments
91+
@validate_call
9292
def convert_2D_segmentation_to_3D(
9393
zarr_url: str,
9494
label_name: str,
@@ -101,8 +101,7 @@ def convert_2D_segmentation_to_3D(
101101
image_suffix_3D_to_add: Optional[str] = None,
102102
overwrite: bool = False,
103103
) -> None:
104-
"""
105-
Convert 2D segmentation to 3D segmentation.
104+
"""Convert 2D segmentation to 3D segmentation.
106105
107106
This task loads the 2D segmentation, replicates it along the Z slice and
108107
stores it back into the 3D OME-Zarr image.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
"""Generate JSON schemas for tasks and write them to the Fractal manifest."""
1+
"""Manifest generation"""
22

33
from fractal_tasks_core.dev.create_manifest import create_manifest
44

55
if __name__ == "__main__":
6+
"""Generate JSON schemas for task arguments afresh, and write them
7+
to the package manifest.
8+
"""
69
PACKAGE = "fractal_helper_tasks"
710
create_manifest(package=PACKAGE)

src/fractal_helper_tasks/drop_t_dimension.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
# This file is derived from a Fractal task core task developed by
77
# Tommaso Comparin & Marco Franzon
88
"""Task to remove singelton T dimension from an OME-Zarr."""
9+
910
import logging
1011
from typing import Any
1112

1213
import dask.array as da
1314
import zarr
1415
from fractal_tasks_core.ngff import load_NgffImageMeta
1516
from fractal_tasks_core.pyramids import build_pyramid
16-
from pydantic.decorator import validate_arguments
17+
from pydantic import validate_call
1718

1819
logger = logging.getLogger(__name__)
1920

2021

2122
def get_attrs_without_t(zarr_url: str):
22-
"""
23-
Generate zattrs without the t dimension.
23+
"""Generate zattrs without the t dimension.
2424
2525
Args:
2626
zarr_url: Path to the zarr image
@@ -39,15 +39,14 @@ def get_attrs_without_t(zarr_url: str):
3939
return zattrs
4040

4141

42-
@validate_arguments
42+
@validate_call
4343
def drop_t_dimension(
4444
*,
4545
zarr_url: str,
4646
suffix: str = "no_T",
4747
overwrite_input: bool = False,
4848
) -> dict[str, Any]:
49-
"""
50-
Drops singleton t dimension.
49+
"""Drops singleton t dimension.
5150
5251
Args:
5352
zarr_url: Path or url to the individual OME-Zarr image to be processed.

0 commit comments

Comments
 (0)