We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4844349 commit 502f533Copy full SHA for 502f533
4 files changed
.pre-commit-config.yaml
@@ -9,7 +9,7 @@ ci:
9
10
repos:
11
- repo: https://github.com/pre-commit/pre-commit-hooks
12
- rev: v4.3.0
+ rev: v4.4.0
13
hooks:
14
- id: end-of-file-fixer
15
- id: trailing-whitespace
@@ -23,20 +23,20 @@ repos:
23
- id: detect-private-key
24
25
- repo: https://github.com/psf/black
26
- rev: 22.3.0
+ rev: 23.3.0
27
28
- id: black
29
name: format code
30
31
- repo: https://github.com/PyCQA/isort
32
- rev: 5.10.1
+ rev: 5.12.0
33
34
- id: isort
35
name: format imports
36
args: ["--profile", "black"]
37
38
- repo: https://github.com/executablebooks/mdformat
39
- rev: 0.7.14
+ rev: 0.7.16
40
41
- id: mdformat
42
name: format markdown
@@ -46,28 +46,28 @@ repos:
46
exclude: CHANGELOG.md
47
48
- repo: https://github.com/PyCQA/flake8
49
- rev: 4.0.1
+ rev: 6.0.0
50
51
- id: flake8
52
name: check PEP8
53
args: ["--ignore=E501,W503,E203"]
54
55
- repo: https://github.com/asottile/pyupgrade
56
- rev: v2.34.0
+ rev: v3.7.0
57
58
- id: pyupgrade
59
name: upgrade code
60
args: ["--py37-plus"]
61
62
- repo: https://github.com/hadialqattan/pycln
63
- rev: v1.2.5
+ rev: v2.1.5
64
65
- id: pycln
66
name: prune imports
67
args: [--expand-stars]
68
69
- repo: https://github.com/nbQA-dev/nbQA
70
- rev: 1.3.1
+ rev: 1.7.0
71
72
- id: nbqa-black
73
additional_dependencies: [black]
examples/pre_processing.py
@@ -1,4 +1,4 @@
1
-from typing import Optional
+from typing import Optional, Union
2
3
import SimpleITK as sitk
4
import typer
@@ -9,7 +9,16 @@
@register_command(app)
-def median_filter(input: sitk.Image, radius: int) -> sitk.Image:
+def add(input1: sitk.Image, input2: Union[sitk.Image, None] = None) -> sitk.Image:
+ """Perform foo filtering"""
+ if input2:
+ sum: sitk.Image = input1 + input2
16
+ return sum
17
+ return input1
18
+
19
20
+@register_command(app)
21
+def median_filter(input: sitk.Image, radius: int = 2) -> sitk.Image:
22
"""Perform median filtering"""
image: sitk.Image = sitk.Median(input, [radius] * input.GetDimension())
return image
setup.cfg
@@ -1,6 +1,7 @@
[metadata]
name = sitk-cli
-version = 0.4.0
+version = 0.5.0
+requires-python = ">=3.8"
5
url = https://github.com/dyollb/sitk-cli
6
description = Wrap SimpleITK functions as command lines
7
long_description = file: README.md
src/sitk_cli/lib.py
@@ -1,6 +1,6 @@
from inspect import Parameter, isclass, signature
from pathlib import Path
+from typing import Optional, Union, get_args, get_origin
@@ -14,10 +14,15 @@ def make_cli(func, output_arg_name="output"):
def _translate_param(p: Parameter):
annotation, default = p.annotation, p.default
- if isclass(p.annotation) and issubclass(
- p.annotation, (sitk.Image, sitk.Transform)
- ):
- if issubclass(p.annotation, sitk.Image):
+ # handle Optional[A] and Union[A, None]
+ origin = get_origin(annotation)
+ args = get_args(annotation)
+ if origin is Union and args and not isinstance(args[0], type(None)):
+ annotation = get_args(annotation)[0]
+ if isclass(annotation) and issubclass(annotation, (sitk.Image, sitk.Transform)):
+ if issubclass(annotation, sitk.Image):
image_args.append(p.name)
else:
transform_args.append(p.name)
0 commit comments