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

move script to entrypoint #131

Open
wants to merge 8 commits 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
11 changes: 2 additions & 9 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ jobs:
CIBW_SKIP: "pp* cp36-* cp37-* *musllinux* cp38-macosx_arm64"
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: pytest --pyargs nlsam --verbose
CIBW_TEST_COMMAND_LINUX: >
pytest --pyargs nlsam --verbose &&
cd {package}/example &&
chmod +x {package}/nlsam/tests/test_scripts1.sh &&
bash {package}/nlsam/tests/test_scripts1.sh &&
chmod +x {package}/nlsam/tests/test_scripts2.sh &&
bash {package}/nlsam/tests/test_scripts2.sh

- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -85,9 +78,9 @@ jobs:
path=$(python -c "import distributed; print(distributed.__path__[0]);")
echo "version=v$(python -c "from importlib.metadata import version; print(version('nlsam'));")" >> $GITHUB_ENV
if [ "$RUNNER_OS" == "Windows" ]; then
pyinstaller ./scripts/nlsam_denoising -F --clean --add-data "${path};.\\distributed\\" --noupx
pyinstaller ./nlsam/scripts.py -n nlsam_denoising -F --clean --add-data "${path};.\\distributed\\" --noupx
else
pyinstaller ./scripts/nlsam_denoising -F --clean --add-data ${path}:./distributed/ --noupx
pyinstaller ./nlsam/scripts.py -n nlsam_denoising -F --clean --add-data ${path}:./distributed/ --noupx
fi

- uses: actions/upload-artifact@v4
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ target/

nlsam.zip
*.code-workspace
log
*.nii
*.nii.gz
wheelhouse/*
2 changes: 0 additions & 2 deletions scripts/nlsam_denoising → nlsam/scripts.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

import os
import argparse
import logging
Expand Down
42 changes: 42 additions & 0 deletions nlsam/tests/test_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import subprocess
import pytest

from pathlib import Path

cwd = Path(__file__).parents[2] / Path("example")
commands_crop = [
'''python -c "import nibabel as nib; import numpy as np; d = nib.load('dwi.nii.gz').get_fdata(); nib.save(nib.Nifti1Image(d[40:50, 80:85],np.eye(4)), 'dwi_crop.nii.gz')"''',
'''python -c "import nibabel as nib; import numpy as np; d = nib.load('mask.nii.gz').get_fdata(); nib.save(nib.Nifti1Image(d[40:50, 80:85],np.eye(4)), 'mask_crop.nii.gz')"''',
'''python -c "import nibabel as nib; import numpy as np; d = nib.load('mask.nii.gz').get_fdata(); nib.save(nib.Nifti1Image(np.random.rayleigh(10, d[40:50, 80:85].shape),np.eye(4)), 'noise.nii.gz')"''',
]

commands_nlsam = [
# Test on example dataset
'nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -f -N 1 --noise_est local_std --sh_order 0 --log log --cores 1 -m mask_crop.nii.gz',
'nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f -N 1 --noise_est local_std --sh_order 6 --iterations 5 --verbose --save_sigma sigma.nii.gz',
'nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --noise_est auto --sh_order 6 --iterations 5 --verbose --save_sigma sigma.nii.gz --save_N N.nii.gz',
'nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose --sh_order 0 --b0_threshold 10 --noise_mask pmask.nii.gz',
# Test on niftis
"gunzip dwi_crop.nii.gz mask_crop.nii.gz sigma.nii.gz"
"nlsam_denoising dwi_crop.nii dwi_nlsam.nii bvals bvecs -m mask_crop.nii -f --verbose --sh_order 0 -N 1 --no_stabilization --load_sigma sigma.nii --is_symmetric --use_threading --save_difference diff.nii",
"nlsam_denoising dwi_crop.nii dwi_nlsam.nii bvals bvecs -m mask_crop.nii -f --verbose --sh_order 0 --no_denoising --save_sigma sigma.nii --save_stab stab.nii --load_mhat dwi_crop.nii --save_eta eta.nii",
# Test on example dataset
"nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose -N 1 --noise_est local_std --sh_order 0 --block_size 2,2,2 --save_sigma sigma.nii.gz --cores 1",
"nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose --sh_order 0 -N 1 --load_sigma sigma.nii.gz --no_subsample --fix_implausible --no_clip_eta",
"nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose --sh_order 0 --noise_map noise.nii.gz --noise_mask pmask.nii.gz --use_f32",
"nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose --sh_order 0 -N 1 --load_sigma sigma.nii.gz --no_stabilization --no_denoising",
"nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose --sh_order 0 -N 1 --load_sigma sigma.nii.gz --no_denoising --no_clip_eta",
"nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose --sh_order 0 -N 1 --noise_est local_std --no_denoising",
"nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose --sh_order 0 --noise_est auto --no_denoising --cores 4",
"nlsam_denoising dwi_crop.nii.gz dwi_nlsam.nii.gz bvals bvecs -m mask_crop.nii.gz -f --verbose --sh_order 0 --no_denoising",
]


@pytest.mark.parametrize("command", commands_crop)
def test_crop(command):
subprocess.run([command], shell=True, cwd=cwd, check=True)


@pytest.mark.parametrize("command", commands_nlsam)
def test_script_nlsam(command):
subprocess.run([command], shell=True, cwd=cwd, check=True)
36 changes: 0 additions & 36 deletions nlsam/tests/test_scripts1.sh

This file was deleted.

39 changes: 0 additions & 39 deletions nlsam/tests/test_scripts2.sh

This file was deleted.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
requires = ["Cython>=0.29.33",
"scipy>=1.5",
"oldest-supported-numpy",
"setuptools",
"setuptools>=60",
"wheel"]
build-backend = "setuptools.build_meta"


[project]
name = "nlsam"
version = '0.7.1'
Expand All @@ -32,3 +31,7 @@ dependencies = [
homepage = "https://github.com/samuelstjean/nlsam"
documentation = "https://nlsam.readthedocs.io/en/latest/"
changelog = "https://github.com/samuelstjean/nlsam/blob/master/CHANGELOG.md"


[project.scripts]
nlsam_denoising = "nlsam.scripts:main"
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

ext_modules = cythonize("nlsam/*.pyx")
include_dirs = [numpy.get_include()]
scripts = ['scripts/nlsam_denoising']

setup(
scripts=scripts,
packages=find_packages(),
include_dirs=include_dirs,
packages=find_packages(),
ext_modules=ext_modules)
Loading