[build-system] requires = [ "setuptools>=78.1.1", "wheel", "versioneer[toml]", "more-itertools>=8.0", "ninja", "packaging", "torch>=2.12.1", "numpy>=1.24,<3.0", "backports.tarfile" # see https://github.com/Project-MONAI/MONAI/issues/8791 ] build-backend = "setuptools.build_meta" [project] name = "monai" description = "AI Toolkit for Healthcare Imaging" readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.11" license = "Apache-2.0" license-files = ["LICENSE"] authors = [{ name = "MONAI Consortium", email = "monai.contact@gmail.com" }] classifiers = [ "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: Science/Research", "Intended Audience :: Healthcare Industry", "Programming Language :: C++", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", "Programming Language :: Python :: 3.15", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Artificial Intelligence", "Topic :: Scientific/Engineering :: Medical Science Apps.", "Topic :: Scientific/Engineering :: Information Analysis", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Typing :: Typed", ] dependencies = [ "torch>=2.12.1", "numpy>=1.24,<3.0" ] dynamic = ["version"] [project.urls] Homepage = "https://project-monai.github.io/" Documentation = "https://monai.readthedocs.io/" "Bug Tracker" = "https://github.com/Project-MONAI/MONAI/issues" "Source Code" = "https://github.com/Project-MONAI/MONAI" [project.optional-dependencies] # All dependencies are included here except some omitted for compatibility. Testing dependencies are typically not # needed and so present only in "testing". Ensure requirement changes in other lists are reflected here as well. all=[ # nni is listed here rather than in all_python because it depends on nvidia-ml-py "monai[all_python,nni,pynvml,cucim]", # per #5882 these requirements must be on one line to get removed by sed in weekly-preview.yml "MetricsReloaded @ git+https://github.com/Project-MONAI/MetricsReloaded@monai-support", "segment_anything @ git+https://github.com/facebookresearch/segment-anything.git@6fdee8f2727f4506cfbbe553e23b895e27956588" ] # The counterpart of "all" for AMD ROCm, do not combine it with "all", "cucim" or "cupy": the AMD and NVIDIA packages # install the same cucim and cupy modules. See the ROCm section of docs/source/installation.md. all_amd=[ "monai[all_python,amd_cupy,hipcim]", # per #5882 these requirements must be on one line to get removed by sed in weekly-preview.yml "MetricsReloaded @ git+https://github.com/Project-MONAI/MetricsReloaded@monai-support", "segment_anything @ git+https://github.com/facebookresearch/segment-anything.git@6fdee8f2727f4506cfbbe553e23b895e27956588" ] # All dependencies which are not conditional on platform are here, included as MONAI optionals defined below this one. all_python=[ "monai[clearml,einops,fire,gdown,h5py,huggingface_hub,ignite,imagecodecs,itk,jsonschema,lmdb,matplotlib,mlflow]", "monai[nibabel,onnx,openslide,optuna,pandas,pandas,pillow,polygraphy,psutil,pyamg,pybind11,pydicom,pynrrd]", "monai[pyyaml,requests,scipy,skimage,tensorboard,tensorboardX,tifffile,torchio,torchvision,tqdm,transformers,zarr]" ] # AMD ROCm build of CuPy, from AMD's package index; the floor skips the 0.0.2 placeholder on PyPI amd_cupy = ["amd-cupy>=14.1.1; platform_system == 'Linux'"] clearml = ["clearml>=1.10.0rc0"] cucim = [ "cucim-cu12; platform_system == 'Linux' and python_version <= '3.10'", "cucim-cu13; platform_system == 'Linux' and python_version >= '3.11'" ] cupy = ["cupy-cuda13x!=14.1.0"] # not in all, the choice between cuda12x and cuda13x that can't be resolved here einops = ["einops"] fire = ["fire"] gdown = ["gdown>=4.7.3"] h5py = ["h5py"] # hipCIM, the AMD ROCm build of cuCIM, from AMD's package index; the floor skips the 0.0.2 placeholder on PyPI hipcim = ["amd-hipcim>=26.6.0; platform_system == 'Linux'"] huggingface_hub = ["huggingface_hub"] hyena = ["nvsubquadratic>=0.1.1", "omegaconf", "einops"] # omitted from all for compatibility ignite = ["pytorch-ignite"] imagecodecs = ["imagecodecs; platform_system == 'Linux' or platform_system == 'Darwin'"] itk = ["itk>=5.2"] jsonschema = ["jsonschema"] lmdb = ["lmdb"] lpips = ["torchvision"] # compatibility extra; LPIPS is implemented within MONAI matplotlib = ["matplotlib>=3.11.2"] # per #5882 this requirement must be on one line to get removed by sed in weekly-preview.yml metrics_reloaded = ["MetricsReloaded @ git+https://github.com/Project-MONAI/MetricsReloaded@monai-support"] mlflow = ["mlflow>=3.15.2"] nibabel = ["nibabel"] nni = [ "nni; platform_system == 'Linux' and 'arm' not in platform_machine and 'aarch' not in platform_machine", "filelock<3.12.0", # https://github.com/microsoft/nni/issues/5523 "typeguard<3" # https://github.com/microsoft/nni/issues/5457 ] # omitted from all: CUDA 13 Linux packages; CUDA 12 users should install matching cupy/nvimgcodec wheels # required for GPU accelerated decoding of compressed DICOM images nvimgcodec = [ "pydicom", # Tighter requirements than just the "cucim" optional dependency to get around a bug with cupy, also cucim>26.8 will # require Numpy 2.x. "cucim-cu13>=26.6.0; platform_system == 'Linux' and python_version >= '3.11'", "cupy-cuda13x[ctk]!=14.1.0; platform_system == 'Linux'", "nvidia-nvimgcodec-cu13[all]>=0.8.0; platform_system == 'Linux'" ] onnx = ["onnx>=1.13.0", "onnx_graphsurgeon", "onnxscript"] openslide = ["openslide-python", "openslide-bin"] optuna = ["optuna"] pandas = ["pandas"] pillow = ["pillow!=8.3.0"] # https://github.com/python-pillow/Pillow/issues/5571 polygraphy = ["polygraphy"] psutil = ["psutil"] pyamg = ["pyamg>=5.0.0,<5.3.0"] pybind11 = ["pybind11"] pydicom = ["pydicom"] pynrrd = ["pynrrd"] pynvml = ["nvidia-ml-py"] pyyaml = ["pyyaml"] requests = ["requests"] # per #5882 this requirement must be on one line to get removed by sed in weekly-preview.yml segment_anything = ["segment_anything @ git+https://github.com/facebookresearch/segment-anything.git@6fdee8f2727f4506cfbbe553e23b895e27956588"] scipy = ["scipy>=1.12.0"] skimage = ["scikit-image>=0.19.0"] tensorboard = ["tensorboard>=2.12.0"] # https://github.com/Project-MONAI/MONAI/issues/7434 tensorboardX = ["tensorboardX"] tifffile = ["tifffile; platform_system == 'Linux' or platform_system == 'Darwin'"] torchio = ["torchio"] torchvision = ["torchvision"] tqdm = ["tqdm>=4.47.0"] transformers = ["transformers>=5.5.0"] # 5.x needs the transchex BertLayer/BertConfig updates; re-verify the NGC image float8 concern zarr = ["zarr"] # these dependencies are for testing/building only, they aren't needed for regular use so don't appear in "all" testing = [ "black>=26.5.1", "coverage>=5.5", "isort>9.0.0", "mccabe", "packaging", "parameterized", "pep8-naming", "pre-commit", "pycodestyle", "pyflakes", "pyrefly>=1.0.0", "ruff>=0.16.5", "tomli", # used in print_dependencies.py for Python<3.11 "types-PyYAML", "types-setuptools" ] [tool.setuptools] # C++/CUDA sources under monai/csrc are compiled into monai._C; they are not Python packages or package data include-package-data = false [tool.setuptools.dynamic] version = {attr = "monai.__version__"} [tool.versioneer] VCS = "git" style = "pep440" versionfile_source = "monai/_version.py" versionfile_build = "monai/_version.py" tag_prefix = "" parentdir_prefix = "" [tool.isort] known_first_party = ["monai"] profile = "black" line_length = 120 skip = [".git", ".eggs", "venv", ".venv", "versioneer.py", "_version.py", "conf.py", "monai/__init__.py"] skip_glob = ["*.pyi"] add_imports = ["from __future__ import annotations"] append_only = true [tool.mypy] ignore_missing_imports = true no_implicit_optional = true warn_redundant_casts = true warn_unused_ignores = false warn_return_any = true strict_equality = true show_column_numbers = true show_error_codes = true pretty = false warn_unused_configs = true extra_checks = true exclude = ["venv/"] [[tool.mypy.overrides]] module = ["versioneer", "monai._version", "monai.eggs"] ignore_errors = true [[tool.mypy.overrides]] module = ["monai.*"] check_untyped_defs = true disallow_untyped_decorators = true [[tool.mypy.overrides]] module = [ "monai._extensions.*", "monai.apps.*", "monai.auto3dseg.*", "monai.bundle.*", "monai.config.*", "monai.engines.*", "monai.fl.*", "monai.handlers.*", "monai.inferers.*", "monai.losses.*", "monai.metrics.*", "monai.optimizers.*", "monai.utils.*", "monai.visualize.*" ] disallow_incomplete_defs = true [tool.coverage.run] concurrency = ["multiprocessing"] source = ["."] data_file = ".coverage/.coverage" omit = ["setup.py"] [tool.coverage.report] exclude_lines = [ "pragma: no cover", "if TYPE_CHECKING:", "raise NotImplementedError", "if __name__ == .__main__.:", ] show_missing = true skip_covered = true [tool.coverage.xml] output = "coverage.xml" [tool.black] line-length = 120 target-version = ['py310'] skip-magic-trailing-comma = true include = '\.pyi?$' exclude = ''' ( /( # exclude a few common directories in the root of the project \.eggs | \.git | \.hg | \.tox | \.venv | \.mypy_cache | \.pytype | venv | _build | buck-out | build | dist )/ # also separately exclude a file named versioneer.py | versioneer.py | monai/_version.py ) ''' [tool.ruff] line-length = 120 target-version = "py310" # .pre-commit-config.yaml's ruff hook excludes these separately at the pre-commit layer extend-exclude = ["versioneer.py", "monai/_version.py"] [tool.ruff.lint] select = [ "B", # flake8-bugbear - https://docs.astral.sh/ruff/rules/#flake8-bugbear-b "C90", # mccabe (complexity) - https://docs.astral.sh/ruff/rules/#mccabe-c90 "E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e "F", # pyflakes - https://docs.astral.sh/ruff/rules/#pyflakes-f "N", # pep8-naming - https://docs.astral.sh/ruff/rules/#pep8-naming-n "PIE", # flake8-pie - https://docs.astral.sh/ruff/rules/#flake8-pie-pie "TID", # flake8-tidy-imports - https://docs.astral.sh/ruff/rules/#flake8-tidy-imports-tid "W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w "NPY", # NumPy specific rules - https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy "UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up "RUF100", # aka yesqa - https://docs.astral.sh/ruff/rules/unused-noqa/ "F401", # unused imports - https://docs.astral.sh/ruff/rules/unused-import/ ] extend-ignore = [ "E741", # ambiguous variable name "NPY002", # numpy-legacy-random "E203", # whitespace before ':' (pycodestyle) "E501", # line too long (pycodestyle) "C408", # unnecessary collection call (flake8-comprehensions) "N812", # lowercase imported as non lowercase (pep8-naming) "B023", # function uses loop variable (flake8-bugbear) "B905", # zip() without an explicit strict= parameter (flake8-bugbear) "B028", # no explicit stacklevel keyword argument found (flake8-bugbear) ] [tool.ruff.lint.per-file-ignores] "tests/**" = [ "B018", "C901", "N999", "N801" ] "monai/apps/detection/utils/ATSS_matcher.py" = [ "N999" ] "__init__.py" = ["F401"] # TODO: change importation in __init__.py files to suit F401 "monai/bundle/__main__.py" = ["F401"] [tool.ruff.lint.mccabe] max-complexity = 50 # todo lower this treshold when yesqa id replaced with Ruff's RUF100 [tool.pytest.ini_options] pythonpath = ["."] [tool.pytype] # Space-separated list of files or directories to exclude. exclude = ["versioneer.py", "_version.py"] # Space-separated list of files or directories to process. inputs = ["monai"] # Keep going past errors to analyze as many files as possible. keep_going = true # Run N jobs in parallel. jobs = 8 # All pytype output goes here. output = ".pytype" # Paths to source code directories, separated by ':'. pythonpath = "." # Check attribute values against their annotations. check_attribute_types = true # Check container mutations against their annotations. check_container_types = true # Check parameter defaults and assignments against their annotations. check_parameter_types = true # Check variable values against their annotations. check_variable_types = true # Comma or space separated list of error names to ignore. disable = ["pyi-error"] # Report errors. report_errors = true # Experimental: Infer precise return types even for invalid function calls. precise_return = true # Experimental: solve unknown types to label with structural types. protocols = true # Experimental: Only load submodules that are explicitly imported. strict_import = false [tool.pyrefly] # Check only the monai package project-includes = ["monai/"] # Exclude auto-generated and vendored files project-excludes = [ "**/venv/**", "**/.venv/**", "versioneer.py", "monai/_version.py", ] # Match CI environment python-version = "3.11" python-platform = "linux" # "legacy" preset provides a smooth migration from previous type checkers preset = "legacy" # Check unannotated defs (previously enforced in mypy config) check-unannotated-defs = true [tool.pyrefly.errors] # Ignore missing imports missing-import = "ignore" # Suppress unused-ignore warnings unused-ignore = "ignore" # Suppress implicit-import globally (MONAI style uses lazy imports) implicit-import = "ignore" # Downgrade errors in unannotated/dynamic code to warnings # (pre-existing issues, not new — will fix incrementally) bad-assignment = "warn" bad-return = "warn" bad-argument-type = "warn" invalid-annotation = "ignore" not-iterable = "warn" not-callable = "warn" bad-index = "warn" # Pre-existing errors not flagged by previous type checkers # Suppress for a smooth migration; fix incrementally missing-attribute = "ignore" bad-override = "ignore" no-matching-overload = "ignore" unsupported-operation = "ignore" unnecessary-type-conversion = "ignore" missing-module-attribute = "ignore" not-a-type = "ignore" invalid-yield = "ignore" deprecated = "ignore"