From 458ac6532335b874f49196ad4bc6ffa2e63253ec Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 15 Jan 2022 12:03:19 +0000 Subject: [PATCH 1/7] Python package --- .gitignore | 11 +++++++++++ SuperBuild/SuperBuild.cmake | 4 ++++ dcm2niix/__init__.py | 19 ++++++++++++++++++ pyproject.toml | 7 +++++++ setup.cfg | 39 +++++++++++++++++++++++++++++++++++++ setup.py | 14 +++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 dcm2niix/__init__.py create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 0b9be923..0b86f87c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,14 @@ /build/ /bin/ /console/dcm2niix +# Python wrapper +*.py[co] +*.so +__pycache__/ +/_skbuild/ +/_cmake_test_compile/ +/dcm2niix/_dist_ver.py +/dcm2niix/dcm2niix +MANIFEST +/*.egg*/ +/dist/ diff --git a/SuperBuild/SuperBuild.cmake b/SuperBuild/SuperBuild.cmake index e1057a0f..f395cafb 100644 --- a/SuperBuild/SuperBuild.cmake +++ b/SuperBuild/SuperBuild.cmake @@ -164,6 +164,10 @@ ExternalProject_Add(console -DBUILD_DCM2NIIXFSLIB:BOOL=${BUILD_DCM2NIIXFSLIB} ) +if(SKBUILD) + install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION dcm2niix + USE_SOURCE_PERMISSIONS) +endif() install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION bin USE_SOURCE_PERMISSIONS) diff --git a/dcm2niix/__init__.py b/dcm2niix/__init__.py new file mode 100644 index 00000000..6b32f89d --- /dev/null +++ b/dcm2niix/__init__.py @@ -0,0 +1,19 @@ +"""Thin wrapper around dcm2niix binary""" +__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', 'bin_path'] + +from pathlib import Path + +bin_path = Path(__file__).resolve().parent / "dcm2niix" +bin = str(bin_path) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..5c9a0639 --- /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 = "dcm2niix/_dist_ver.py" +write_to_template = "__version__ = '{version}'\n" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..d7c58507 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,39 @@ +[metadata] +name=pydcm2niix +description=DCM2NIIX Python package +long_description=file: README.md +long_description_content_type=text/markdown +license_file=license.txt +url=https://github.com/rordenlab/dcm2niix +project_urls= + Changelog=https://github.com/rordenlab/dcm2niix/releases + Documentation=https://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage +author=Li X, Morgan PS, Ashburner J, Smith J, Rorden C +maintainer=Casper da Costa-Luis +maintainer_email=imaging@cdcl.ml +keywords=research, jpeg, dicom, neuroscience, mri, neuroimaging, nifti, dcm, nii, nitrc, bids, dcm2niix, mricrogl +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 :: 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 diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..05552803 --- /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=["dcm2niix"], + cmake_languages=("CXX",), cmake_minimum_required_version="3.18", + cmake_args=[f"-DCM2NIIX_BUILD_VERSION={build_ver}", "-DBUILD_ALL_DEP=ON"]) From b439045c94e145fe90d9b190126a6b6d30c0ad01 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 15 Jan 2022 12:14:01 +0000 Subject: [PATCH 2/7] mention pip install --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 029006d4..ea6aa9aa 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ There are a couple ways to install dcm2niix - [MRIcroGL (NITRC)](https://www.nitrc.org/projects/mricrogl) or [MRIcroGL (GitHub)](https://github.com/rordenlab/MRIcroGL12/releases) includes dcm2niix that can be run from the command line or from the graphical user interface (select the Import menu item). The Linux version of dcm2niix is compiled on a [holy build box](https://github.com/phusion/holy-build-box), so it should run on any Linux distribution. - If you have a MacOS computer with Homebrew or MacPorts you can run `brew install dcm2niix` or `sudo port install dcm2niix`, respectively. - If you have Conda, [`conda install -c conda-forge dcm2niix`](https://anaconda.org/conda-forge/dcm2niix) on Linux, MacOS or Windows. + - If you have pip, `python -m pip install pydcm2niix` on Linux, MacOS or Windows. - On Debian Linux computers you can run `sudo apt-get install dcm2niix`. From 3f698b9c86428b600e715602b623b0dcfa873f47 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 15 Jan 2022 12:25:35 +0000 Subject: [PATCH 3/7] add executable --- dcm2niix/__init__.py | 10 +++++++++- dcm2niix/__main__.py | 3 +++ setup.cfg | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 dcm2niix/__main__.py diff --git a/dcm2niix/__init__.py b/dcm2niix/__init__.py index 6b32f89d..639f1f16 100644 --- a/dcm2niix/__init__.py +++ b/dcm2niix/__init__.py @@ -11,9 +11,17 @@ __version__ = get_version(root="../..", relative_to=__file__) except (ImportError, LookupError): __version__ = "UNKNOWN" -__all__ = ['bin', 'bin_path'] +__all__ = ['bin', 'bin_path', 'main'] from pathlib import Path bin_path = Path(__file__).resolve().parent / "dcm2niix" bin = str(bin_path) + + +def main(args=None): + if args is None: + import sys + args = sys.argv[1:] + from subprocess import run + run([bin] + args) diff --git a/dcm2niix/__main__.py b/dcm2niix/__main__.py new file mode 100644 index 00000000..8273c4ff --- /dev/null +++ b/dcm2niix/__main__.py @@ -0,0 +1,3 @@ +from . import main + +main() diff --git a/setup.cfg b/setup.cfg index d7c58507..f77086a1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,7 +19,6 @@ classifiers= Intended Audience :: Science/Research Operating System :: Microsoft :: Windows Operating System :: POSIX :: Linux - Programming Language :: C Programming Language :: C++ Programming Language :: Python :: 3 Programming Language :: Python :: 3.6 @@ -37,3 +36,6 @@ setup_requires= cmake>=3.18 ninja python_requires=>=3.6 +[options.entry_points] +console_scripts= + dcm2niix=dcm2niix:main From 747536036922c310e59498e3042628b3e5b2f726 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 9 May 2022 05:10:39 +0100 Subject: [PATCH 4/7] rename PyPI package - pydcm2niix => dcm2niix - thanks to https://github.com/pypa/pypi-support/issues/1609 - closes #573 --- README.md | 2 +- dcm2niix/__init__.py | 2 +- setup.cfg | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ea6aa9aa..2de7fb84 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ There are a couple ways to install dcm2niix - [MRIcroGL (NITRC)](https://www.nitrc.org/projects/mricrogl) or [MRIcroGL (GitHub)](https://github.com/rordenlab/MRIcroGL12/releases) includes dcm2niix that can be run from the command line or from the graphical user interface (select the Import menu item). The Linux version of dcm2niix is compiled on a [holy build box](https://github.com/phusion/holy-build-box), so it should run on any Linux distribution. - If you have a MacOS computer with Homebrew or MacPorts you can run `brew install dcm2niix` or `sudo port install dcm2niix`, respectively. - If you have Conda, [`conda install -c conda-forge dcm2niix`](https://anaconda.org/conda-forge/dcm2niix) on Linux, MacOS or Windows. - - If you have pip, `python -m pip install pydcm2niix` on Linux, MacOS or Windows. + - If you have pip, `python -m pip install dcm2niix` on Linux, MacOS or Windows. - On Debian Linux computers you can run `sudo apt-get install dcm2niix`. diff --git a/dcm2niix/__init__.py b/dcm2niix/__init__.py index 639f1f16..8a4127ab 100644 --- a/dcm2niix/__init__.py +++ b/dcm2niix/__init__.py @@ -1,5 +1,5 @@ """Thin wrapper around dcm2niix binary""" -__author__ = "Casper da Costa-Luis" +__author__ = "Casper da Costa-Luis " __date__ = "2022" # version detector. Precedence: installed dist, git, 'UNKNOWN' try: diff --git a/setup.cfg b/setup.cfg index f77086a1..785be9d2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name=pydcm2niix +name=dcm2niix description=DCM2NIIX Python package long_description=file: README.md long_description_content_type=text/markdown diff --git a/setup.py b/setup.py index 05552803..87754aff 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from skbuild import setup __version__ = get_version(root=".", relative_to=__file__) -build_ver = ".".join(__version__.split('.')[:3]).split(".dev")[0] +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=["dcm2niix"], From b91d6db0da6d3a314c14c6beaf7de51b4d46a78f Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 30 Jun 2022 09:18:54 +0100 Subject: [PATCH 5/7] fix typo --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 87754aff..72f2a7ac 100644 --- a/setup.py +++ b/setup.py @@ -11,4 +11,4 @@ i.write_text(re.sub("^//.*$\n^[^#].*pip-build-env.*$", "", i.read_text(), flags=re.M)) setup(use_scm_version=True, packages=["dcm2niix"], cmake_languages=("CXX",), cmake_minimum_required_version="3.18", - cmake_args=[f"-DCM2NIIX_BUILD_VERSION={build_ver}", "-DBUILD_ALL_DEP=ON"]) + cmake_args=[f"-DDCM2NIIX_BUILD_VERSION={build_ver}", "-DBUILD_ALL_DEP=ON"]) From 7ce50febd616f4ab70a4fdddc86f909b48c696f5 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 30 Jun 2022 09:19:26 +0100 Subject: [PATCH 6/7] remove unneeded BUILD_ALL_DEP --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 72f2a7ac..53e2e2e7 100644 --- a/setup.py +++ b/setup.py @@ -11,4 +11,4 @@ i.write_text(re.sub("^//.*$\n^[^#].*pip-build-env.*$", "", i.read_text(), flags=re.M)) setup(use_scm_version=True, packages=["dcm2niix"], cmake_languages=("CXX",), cmake_minimum_required_version="3.18", - cmake_args=[f"-DDCM2NIIX_BUILD_VERSION={build_ver}", "-DBUILD_ALL_DEP=ON"]) + cmake_args=[f"-DDCM2NIIX_BUILD_VERSION={build_ver}"]) From 26723410c977dd501cf57a9f244f9eccbcd86815 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 30 Jun 2022 09:19:51 +0100 Subject: [PATCH 7/7] remove unneeded DCM2NIIX_BUILD_VERSION --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 53e2e2e7..146f7a03 100644 --- a/setup.py +++ b/setup.py @@ -10,5 +10,4 @@ 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=["dcm2niix"], - cmake_languages=("CXX",), cmake_minimum_required_version="3.18", - cmake_args=[f"-DDCM2NIIX_BUILD_VERSION={build_ver}"]) + cmake_languages=("CXX",), cmake_minimum_required_version="3.18")