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

Python package #654

Merged
merged 7 commits into from
Nov 24, 2022
Merged
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 dcm2niix` on Linux, MacOS or Windows.
- On Debian Linux computers you can run `sudo apt-get install dcm2niix`.


Expand Down
4 changes: 4 additions & 0 deletions SuperBuild/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 27 additions & 0 deletions dcm2niix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Thin wrapper around dcm2niix binary"""
__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', '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)
3 changes: 3 additions & 0 deletions dcm2niix/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import main

main()
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 = "dcm2niix/_dist_ver.py"
write_to_template = "__version__ = '{version}'\n"
41 changes: 41 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[metadata]
name=dcm2niix
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
[email protected]
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 :: 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=
dcm2niix=dcm2niix:main
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""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")