diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..975417c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Python wrapper +*.py[co] +*.so +__pycache__/ +/_skbuild/ +/_cmake_test_compile/ +/niftyreg/_dist_ver.py +/niftyreg/niftyreg +MANIFEST +/*.egg*/ +/build/ +/dist/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 5becd7d4..93fd8af3 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,9 @@ endif("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" MAT if(APPLE) set(CMAKE_MACOSX_RPATH "${CMAKE_INSTALL_PREFIX}/lib") endif(APPLE) +if(SKBUILD) + set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/niftyreg") +endif(SKBUILD) #----------------------------------------------------------------------------- if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message("In-source builds not allowed by NiftyReg police.") @@ -229,4 +232,4 @@ if(DOXYGEN_FOUND) ) message(STATUS "Found doxygen") endif(DOXYGEN_FOUND) -#----------------------------------------------------------------------------- \ No newline at end of file +#----------------------------------------------------------------------------- diff --git a/niftyreg/__init__.py b/niftyreg/__init__.py new file mode 100644 index 00000000..13ff7074 --- /dev/null +++ b/niftyreg/__init__.py @@ -0,0 +1,29 @@ +"""Thin wrapper around niftyreg binaries""" +__author__ = "Casper da Costa-Luis " +__date__ = "2022" +# version detector. Precedence: installed dist, git, 'UNKNOWN' +try: + from ._dist_ver import __version__ +except ImportError: # pragma: nocover + try: + from setuptools_scm import get_version + + __version__ = get_version(root="../..", relative_to=__file__) + except (ImportError, LookupError): + __version__ = "UNKNOWN" +__all__ = ['bin_path', 'main'] + +from pathlib import Path + +bin_path = Path(__file__).resolve().parent / "bin" + + +def main(args=None): + if args is None: + import sys + args = sys.argv[1:] + if not args or args[0].startswith("-"): + print(f"Options: {' '.join(i.name[4:] for i in bin_path.glob('reg_*'))}") + else: + from subprocess import run + run([str(bin_path / ("reg_" + args[0]))] + args[1:]) diff --git a/niftyreg/__main__.py b/niftyreg/__main__.py new file mode 100644 index 00000000..8273c4ff --- /dev/null +++ b/niftyreg/__main__.py @@ -0,0 +1,3 @@ +from . import main + +main() diff --git a/niftyreg_build_version.txt b/niftyreg_build_version.txt index b5489e5e..2bbd69c2 100644 --- a/niftyreg_build_version.txt +++ b/niftyreg_build_version.txt @@ -1 +1 @@ -69 +70 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1e627d69 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4", + "scikit-build>=0.11.0", "cmake>=3.18", "ninja"] + +[tool.setuptools_scm] +write_to = "niftyreg/_dist_ver.py" +write_to_template = "__version__ = '{version}'\n" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..d8c5efe4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,40 @@ +[metadata] +name=niftyreg +description=NiftyReg Python package +long_description=file: README.txt +long_description_content_type=text/markdown +license_file=LICENSE.txt +url=https://github.com/KCL-BMEIS/niftyreg +project_urls= + Changelog=https://github.com/KCL-BMEIS/niftyreg/releases +author=Marc Modat +maintainer=Casper da Costa-Luis +maintainer_email=imaging@cdcl.ml +keywords=image-registration +classifiers= + Development Status :: 5 - Production/Stable + Intended Audience :: Education + Intended Audience :: Healthcare Industry + Intended Audience :: Science/Research + Operating System :: Microsoft :: Windows + Operating System :: POSIX :: Linux + Programming Language :: C++ + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3 :: Only + Topic :: Scientific/Engineering :: Medical Science Apps. +[options] +setup_requires= + setuptools>=42 + wheel + setuptools_scm[toml] + scikit-build>=0.11.0 + cmake>=3.18 + ninja +python_requires=>=3.6 +[options.entry_points] +console_scripts= + niftyreg=niftyreg:main diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..5b8fea47 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +"""Compile source code and setup Python 3 package""" +import re +from pathlib import Path + +from setuptools_scm import get_version +from skbuild import setup + +__version__ = get_version(root=".", relative_to=__file__) +build_ver = ".".join(__version__.split(".")[:3]).split(".dev")[0] +for i in (Path(__file__).resolve().parent / "_skbuild").rglob("CMakeCache.txt"): + i.write_text(re.sub("^//.*$\n^[^#].*pip-build-env.*$", "", i.read_text(), flags=re.M)) +setup(use_scm_version=True, packages=["niftyreg"], + cmake_languages=("CXX",), cmake_minimum_required_version="3.18", + cmake_args=["-DBUILD_ALL_DEP=ON"])