From a778abdb91abf053995a3c98eef6864399f03724 Mon Sep 17 00:00:00 2001 From: Spiros Maggioros Date: Thu, 31 Oct 2024 15:42:05 +0200 Subject: [PATCH] Fixed pre-commit and some arguments bugs --- DLICV/__main__.py | 35 +++++++++++++++-------------------- setup.py | 47 +++++++++++++++++++++-------------------------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/DLICV/__main__.py b/DLICV/__main__.py index 98bf391..3fcb061 100644 --- a/DLICV/__main__.py +++ b/DLICV/__main__.py @@ -1,9 +1,10 @@ import argparse import json import os -from pathlib import Path import shutil +import sys import warnings +from pathlib import Path import torch @@ -15,12 +16,13 @@ # VERSION = pkg_resources.require("NiChart_DLMUSE")[0].version VERSION = 1.0 + def main() -> None: - prog="DLICV" + prog = "DLICV" parser = argparse.ArgumentParser( prog=prog, description="DLICV - Deep Learning Intra Cranial Volume.", - usage = """ + usage=""" DLICV v{VERSION} ICV calculation for structural MRI data. @@ -36,18 +38,22 @@ def main() -> None: -o /path/to/output \ -device cpu|cuda|mps - """.format(VERSION=VERSION), + """.format( + VERSION=VERSION + ), ) # Required Arguments parser.add_argument( "-i", + "--in_dir", type=str, required=True, help="[REQUIRED] Input folder with T1 sMRI images (nii.gz).", ) parser.add_argument( "-o", + "out_dir", type=str, required=True, help="[REQUIRED] Output folder. If it does not exist it will be created. Predicted segmentations will have the same name as their source images.", @@ -200,14 +206,8 @@ def main() -> None: args.f = [0] if args.clear_cache: - shutil.rmtree(os.path.join( - Path(__file__).parent, - "nnunet_results" - )) - shutil.rmtree(os.path.join( - Path(__file__).parent, - ".cache" - )) + shutil.rmtree(os.path.join(Path(__file__).parent, "nnunet_results")) + shutil.rmtree(os.path.join(Path(__file__).parent, ".cache")) if not args.i or not args.o: print("Cache cleared and missing either -i / -o. Exiting.") sys.exit(0) @@ -240,14 +240,8 @@ def main() -> None: ) if args.clear_cache: - shutil.rmtree(os.path.join( - Path(__file__).parent, - "nnunet_results" - )) - shutil.rmtree(os.path.join( - Path(__file__).parent, - ".cache" - )) + shutil.rmtree(os.path.join(Path(__file__).parent, "nnunet_results")) + shutil.rmtree(os.path.join(Path(__file__).parent, ".cache")) # Check if model exists. If not exist, download using HuggingFace if not os.path.exists(model_folder): @@ -255,6 +249,7 @@ def main() -> None: print("DLICV model not found, downloading...") from huggingface_hub import snapshot_download + local_src = Path(__file__).parent snapshot_download(repo_id="nichart/DLICV", local_dir=local_src) print("DLICV model has been successfully downloaded!") diff --git a/setup.py b/setup.py index 2645e53..8ab2004 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,13 @@ """Setup tool for DLICV.""" -import io -import os from pathlib import Path + from setuptools import find_packages, setup this_directory = Path(__file__).parent long_description = (this_directory / "README.md").read_text() -with open('requirements.txt') as f: +with open("requirements.txt") as f: required = f.read().splitlines() setup( @@ -26,29 +25,25 @@ packages=find_packages(exclude=["tests", ".github"]), python_requires=">=3.8", install_requires=required, - entry_points={ - "console_scripts": ["DLICV = DLICV.__main__:main"] - }, + entry_points={"console_scripts": ["DLICV = DLICV.__main__:main"]}, classifiers=[ - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "Intended Audience :: Healthcare Industry", - "Programming Language :: Python :: 3", - "Topic :: Scientific/Engineering :: Artificial Intelligence", - "Topic :: Scientific/Engineering :: Image Processing", - "Topic :: Scientific/Engineering :: Medical Science Apps.", - ], + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Intended Audience :: Healthcare Industry", + "Programming Language :: Python :: 3", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Topic :: Scientific/Engineering :: Image Processing", + "Topic :: Scientific/Engineering :: Medical Science Apps.", + ], license="By installing/using DLICV, the user agrees to the following license: See https://www.med.upenn.edu/cbica/software-agreement-non-commercial.html", - keywords = [ - 'deep learning', - 'image segmentation', - 'semantic segmentation', - 'medical image analysis', - 'medical image segmentation', - 'nnU-Net', - 'nnunet' - ], - package_data={ - "DLICV": ["VERSION"] - }, + keywords=[ + "deep learning", + "image segmentation", + "semantic segmentation", + "medical image analysis", + "medical image segmentation", + "nnU-Net", + "nnunet", + ], + package_data={"DLICV": ["VERSION"]}, )