[build-system] build-backend = "hatchling.build" requires = ["hatchling", "hatch-vcs", "setuptools-scm!=9.0.0"] [dependency-groups] # A combination of dependencies useful for developers dev = [ {include-group = "test"}, {include-group = "doc"}, {include-group = "style"}, {include-group = "rich"}, "tox>=4", "tox-uv" ] # Requirements necessary for building the documentation doc = [ "docutils>=0.17", "furo>=2024.8.6", "jupyterlite-pyodide-kernel>=0.7.2", "jupyterlite-sphinx>=0.22.1", "marimo>=0.12.0", "memory_profiler>=0.61", # measuring memory during docs building "myst-parser>=3.0.1", "numpydoc>=1.8.0", "ruamel.yaml>=0.18.6", "sphinx>=7.4.7", "sphinx-copybutton>=0.5.2", "sphinx-design>=0.6.1", "sphinxcontrib-mermaid>=1.0.0", "sphinx-gallery>=0.18.0", "sphinxcontrib-bibtex>=2.6.3", "sphinxext-opengraph>=0.9.1", "templateflow>=25.0.0", "pyarrow>=13.0.0" # mostly to avoid some warnings in pandas ] min = [ "joblib==1.2.0", "nibabel==5.2.0", "numpy==1.26.0", "pandas==2.3.0", "requests==2.33.0", # scikit-learn version 1.7.0 has a bug that prevents _repr_html_ to run # correctly # https://scikit-learn.org/stable/whats_new/v1.7.html#sklearn-base "scikit-learn==1.5.0,!=1.7.0", "scipy==1.11.1", "jinja2==3.1.6" ] min_plotting = [ {include-group = "min"}, "kaleido==1.1.0", "matplotlib==3.8.0", "plotly==6.1.1" ] # For prettier printing rich = ["rich>=12.0.0"] # Applying style guide style = ['prek'] test = [ {include-group = "test_common"}, "coverage>=7.0.0", "lxml>=6.0.0", "pytest-cov>=7.0.0", "pytest-timeout>=2.4.0", "pytest-xdist[psutil]>=3.8" ] # For running unit and docstring tests test_common = [ "numpydoc>=1.8.0", "polars>=1.0.0", "pytest>=6.0.0", "pytest-csv>=3.0.0", "pytest-randomly>=4.0.0", "pytest-reporter-html1>=0.9.2,<0.9.4", "pytest-rerunfailures>=16.1", "pyarrow>=13.0.0" # mostly to avoid some warnings in pandas ] # Running test for free threaded python # requires fewer extensions test_free_threaded = [ {include-group = "test_common"}, "pytest-run-parallel>=0.8.2" ] # For running baseline image comparison tests (requires matplotlib) test_mpl = ["pytest-mpl>=0.18.0"] [project] authors = [{name = "Nilearn developers"}] classifiers = [ "Intended Audience :: Science/Research", "Intended Audience :: Developers", "Programming Language :: C", "Programming Language :: Python", "Topic :: Software Development", "Topic :: Scientific/Engineering", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Operating System :: Unix", "Operating System :: MacOS", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14" ] dependencies = [ "joblib>=1.2.0", "nibabel>=5.2.0", "numpy>=1.26.0", "pandas>=2.3.0", "requests>=2.33.0", # sklearn 1.7.0 has a bug that prevents _repr_html_ to run correctly # https://scikit-learn.org/stable/whats_new/v1.7.html#sklearn-base # sklearn 1.9.0 creates sluggish HTML representation of estimators with many features # https://github.com/scikit-learn/scikit-learn/issues/34203 "scikit-learn>=1.5.0,!=1.7.0,!=1.9.0", "jinja2>=3.1.6", "scipy>=1.11.1", "packaging>=26.0.0" ] description = "Statistical learning for neuroimaging in Python" # Version from setuptools_scm dynamic = ["version"] license = "BSD-3-Clause" license-files = ["LICENSE"] maintainers = [ {name = "Bertrand Thirion", email = "bertrand.thirion@inria.fr"} ] name = "nilearn" readme = "README.rst" requires-python = ">=3.10" [project.optional-dependencies] # keep plotly as a separate optional extra dependency because of its size plotly = [ "kaleido>=1.1.0", "plotly>=6.1.1" ] plotting = [ "matplotlib>=3.8.0" ] [project.urls] Changelog = "https://nilearn.github.io/stable/changes/whats_new.html" Development = "https://github.com/nilearn/nilearn" Discussions = "https://neurostars.org/tag/nilearn/19" Homepage = "https://nilearn.github.io" [tool.codespell] builtin = "clear,rare,en-GB_to_en-US" ignore-words = ".github/codespell_ignore_words.txt" skip = "./.git,*.cff,*.bib,*/tmp,*.min.js,*.umd.js,localizer_behavioural.tsv,.mypy_cache,env,venv,./doc/auto_examples,./doc/modules/generated/*,./doc/_build,./maint_tools/*.html,./examples/*/results,AUTHORS.rst" [tool.djlint] blank_line_after_tag = "load,extends,include,endblock,set" blank_line_before_tag = "load,extends,include,block,set" format_css = true ignore = "H030,H031,H021,H006" max_line_length = 79 use_gitignore = true [tool.djlint.css] indent_size = 5 [tool.djlint.per-file-ignores] "doc/ci.jinja" = "H025" [tool.doc8] allow-long-titles = true ignore-path = [ "*/changes/*.rst", "*/modules/generated/*", "*/modules/generated_reports/*", "*/templates/*.rst", "doc/authors.rst", "doc/includes/*", "doc/modules/datasets.rst", # to ignore mystparser error "AUTHORS.rst" ] max-line-length = 120 [tool.hatch.build.hooks.vcs] version-file = "nilearn/_version.py" [tool.hatch.build.targets.wheel] exclude = [ "nilearn/plotting/tests/baseline", "nilearn/maskers/tests/baseline", "nilearn/glm/tests/baseline" ] packages = ["nilearn"] [tool.hatch.version] source = "vcs" [tool.importlinter] root_package = "nilearn" [[tool.importlinter.contracts]] ignore_imports = [ "nilearn.*.tests.* -> nilearn._utils.estimator_checks", # allowed in tests "nilearn._utils.estimator_checks -> nilearn.glm.*", # allowed in tests "nilearn.plotting.matrix.tests.* -> nilearn.glm.**", # allowed in tests "nilearn.plotting.tests.* -> nilearn.glm.**", # allowed in tests "nilearn.plotting.tests.* -> nilearn._utils.data_gen", # allowed in tests "nilearn.plotting.matrix.* -> nilearn.glm.**", "nilearn.interfaces.bids.glm -> nilearn.glm.io", # TODO: (nilearn >= 0.15.0) remove "nilearn.interfaces.bids.glm -> nilearn.glm.first_level", # TODO: (nilearn >= 0.15.0) remove "nilearn.interfaces.bids.glm -> nilearn.glm.second_level", # TODO: (nilearn >= 0.15.0) remove "nilearn.interfaces.tests.test_glm -> nilearn.glm.first_level" # TODO: (nilearn >= 0.15.0) remove ] # ** utils: # - can import from any lower layers # ** glm, decoding, connectome, decomposition: # - cannot import from each other # - but can import from any lower layers # ** mass_univariate: # - can import from any lower layers # ** maskers, image, surface, plotting, masking, datasets, reporting, interfaces: # - can import from each other # - can import from any lower layers # ** signal: # - can import from any lower layers # TODO: not yet included are regions layers = [ "nilearn.utils", "nilearn.glm | nilearn.decoding | nilearn.connectome | nilearn.decomposition", "nilearn.mass_univariate", "nilearn.maskers : nilearn.image : nilearn.surface : nilearn.plotting : nilearn.masking : nilearn.reporting : nilearn.datasets : nilearn.interfaces", "nilearn.signal", "nilearn._base", "nilearn.nilearn_typing | nilearn.exceptions | nilearn._utils.versions" ] name = "main architecture" type = "layers" [[tool.importlinter.contracts]] ignore_imports = [ "nilearn.*.tests.* -> nilearn._utils.estimator_checks", # allowed in tests "nilearn._utils.estimator_checks -> nilearn.glm.*", # allowed in tests "nilearn.plotting.matrix.tests.* -> nilearn.glm.**", # allowed in tests "nilearn.plotting.tests.* -> nilearn.glm.**", # allowed in tests "nilearn.plotting.tests.* -> nilearn._utils.data_gen", # allowed in tests "nilearn.plotting.matrix.* -> nilearn.glm.**", "nilearn.interfaces.bids.glm -> nilearn.glm.io", # TODO: (nilearn >= 0.15.0) remove "nilearn.interfaces.bids.glm -> nilearn.glm.first_level", # TODO: (nilearn >= 0.15.0) remove "nilearn.interfaces.bids.glm -> nilearn.glm.second_level", # TODO: (nilearn >= 0.15.0) remove "nilearn.interfaces.tests.test_glm -> nilearn.glm.first_level", # TODO: (nilearn >= 0.15.0) remove # additional on top of those of "main architecture" "nilearn.plotting.tests.test_img_comparisons -> nilearn._utils.data_gen", # allowed in tests "nilearn.plotting.tests.test_img_comparisons -> nilearn.maskers", # allowed in tests # TODO "nilearn.plotting.image.img_plotting -> nilearn.maskers", "nilearn.plotting.img_comparison -> nilearn._utils.masker_validation", "nilearn.plotting.img_comparison -> nilearn.maskers", "nilearn.image.image -> nilearn._utils.masker_validation" ] layers = [ "nilearn.glm", "nilearn.maskers", "nilearn.reporting", "nilearn.plotting" ] name = "reporting" type = "layers" [[tool.importlinter.contracts]] forbidden_modules = [ "nilearn.mass_univariate", "nilearn.reporting", "nilearn.plotting", "nilearn.maskers", "nilearn.image", "nilearn.surface", "nilearn.masking", "nilearn.datasets" ] ignore_imports = [ "nilearn.connectome.tests.* -> nilearn._utils.estimator_checks", "nilearn.connectome.tests.test_connectivity_matrices -> nilearn.tests.test_signal", "nilearn.connectome.tests.test_group_sparse_cov -> nilearn._utils.data_gen" ] name = "'nilearn.connectome' only imports from 'nilearn.signal'" source_modules = ["nilearn.connectome"] type = "forbidden" [[tool.importlinter.contracts]] forbidden_modules = [ "nilearn._utils.data_gen" ] name = "fixtures from 'nilearn.conftest' should not rely on data generated in 'nilearn._utils.data_gen'" source_modules = [ "nilearn.conftest" ] type = "forbidden" [[tool.importlinter.contracts]] allowed_importers = ["nilearn.glm"] name = "only 'nilearn.glm' imports from 'nilearn.mass_univariate'" protected_modules = ["nilearn.mass_univariate"] type = 'protected' [[tool.importlinter.contracts]] allowed_importers = [ "nilearn.reporting", "nilearn.plotting", "nilearn.glm" # TODO try to avoid ] name = "assets only imported by reporting, plotting, glm" protected_modules = [ "nilearn._assets" ] type = "protected" [tool.mypy] allow_redefinition = false enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] exclude = [ 'nilearn_cache/.*', 'nilearn/_version.py' ] warn_unreachable = true [[tool.mypy.overrides]] ignore_errors = true module = ["nilearn._version"] [[tool.mypy.overrides]] ignore_missing_imports = true module = [ "IPython.*", "jinja2.*", "joblib.*", "kaleido", "matplotlib.*", "memory_profiler.*", "mpl_toolkits.*", "marimo.*", "nibabel.*", "nilearn._version", "numpydoc.*", "packaging.*", "plotly.*", "polars.*", "pytest.*", "rich.*", "scipy.*", "sklearn.*", "statsmodels.*", "svg.*" ] [tool.pytest.ini_options] # We do not run doctests systematically with "--doctest-modules". # This is because some doctests outside of nilearn.plotting require matplotlib # and would lead to import errors when run without the plotting dependencies. addopts = "-ra --strict-config --strict-markers --showlocals --capture=no -v --template=maint_tools/templates/index.html" doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS" # see https://docs.pytest.org/en/stable/how-to/capture-warnings.html#controlling-warnings filterwarnings = [ # ignoring warnings about using a non-interactive plotting backend 'ignore:.*you are using the.*:UserWarning' ] junit_family = "xunit2" log_cli_level = "INFO" log_level = "INFO" markers = [ "slow", # for tests that exceed the timeout allowed for each test "single_process", # for test that require testing n_jobs>1 or that are flaky when used xdist testing parallelization "thread_unsafe", # used by pytest-run-parallel: adding it here to avoid warning and not always install the extension "ai_generated", # used by AI agents to flag tests they generate or modify "engines", # used to specify engines for a test to be selected from available ones "mpl_image_compare" # registered here so --strict-markers works without pytest-mpl installed ] minversion = "6.0" testpaths = ["nilearn"] xfail_strict = true [tool.ruff] extend-exclude = ["doc/auto_examples/*", "nilearn/_version.py"] include = [ "pyproject.toml", "nilearn/**/*.py", "examples/**/*.py", "maint_tools/**/*.py", "doc/**/*.py" ] indent-width = 4 line-length = 79 [tool.ruff.format] docstring-code-format = true docstring-code-line-length = "dynamic" indent-style = "space" line-ending = "auto" quote-style = "double" skip-magic-trailing-comma = false [tool.ruff.lint] dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" fixable = ["ALL"] ignore = [ "ARG005", "D105", "D205", "D301", "E741", "ERA001", "N803", "N806", "PERF203", "PLR2004", "PTH207", # Avoid linter rules conflicting with the formatter # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules "COM812", "COM819", "E111", "E114", "E117", "Q000", "Q001", "Q002", "Q003", "W191" ] # List of all the ruff rules (includes why the rule matters) # https://docs.astral.sh/ruff/rules/ select = [ "ARG", "B", "C4", "C90", "D", "E", "ERA", "F", "FLY", "FURB", "I", "N", "NPY", "PERF", "PIE", "PTH", "PD", "PGH", "PLR", "RUF", "SIM", "TID", "UP", "W" ] unfixable = [] [tool.ruff.lint.mccabe] max-complexity = 23 [tool.ruff.lint.per-file-ignores] "**/{asv_benchmarks}/*" = ["TID"] "**/{doc}/*" = ["B018", "D103"] # 17 D103 errors to fix "**/{examples}/*" = ["B018", "D103", "D400", "E402"] # 13 D103 errors to fix "__init__.py" = ["D104", "E402"] "doc/conf.py" = ["I001"] # ignore sorting because this leads to conflict when running prek locally and in CI "nilearn/**/tests/test_*" = ["D100"] "nilearn/connectome/tests/test_connectivity_matrices.py" = ["D103"] # 30 errors to fix "nilearn/datasets/func.py" = ["PTH211"] # 1 error "nilearn/datasets/tests/conftest.py" = ["D102"] "nilearn/datasets/tests/test_atlas.py" = ["D103"] # 24 errors to fix "nilearn/datasets/tests/test_func.py" = ["D103"] # 37 errors to fix "nilearn/decoding/tests/test_decoder.py" = ["D103"] # 26 errors to fix "nilearn/glm/tests/test_contrasts.py" = ["D103"] # 17 errors to fix "nilearn/glm/tests/test_design_matrix.py" = ["D103"] # 22 errors to fix "nilearn/glm/tests/test_second_level.py" = ["D103"] # 17 errors to fix "nilearn/image/tests/test_image.py" = ["D103"] # 37 errors to fix "nilearn/image/tests/test_resampling.py" = ["D103"] # 29 errors to fix "nilearn/regions/tests/test_parcellations.py" = ["D103"] # 15 errors to fix "nilearn/regions/tests/test_region_extractor.py" = ["D103"] # 20 errors to fix "nilearn/regions/tests/test_signal_extraction.py" = ["D103"] # 20 errors to fix "nilearn/surface/tests/test_surface.py" = ["D103"] # 44 errors to fix [tool.ruff.lint.pydocstyle] convention = "numpy" [tool.ruff.lint.pylint] # https://docs.astral.sh/ruff/settings/#lint_pylint_max-args max-args = 27 # https://docs.astral.sh/ruff/settings/#lint_pylint_max-branches max-branches = 22 # https://docs.astral.sh/ruff/settings/#lint_pylint_max-returns max-returns = 8 # https://docs.astral.sh/ruff/settings/#lint_pylint_max-statements max-statements = 110