Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip package #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Python wrapper
*.py[co]
*.so
__pycache__/
/_skbuild/
/_cmake_test_compile/
/niftyreg/_dist_ver.py
/niftyreg/niftyreg
MANIFEST
/*.egg*/
/build/
/dist/
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -229,4 +232,4 @@ if(DOXYGEN_FOUND)
)
message(STATUS "Found doxygen")
endif(DOXYGEN_FOUND)
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
29 changes: 29 additions & 0 deletions niftyreg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Thin wrapper around niftyreg binaries"""
__author__ = "Casper da Costa-Luis <https://github.com/casperdcl>"
__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:])
3 changes: 3 additions & 0 deletions niftyreg/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import main

main()
2 changes: 1 addition & 1 deletion niftyreg_build_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
69
70
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
40 changes: 40 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
[email protected]
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
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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"])