code: def _check_nb_files_derivatives_for_task(
      bids_path,
      n_sub,
      n_ses,
      task,
      n_run,
      extra_entity=None,
  ):
      """Check number of each file 'type' in derivatives for a given task."""
      for suffix in ["timeseries.tsv"]:
          # 1 confound per raw file
          # so we do not use the extra entity for derivatives entities like res
          if extra_entity is None or "res" in extra_entity:
              file_pattern = _bids_path_template(
                  task=task,
                  suffix=suffix,
                  n_runs=n_run,
                  extra_entity=None,
              )
          elif "acq" in extra_entity:
              file_pattern = _bids_path_template(
                  task=task,
                  suffix=suffix,
                  n_runs=n_run,
                  extra_entity=extra_entity,
              )
  
          files = list(bids_path.glob(f"derivatives/{file_pattern}"))
          assert len(files) == n_sub * n_ses * n_run
  
      for space in ["MNI", "T1w"]:
          file_pattern = _bids_path_template(
              task=task,
              suffix="bold.nii.gz",
              n_runs=n_run,
              space=space,
              desc="preproc",
              extra_entity=extra_entity,
          )
          files = list(bids_path.glob(f"derivatives/{file_pattern}"))
          assert len(files) == n_sub * n_ses * n_run
  
      # only T1w have desc-fmriprep_bold
      file_pattern = _bids_path_template(
          task=task,
          suffix="bold.nii.gz",
          n_runs=n_run,
          space="T1w",
          desc="fmriprep",
          extra_entity=extra_entity,
      )
      files = list(bids_path.glob(f"derivatives/{file_pattern}"))
      assert len(files) == n_sub * n_ses * n_run
  
      file_pattern = _bids_path_template(
          task=task,
          suffix="bold.nii.gz",
          n_runs=n_run,
          space="MNI",
          desc="fmriprep",
          extra_entity=extra_entity,
      )
      files = list(bids_path.glob(f"derivatives/{file_pattern}"))
      assert not files
  
imports: from __future__ import annotations
  import json
  import numpy
  import pytest
  from nilearn._utils.data_gen import add_metadata_to_bids_dataset, create_fake_bids_dataset, generate_fake_fmri, generate_labeled_regions, generate_maps, generate_regions_ts
  from nilearn.image import get_data
label_desc: Use image node_id 5 for calling a global function with example usage: _check_nb_files_derivatives_for_task(bids_path, n_sub, n_ses, task, n_run, extra_entity) without return types