Skip to content

Commit

Permalink
added increment_version_tool and edited NOTICE file
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Mar 22, 2024
1 parent 62f0eb2 commit 10f855d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Revert version to most recent version tag on upstream update
- name: Revert version to most recent version tag on Nipype or Nipype2Pydra update
if: github.event_name == 'repository_dispatch'
run: git checkout $(git tag -l | grep 'v.*' | tail -n 1 | awk -F post '{print $1}')

Expand Down
9 changes: 9 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Pydra-Ants
Copyright 2024 Pydra Development Team

The ApplyTransforms, BiasCorrection, CreateJacobianDeterminantImage and Registration
task interfaces were copied from the https://github.com/ghisvail/pydra-ants repository.

The basis for the remaining task interfaces defined in this package were semi-automatically
converted from Nipype interfaces (https://github.com/nipy/nipype) using the Nipype2Pydra
tool (https://github.com/nipype/nipype2pydra).
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies = [
"fileformats >=0.8.3",
"fileformats-datascience >=0.1",
"fileformats-medimage >=0.4.1",
"fileformats-medimage-ants"
# "fileformats-medimage-ants"
]
license = {file = "LICENSE"}
authors = [{name = "Nipype developers", email = "[email protected]"}]
Expand Down Expand Up @@ -54,7 +54,7 @@ test = [
"fileformats-extras",
"fileformats-datascience-extras",
"fileformats-medimage-extras",
"fileformats-medimage-ants-extras"
# "fileformats-medimage-ants-extras"
]

[tool.hatch.version]
Expand Down
69 changes: 69 additions & 0 deletions tools/increment_tool_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
from pathlib import Path
import inspect
from importlib import import_module
import click
from looseversion import LooseVersion
from pydra.engine.core import TaskBase


PKG_DIR = Path(__file__).parent.parent
TASKS_DIR = PKG_DIR / "pydra" / "tasks" / "ants"
VERSION_GRANULARITY = (
2 # Number of version parts to include: 1 - major, 2 - minor, 3 - micro
)


@click.command(
help="""Increment the latest version or create a new sub-package for interfaces for
a new release of AFNI depending on whether one already exists or not.
NEW_VERSION the version of AFNI to create a new sub-package for
"""
)
@click.argument("new_version", type=LooseVersion)
def increment_tool_version(new_version: LooseVersion):

# Get the name of the sub-package, e.g. "v2_5"
new_subpkg_name = "_".join(str(p) for p in new_version.version[:VERSION_GRANULARITY]) # type: ignore
if not new_subpkg_name.startswith("v"):
new_subpkg_name = "v" + new_subpkg_name
sub_pkg_dir = TASKS_DIR / new_subpkg_name
if not sub_pkg_dir.exists():

prev_version = sorted(
(
p.name
for p in TASKS_DIR.iterdir()
if p.is_dir() and p.name.startswith("v")
),
key=lambda x: LooseVersion(".".join(x.split("_"))).version,
)[-1]
prev_ver_mod = import_module(f"pydra.tasks.ants.{prev_version}")

mod_attrs = [getattr(prev_ver_mod, a) for a in dir(prev_ver_mod)]
task_classes = [
a for a in mod_attrs if inspect.isclass(a) and issubclass(a, TaskBase)
]

code_str = (
f"from pydra.tasks.ants import {prev_version}\n"
"from . import _tool_version\n"
)

for task_cls in task_classes:
code_str += (
f"\n\nclass {task_cls.__name__}({prev_version}.{task_cls.__name__}):\n"
" TOOL_VERSION = _tool_version.TOOL_VERSION\n"
)

sub_pkg_dir.mkdir(exist_ok=True)
with open(sub_pkg_dir / "__init__.py", "w") as f:
f.write(code_str)

with open(sub_pkg_dir / "_tool_version.py", "w") as f:
f.write(f'TOOL_VERSION = "{new_version}"\n')


if __name__ == "__main__":
increment_tool_version()
3 changes: 3 additions & 0 deletions tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
click >= 8.1.3
looseversion >= 1.1
pydra >= 0.23

0 comments on commit 10f855d

Please sign in to comment.