diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 7b1545e..020c966 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -8,17 +8,17 @@ name: CI/CD on: push: - branches: [ main ] + branches: [ main, develop ] tags: [ '*' ] pull_request: - branches: [ main ] + branches: [ main, develop ] jobs: devcheck: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, '3.10'] # Check oldest and newest versions + python-version: ['3.8', '3.12'] # Check oldest and newest versions pip-flags: ['', '--editable'] pydra: - 'pydra' @@ -92,7 +92,7 @@ jobs: run: python -m build - name: Check distributions run: twine check dist/* - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: distributions path: dist/ diff --git a/README.md b/README.md index 303ac2d..7241818 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,15 @@ All tasks will be inserted into the `pydra.tasks.` namespac 1. Once the repo is created and cloned, search for CHANGEME (`grep -rn CHANGEME . `) and replace with appropriate name. 1. Rename the namespace package root directory to replace `CHANGEME` with the name of the package: - * `src/pydra/tasks/CHANGEME` + * `pydra/tasks/CHANGEME` 1. Under the newly renamed package (i.e. formerly CHANGEME) there is a directory named "v1", - `src/pydra/tasks//v1`, change this to valid Python package name starting with + `pydra/tasks//v1`, change this to valid Python package name starting with 'v' to indicate the version of the tool the Pydra interfaces will be designed for, - e.g. FSL v6.0.2 could be `src/pydra/tasks/fsl/v6` or `src/pydra/tasks/fsl/v6_0` depending on + e.g. FSL v6.0.2 could be `pydra/tasks/fsl/v6` or `pydra/tasks/fsl/v6_0` depending on how stable the CLI of the tool is between minor versions. -1. Edit `src/pydra/tasks//latest.py` to update references to `v1` to the +1. Edit `pydra/tasks//latest.py` to update references to `v1` to the tool target version -1. Add tasks to the `src/pydra/tasks//v` folder. +1. Add tasks to the `pydra/tasks//v` folder. 1. You may want to initialize a [Sphinx] docs directory. 1. Review the workflow in `.github/workflows/pythonpackage.yml`. Testing editable installations is probably not useful unless you are reconfiguring namespace packages. diff --git a/docs/conf.py b/docs/conf.py index c8338f4..954c63b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,7 +17,7 @@ # -- Project information ----------------------------------------------------- -project = "pydra-CHANGEME" +project = "pydra-tasks-CHANGEME" copyright = "2020, Xihe Xie" author = "Xihe Xie" diff --git a/pydra/tasks/CHANGEME/v1/__init__.py b/pydra/tasks/CHANGEME/v1_0/__init__.py similarity index 100% rename from pydra/tasks/CHANGEME/v1/__init__.py rename to pydra/tasks/CHANGEME/v1_0/__init__.py diff --git a/pyproject.toml b/pyproject.toml index a5ea6c7..b6b3605 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,13 +3,13 @@ requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" [project] -name = "pydra-CHANGEME" +name = "pydra-tasks-CHANGEME" description = "Pydra tasks package for CHANGEME" readme = "README.md" requires-python = ">=3.8" dependencies = [ - "pydra >=0.22", - "fileformats >=0.8.3", + "pydra >=1.0a", + "fileformats >=0.15.0", "fileformats-datascience >=0.1", "fileformats-medimage >=0.4.1", "fileformats-medimage-CHANGEME" diff --git a/tools/increment_tool_version.py b/tools/increment_tool_version.py new file mode 100755 index 0000000..e6d56ed --- /dev/null +++ b/tools/increment_tool_version.py @@ -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() diff --git a/tools/rename_template.py b/tools/rename_template.py index ef1889c..05055bb 100755 --- a/tools/rename_template.py +++ b/tools/rename_template.py @@ -24,14 +24,14 @@ def load_gitignore(repo): cmd, new_name, *_ = sys.argv -for root, dirs, files in os.walk(PACKAGE_ROOT): +for root_, dirs, files in os.walk(PACKAGE_ROOT): ignore = load_gitignore(PACKAGE_ROOT).search for d in [d for d in dirs if ignore(f"{d}/")]: dirs.remove(d) for f in [f for f in files if ignore(f)]: files.remove(f) - root = Path(root) + root = Path(root_) for src in list(dirs): if "CHANGEME" in src: dst = src.replace("CHANGEME", new_name) @@ -40,7 +40,6 @@ def load_gitignore(repo): dirs.remove(src) dirs.append(dst) for fname in files: - f = root / fname text = Path.read_text(root / fname) if "CHANGEME" in text: print(f"Rewriting: {root / fname}") diff --git a/tools/requirements.txt b/tools/requirements.txt new file mode 100644 index 0000000..3b7ccec --- /dev/null +++ b/tools/requirements.txt @@ -0,0 +1,3 @@ +click >= 8.1.3 +looseversion >= 1.1 +pydra >= 0.23 \ No newline at end of file