Skip to content

Commit 736306b

Browse files
authored
Merge pull request #510 from mgxd/enh/fs-license-env
ENH: add ability to set license
2 parents 98ff359 + d14b719 commit 736306b

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

niworkflows/utils/misc.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,32 @@ def pass_dummy_scans(algo_dummy_scans, dummy_scans=None):
263263
return dummy_scans
264264

265265

266-
def check_valid_fs_license():
267-
"""Run ``mri_convert`` to assess FreeSurfer access to a license."""
266+
def check_valid_fs_license(lic=None):
267+
"""
268+
Run ``mri_convert`` to assess FreeSurfer access to a license.
269+
270+
Parameters
271+
----------
272+
lic : :obj:`str`, optional
273+
Path to FreeSurfer license file
274+
275+
Returns
276+
-------
277+
valid : :obj:`bool`
278+
FreeSurfer license is valid
279+
280+
"""
268281
from pathlib import Path
269282
import subprocess as sp
270283
from tempfile import TemporaryDirectory
271284

272285
import nibabel as nb
273286
import numpy as np
274287

288+
if lic is not None:
289+
import os
290+
os.environ['FS_LICENSE'] = str(Path(lic).absolute())
291+
275292
with TemporaryDirectory() as tmpdir:
276293
nii_file = str(Path(tmpdir) / 'test.nii.gz')
277294
out_file = str(Path(tmpdir) / 'out.mgz')

niworkflows/utils/tests/test_misc.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test misc module."""
2+
import os
23
from unittest import mock
34

45
import pytest
@@ -17,12 +18,15 @@ def test_pass_dummy_scans(algo_dummy_scans, dummy_scans, expected_out):
1718
assert skip_vols == expected_out
1819

1920

20-
@pytest.mark.parametrize('valid,stderr', [
21-
(True, b''),
22-
(False, b'ERROR: FreeSurfer license file /made/up/license.txt not found'),
23-
(True, b'Non-license ERROR'),
21+
@pytest.mark.parametrize('valid,lic,stderr', [
22+
(True, None, b''),
23+
(False, None, b'ERROR: FreeSurfer license file /made/up/license.txt not found'),
24+
(True, None, b'Non-license ERROR'),
25+
(True, 'custom/license.txt', b''),
2426
])
25-
def test_fs_license_check(valid, stderr):
27+
def test_fs_license_check(valid, lic, stderr):
2628
with mock.patch('subprocess.run') as mocked_run:
2729
mocked_run.return_value.stderr = stderr
28-
assert check_valid_fs_license() == valid
30+
assert check_valid_fs_license(lic=lic) == valid
31+
if lic is not None:
32+
assert os.getenv('FS_LICENSE')

0 commit comments

Comments
 (0)