We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`ValueError: n_jobs must be an integer` when calling freesurfer
Hi,

When I run `python run.py freesurfer --config=~/hMT+/config.py`, I get the following error traceback:

```
Traceback (most recent call last):
  File "/home/merlin/PhD/mne-bids-pipeline/run.py", line 194, in <module>
    fire.Fire(process)
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/merlin/PhD/mne-bids-pipeline/run.py", line 189, in process
    _run_script(script_path, config, root_dir, subject, session, task, run)
  File "/home/merlin/PhD/mne-bids-pipeline/run.py", line 98, in _run_script
    runpy.run_path(script_path, run_name='__main__')
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/merlin/PhD/mne-bids-pipeline/scripts/freesurfer/recon_all.py", line 112, in <module>
    fire.Fire(main)
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/merlin/PhD/mne-bids-pipeline/scripts/freesurfer/recon_all.py", line 94, in main
    parallel, run_func, _ = parallel_func(run_recon, n_jobs=n_jobs)
  File "<decorator-gen-42>", line 24, in parallel_func
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/mne/parallel.py", line 112, in parallel_func
    n_jobs = check_n_jobs(n_jobs)
  File "/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/mne/parallel.py", line 159, in check_n_jobs
    raise ValueError('n_jobs must be an integer')
ValueError: n_jobs must be an integer
```

Checking with pdb, it seems that `recon_all` is called with `n_jobs = "freesurfer"`. I'm not sure why that is.

```
19:36:39 Using custom configuration: /home/merlin/hMT+/config.py
19:36:39 [Step-01] Running: Initializing output directories.
19:36:39 [Step-01] Initializing output directories.
19:36:39 [Step-01] Completed: Initializing output directories.
2021-04-14 19:36:39 INFO Successfully finished running: init_derivatives_dir
2021-04-14 19:36:39 INFO Now running: on_all
> /home/merlin/PhD/mne-bids-pipeline/scripts/freesurfer/recon_all.py(88)main()
     87 
---> 88     logger.info('Running FreeSurfer')
     89 

ipdb> n_jobs
'freesurfer'
ipdb>                                                                                                                                       
```

It might be the config needs to be changed, but I can't figure out how.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scripts/freesurfer/recon_all.py`
Content:
```
1 #!/usr/bin/env python
2 
3 import os
4 import shutil
5 import sys
6 from pathlib import Path
7 import logging
8 from typing import Union
9 
10 import fire
11 
12 from mne.utils import run_subprocess
13 from mne.parallel import parallel_func
14 
15 import config
16 
17 PathLike = Union[str, Path]
18 logger = logging.getLogger('mne-bids-pipeline')
19 fs_bids_app = Path(__file__).parent / 'contrib' / 'run.py'
20 
21 
22 def _get_subjects_dir(root_dir) -> Path:
23     subjects_dir = \
24         Path(root_dir) / "derivatives" / "freesurfer" / "subjects"
25     return subjects_dir
26 
27 
28 def run_recon(root_dir, subject, fs_bids_app) -> None:
29     logger.info(f"Running recon-all on subject {subject}. This will take "
30                 f"a LONG time – it's a good idea to let it run over night.")
31 
32     subjects_dir = _get_subjects_dir(root_dir)
33     subj_dir = subjects_dir / f"sub-{subject}"
34 
35     if subj_dir.exists():
36         logger.info(f"Subject {subject} is already present. Please delete the "
37                     f"directory if you want to recompute.")
38         return
39 
40     env = os.environ
41     if 'FREESURFER_HOME' not in env:
42         raise RuntimeError("FreeSurfer is not available.")
43 
44     license_file = Path(f"{env['FREESURFER_HOME']}/license.txt")
45     if not license_file.exists():
46         license_file = Path(f"{env['FREESURFER_HOME']}/.license")
47     if not license_file.exists():
48         raise RuntimeError("FreeSurfer license file not found.")
49 
50     cmd = [
51         f"{sys.executable}",
52         f"{fs_bids_app}",
53         f"{root_dir}",
54         f"{subjects_dir}", "participant",
55         "--n_cpus=2", "--stages=all", "--skip_bids_validator",
56         f"--license_file={license_file}",
57         f"--participant_label={subject}"
58     ]
59     logger.debug("Running: " + " ".join(cmd))
60     run_subprocess(cmd, env=env, verbose=logger.level)
61 
62 
63 def main(n_jobs: int = 1) -> None:
64     """Run freesurfer recon-all command on BIDS dataset.
65 
66     The command allows to run the freesurfer recon-all
67     command on all subjects of your BIDS dataset. It can
68     run in parallel with the --n_jobs parameter.
69 
70     It is built on top of the FreeSurfer BIDS app:
71 
72     https://github.com/BIDS-Apps/freesurfer
73 
74     You must have freesurfer available on your system.
75 
76     Examples
77     --------
78     run_freesurfer.py /path/to/bids/dataset/study-template-config.py /path/to/freesurfer_bids_app/
79 
80     or to run in parallel (3 subjects at a time):
81 
82     run_freesurfer.py /path/to/bids/dataset/study-template-config.py /path/to/freesurfer_bids_app/ --n_jobs=3
83 
84     """  # noqa
85 
86     logger.info('Running FreeSurfer')
87 
88     subjects = config.get_subjects()
89 
90     root_dir = config.bids_root
91     subjects_dir = _get_subjects_dir(root_dir)
92     subjects_dir.mkdir(parents=True, exist_ok=True)
93 
94     parallel, run_func, _ = parallel_func(run_recon, n_jobs=n_jobs)
95     parallel(run_func(root_dir, subject, fs_bids_app)
96              for subject in subjects)
97 
98     # Handle fsaverage
99     fsaverage_dir = subjects_dir / 'fsaverage'
100     if fsaverage_dir.exists():
101         if fsaverage_dir.is_symlink():
102             fsaverage_dir.unlink()
103         else:
104             shutil.rmtree(fsaverage_dir)
105 
106     env = os.environ
107     shutil.copytree(f"{env['FREESURFER_HOME']}/subjects/fsaverage",
108                     subjects_dir / 'fsaverage')
109 
110 
111 if __name__ == '__main__':
112     fire.Fire(main)
113
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scripts/freesurfer/recon_all.py b/scripts/freesurfer/recon_all.py
--- a/scripts/freesurfer/recon_all.py
+++ b/scripts/freesurfer/recon_all.py
@@ -60,7 +60,7 @@
     run_subprocess(cmd, env=env, verbose=logger.level)
 
 
-def main(n_jobs: int = 1) -> None:
+def main(*, n_jobs: int = 1) -> None:
     """Run freesurfer recon-all command on BIDS dataset.
 
     The command allows to run the freesurfer recon-all

{"golden_diff": "diff --git a/scripts/freesurfer/recon_all.py b/scripts/freesurfer/recon_all.py\n--- a/scripts/freesurfer/recon_all.py\n+++ b/scripts/freesurfer/recon_all.py\n@@ -60,7 +60,7 @@\n     run_subprocess(cmd, env=env, verbose=logger.level)\n \n \n-def main(n_jobs: int = 1) -> None:\n+def main(*, n_jobs: int = 1) -> None:\n     \"\"\"Run freesurfer recon-all command on BIDS dataset.\n \n     The command allows to run the freesurfer recon-all\n", "issue": "`ValueError: n_jobs must be an integer` when calling freesurfer\nHi,\r\n\r\nWhen I run `python run.py freesurfer --config=~/hMT+/config.py`, I get the following error traceback:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/merlin/PhD/mne-bids-pipeline/run.py\", line 194, in <module>\r\n    fire.Fire(process)\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py\", line 141, in Fire\r\n    component_trace = _Fire(component, args, parsed_flag_args, context, name)\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py\", line 466, in _Fire\r\n    component, remaining_args = _CallAndUpdateTrace(\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py\", line 681, in _CallAndUpdateTrace\r\n    component = fn(*varargs, **kwargs)\r\n  File \"/home/merlin/PhD/mne-bids-pipeline/run.py\", line 189, in process\r\n    _run_script(script_path, config, root_dir, subject, session, task, run)\r\n  File \"/home/merlin/PhD/mne-bids-pipeline/run.py\", line 98, in _run_script\r\n    runpy.run_path(script_path, run_name='__main__')\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/runpy.py\", line 268, in run_path\r\n    return _run_module_code(code, init_globals, run_name,\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/home/merlin/PhD/mne-bids-pipeline/scripts/freesurfer/recon_all.py\", line 112, in <module>\r\n    fire.Fire(main)\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py\", line 141, in Fire\r\n    component_trace = _Fire(component, args, parsed_flag_args, context, name)\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py\", line 466, in _Fire\r\n    component, remaining_args = _CallAndUpdateTrace(\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/fire/core.py\", line 681, in _CallAndUpdateTrace\r\n    component = fn(*varargs, **kwargs)\r\n  File \"/home/merlin/PhD/mne-bids-pipeline/scripts/freesurfer/recon_all.py\", line 94, in main\r\n    parallel, run_func, _ = parallel_func(run_recon, n_jobs=n_jobs)\r\n  File \"<decorator-gen-42>\", line 24, in parallel_func\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/mne/parallel.py\", line 112, in parallel_func\r\n    n_jobs = check_n_jobs(n_jobs)\r\n  File \"/home/merlin/miniconda3/envs/mne-bids/lib/python3.9/site-packages/mne/parallel.py\", line 159, in check_n_jobs\r\n    raise ValueError('n_jobs must be an integer')\r\nValueError: n_jobs must be an integer\r\n```\r\n\r\nChecking with pdb, it seems that `recon_all` is called with `n_jobs = \"freesurfer\"`. I'm not sure why that is.\r\n\r\n```\r\n19:36:39 Using custom configuration: /home/merlin/hMT+/config.py\r\n19:36:39 [Step-01] Running: Initializing output directories.\r\n19:36:39 [Step-01] Initializing output directories.\r\n19:36:39 [Step-01] Completed: Initializing output directories.\r\n2021-04-14 19:36:39 INFO Successfully finished running: init_derivatives_dir\r\n2021-04-14 19:36:39 INFO Now running: on_all\r\n> /home/merlin/PhD/mne-bids-pipeline/scripts/freesurfer/recon_all.py(88)main()\r\n     87 \r\n---> 88     logger.info('Running FreeSurfer')\r\n     89 \r\n\r\nipdb> n_jobs\r\n'freesurfer'\r\nipdb>                                                                                                                                       \r\n```\r\n\r\nIt might be the config needs to be changed, but I can't figure out how.\n", "before_files": [{"content": "#!/usr/bin/env python\n\nimport os\nimport shutil\nimport sys\nfrom pathlib import Path\nimport logging\nfrom typing import Union\n\nimport fire\n\nfrom mne.utils import run_subprocess\nfrom mne.parallel import parallel_func\n\nimport config\n\nPathLike = Union[str, Path]\nlogger = logging.getLogger('mne-bids-pipeline')\nfs_bids_app = Path(__file__).parent / 'contrib' / 'run.py'\n\n\ndef _get_subjects_dir(root_dir) -> Path:\n    subjects_dir = \\\n        Path(root_dir) / \"derivatives\" / \"freesurfer\" / \"subjects\"\n    return subjects_dir\n\n\ndef run_recon(root_dir, subject, fs_bids_app) -> None:\n    logger.info(f\"Running recon-all on subject {subject}. This will take \"\n                f\"a LONG time \u2013 it's a good idea to let it run over night.\")\n\n    subjects_dir = _get_subjects_dir(root_dir)\n    subj_dir = subjects_dir / f\"sub-{subject}\"\n\n    if subj_dir.exists():\n        logger.info(f\"Subject {subject} is already present. Please delete the \"\n                    f\"directory if you want to recompute.\")\n        return\n\n    env = os.environ\n    if 'FREESURFER_HOME' not in env:\n        raise RuntimeError(\"FreeSurfer is not available.\")\n\n    license_file = Path(f\"{env['FREESURFER_HOME']}/license.txt\")\n    if not license_file.exists():\n        license_file = Path(f\"{env['FREESURFER_HOME']}/.license\")\n    if not license_file.exists():\n        raise RuntimeError(\"FreeSurfer license file not found.\")\n\n    cmd = [\n        f\"{sys.executable}\",\n        f\"{fs_bids_app}\",\n        f\"{root_dir}\",\n        f\"{subjects_dir}\", \"participant\",\n        \"--n_cpus=2\", \"--stages=all\", \"--skip_bids_validator\",\n        f\"--license_file={license_file}\",\n        f\"--participant_label={subject}\"\n    ]\n    logger.debug(\"Running: \" + \" \".join(cmd))\n    run_subprocess(cmd, env=env, verbose=logger.level)\n\n\ndef main(n_jobs: int = 1) -> None:\n    \"\"\"Run freesurfer recon-all command on BIDS dataset.\n\n    The command allows to run the freesurfer recon-all\n    command on all subjects of your BIDS dataset. It can\n    run in parallel with the --n_jobs parameter.\n\n    It is built on top of the FreeSurfer BIDS app:\n\n    https://github.com/BIDS-Apps/freesurfer\n\n    You must have freesurfer available on your system.\n\n    Examples\n    --------\n    run_freesurfer.py /path/to/bids/dataset/study-template-config.py /path/to/freesurfer_bids_app/\n\n    or to run in parallel (3 subjects at a time):\n\n    run_freesurfer.py /path/to/bids/dataset/study-template-config.py /path/to/freesurfer_bids_app/ --n_jobs=3\n\n    \"\"\"  # noqa\n\n    logger.info('Running FreeSurfer')\n\n    subjects = config.get_subjects()\n\n    root_dir = config.bids_root\n    subjects_dir = _get_subjects_dir(root_dir)\n    subjects_dir.mkdir(parents=True, exist_ok=True)\n\n    parallel, run_func, _ = parallel_func(run_recon, n_jobs=n_jobs)\n    parallel(run_func(root_dir, subject, fs_bids_app)\n             for subject in subjects)\n\n    # Handle fsaverage\n    fsaverage_dir = subjects_dir / 'fsaverage'\n    if fsaverage_dir.exists():\n        if fsaverage_dir.is_symlink():\n            fsaverage_dir.unlink()\n        else:\n            shutil.rmtree(fsaverage_dir)\n\n    env = os.environ\n    shutil.copytree(f\"{env['FREESURFER_HOME']}/subjects/fsaverage\",\n                    subjects_dir / 'fsaverage')\n\n\nif __name__ == '__main__':\n    fire.Fire(main)\n", "path": "scripts/freesurfer/recon_all.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\nimport os\nimport shutil\nimport sys\nfrom pathlib import Path\nimport logging\nfrom typing import Union\n\nimport fire\n\nfrom mne.utils import run_subprocess\nfrom mne.parallel import parallel_func\n\nimport config\n\nPathLike = Union[str, Path]\nlogger = logging.getLogger('mne-bids-pipeline')\nfs_bids_app = Path(__file__).parent / 'contrib' / 'run.py'\n\n\ndef _get_subjects_dir(root_dir) -> Path:\n    subjects_dir = \\\n        Path(root_dir) / \"derivatives\" / \"freesurfer\" / \"subjects\"\n    return subjects_dir\n\n\ndef run_recon(root_dir, subject, fs_bids_app) -> None:\n    logger.info(f\"Running recon-all on subject {subject}. This will take \"\n                f\"a LONG time \u2013 it's a good idea to let it run over night.\")\n\n    subjects_dir = _get_subjects_dir(root_dir)\n    subj_dir = subjects_dir / f\"sub-{subject}\"\n\n    if subj_dir.exists():\n        logger.info(f\"Subject {subject} is already present. Please delete the \"\n                    f\"directory if you want to recompute.\")\n        return\n\n    env = os.environ\n    if 'FREESURFER_HOME' not in env:\n        raise RuntimeError(\"FreeSurfer is not available.\")\n\n    license_file = Path(f\"{env['FREESURFER_HOME']}/license.txt\")\n    if not license_file.exists():\n        license_file = Path(f\"{env['FREESURFER_HOME']}/.license\")\n    if not license_file.exists():\n        raise RuntimeError(\"FreeSurfer license file not found.\")\n\n    cmd = [\n        f\"{sys.executable}\",\n        f\"{fs_bids_app}\",\n        f\"{root_dir}\",\n        f\"{subjects_dir}\", \"participant\",\n        \"--n_cpus=2\", \"--stages=all\", \"--skip_bids_validator\",\n        f\"--license_file={license_file}\",\n        f\"--participant_label={subject}\"\n    ]\n    logger.debug(\"Running: \" + \" \".join(cmd))\n    run_subprocess(cmd, env=env, verbose=logger.level)\n\n\ndef main(*, n_jobs: int = 1) -> None:\n    \"\"\"Run freesurfer recon-all command on BIDS dataset.\n\n    The command allows to run the freesurfer recon-all\n    command on all subjects of your BIDS dataset. It can\n    run in parallel with the --n_jobs parameter.\n\n    It is built on top of the FreeSurfer BIDS app:\n\n    https://github.com/BIDS-Apps/freesurfer\n\n    You must have freesurfer available on your system.\n\n    Examples\n    --------\n    run_freesurfer.py /path/to/bids/dataset/study-template-config.py /path/to/freesurfer_bids_app/\n\n    or to run in parallel (3 subjects at a time):\n\n    run_freesurfer.py /path/to/bids/dataset/study-template-config.py /path/to/freesurfer_bids_app/ --n_jobs=3\n\n    \"\"\"  # noqa\n\n    logger.info('Running FreeSurfer')\n\n    subjects = config.get_subjects()\n\n    root_dir = config.bids_root\n    subjects_dir = _get_subjects_dir(root_dir)\n    subjects_dir.mkdir(parents=True, exist_ok=True)\n\n    parallel, run_func, _ = parallel_func(run_recon, n_jobs=n_jobs)\n    parallel(run_func(root_dir, subject, fs_bids_app)\n             for subject in subjects)\n\n    # Handle fsaverage\n    fsaverage_dir = subjects_dir / 'fsaverage'\n    if fsaverage_dir.exists():\n        if fsaverage_dir.is_symlink():\n            fsaverage_dir.unlink()\n        else:\n            shutil.rmtree(fsaverage_dir)\n\n    env = os.environ\n    shutil.copytree(f\"{env['FREESURFER_HOME']}/subjects/fsaverage\",\n                    subjects_dir / 'fsaverage')\n\n\nif __name__ == '__main__':\n    fire.Fire(main)\n", "path": "scripts/freesurfer/recon_all.py"}]}