Skip to content

Commit ed9af31

Browse files
authored
Merge pull request #2059 from effigies/relative_imports
ENH: Reduce within-package absolute imports
2 parents a61e455 + aaef1f3 commit ed9af31

File tree

18 files changed

+56
-62
lines changed

18 files changed

+56
-62
lines changed

nipype/algorithms/icc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from scipy.linalg import pinv
99
from ..interfaces.base import BaseInterfaceInputSpec, TraitedSpec, \
1010
BaseInterface, traits, File
11-
from nipype.utils import NUMPY_MMAP
11+
from ..utils import NUMPY_MMAP
1212

1313

1414
class ICCInputSpec(BaseInterfaceInputSpec):

nipype/algorithms/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
3131
InputMultiPath,
3232
BaseInterfaceInputSpec, isdefined)
33-
from nipype.utils import NUMPY_MMAP
33+
from ..utils import NUMPY_MMAP
3434

3535
iflogger = logging.getLogger('interface')
3636

nipype/algorithms/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
BaseInterfaceInputSpec, isdefined,
3535
DynamicTraitedSpec, Undefined)
3636
from ..utils.filemanip import fname_presuffix, split_filename
37-
from nipype.utils import NUMPY_MMAP
37+
from ..utils import NUMPY_MMAP
3838

3939
from . import confounds
4040

nipype/interfaces/dipy/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import nibabel as nb
1414
import numpy as np
1515

16+
from ...utils import NUMPY_MMAP
17+
1618
from ... import logging
1719
from ..base import (traits, TraitedSpec, File, isdefined)
1820
from .base import DipyBaseInterface
@@ -179,7 +181,6 @@ def resample_proxy(in_file, order=3, new_zooms=None, out_file=None):
179181
Performs regridding of an image to set isotropic voxel sizes using dipy.
180182
"""
181183
from dipy.align.reslice import reslice
182-
from nipype.utils import NUMPY_MMAP
183184

184185
if out_file is None:
185186
fname, fext = op.splitext(op.basename(in_file))
@@ -223,7 +224,6 @@ def nlmeans_proxy(in_file, settings,
223224
from dipy.denoise.nlmeans import nlmeans
224225
from scipy.ndimage.morphology import binary_erosion
225226
from scipy import ndimage
226-
from nipype.utils import NUMPY_MMAP
227227

228228
if out_file is None:
229229
fname, fext = op.splitext(op.basename(in_file))

nipype/interfaces/fsl/ICA_AROMA.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@
1010
... '../../testing/data'))
1111
>>> os.chdir(datadir)
1212
"""
13-
from nipype.interfaces.base import (
14-
TraitedSpec,
15-
CommandLineInputSpec,
16-
CommandLine,
17-
File,
18-
Directory,
19-
traits,
20-
OutputMultiPath
21-
)
13+
from __future__ import print_function, division, unicode_literals, absolute_import
14+
from ..base import (TraitedSpec, CommandLineInputSpec, CommandLine,
15+
File, Directory, traits)
2216
import os
2317

18+
2419
class ICA_AROMAInputSpec(CommandLineInputSpec):
2520
feat_dir = Directory(exists=True, mandatory=True,
2621
argstr='-feat %s',

nipype/interfaces/fsl/fix.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
23
# vi: set ft=python sts=4 ts=4 sw=4 et:
34
"""The fix module provides classes for interfacing with the `FSL FIX
@@ -53,8 +54,9 @@
5354
outgraph = fix_pipeline.run()
5455
5556
"""
57+
from __future__ import print_function, division, unicode_literals, absolute_import
5658

57-
from nipype.interfaces.base import (
59+
from ..base import (
5860
TraitedSpec,
5961
CommandLineInputSpec,
6062
CommandLine,
@@ -64,13 +66,10 @@
6466
BaseInterfaceInputSpec,
6567
traits
6668
)
67-
from nipype.interfaces.traits_extension import (
68-
Directory,
69-
File,
70-
isdefined
71-
)
69+
from ..traits_extension import Directory, File, isdefined
7270
import os
7371

72+
7473
class TrainingSetCreatorInputSpec(BaseInterfaceInputSpec):
7574
mel_icas_in = InputMultiPath(Directory(exists=True), copyfile=False,
7675
desc='Melodic output directories',

nipype/interfaces/niftyseg/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
23
# vi: set ft=python sts=4 ts=4 sw=4 et:
34

@@ -15,9 +16,10 @@
1516
--------
1617
See the docstrings of the individual classes for examples.
1718
"""
19+
from __future__ import print_function, division, unicode_literals, absolute_import
1820

19-
from nipype.interfaces.niftyreg.base import no_nifty_package
20-
from nipype.interfaces.niftyfit.base import NiftyFitCommand
21+
from ..niftyreg.base import no_nifty_package
22+
from ..niftyfit.base import NiftyFitCommand
2123
import subprocess
2224
import warnings
2325

nipype/interfaces/petpvc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import os
1414

1515
from .base import TraitedSpec, CommandLineInputSpec, CommandLine, File, isdefined, traits
16-
from ..external.due import due, Doi, BibTeX
16+
from ..utils.filemanip import fname_presuffix
17+
from ..external.due import BibTeX
1718

1819
pvc_methods = ['GTM',
1920
'IY',
@@ -200,8 +201,6 @@ def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True,
200201
New filename based on given parameters.
201202
202203
"""
203-
from nipype.utils.filemanip import fname_presuffix
204-
205204
if basename == '':
206205
msg = 'Unable to generate filename for command %s. ' % self.cmd
207206
msg += 'basename is not set!'

nipype/interfaces/utility/wrappers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
from builtins import str, bytes
2121

22-
from nipype import logging
22+
from ... import logging
2323
from ..base import (traits, DynamicTraitedSpec, Undefined, isdefined, runtime_profile,
24-
BaseInterfaceInputSpec)
24+
BaseInterfaceInputSpec, get_max_resources_used)
2525
from ..io import IOBase, add_traits
2626
from ...utils.filemanip import filename_to_list
2727
from ...utils.misc import getsource, create_function_from_source
@@ -138,7 +138,6 @@ def _add_output_traits(self, base):
138138

139139
def _run_interface(self, runtime):
140140
# Get workflow logger for runtime profile error reporting
141-
from nipype import logging
142141
logger = logging.getLogger('workflow')
143142

144143
# Create function handle
@@ -163,7 +162,6 @@ def _function_handle_wrapper(queue, **kwargs):
163162

164163
# Profile resources if set
165164
if runtime_profile:
166-
from nipype.interfaces.base import get_max_resources_used
167165
import multiprocessing
168166
# Init communication queue and proc objs
169167
queue = multiprocessing.Queue()

nipype/pipeline/engine/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# -*- coding: utf-8 -*-
32
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
43
# vi: set ft=python sts=4 ts=4 sw=4 et:
@@ -24,7 +23,7 @@
2423
import pickle
2524
from functools import reduce
2625
import numpy as np
27-
from nipype.utils.misc import package_check
26+
from ...utils.misc import package_check
2827

2928
package_check('networkx', '1.3')
3029

nipype/utils/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import
33

4-
from nipype.utils.config import NUMPY_MMAP
5-
from nipype.utils.onetime import OneTimeProperty, setattr_on_read
6-
from nipype.utils.tmpdirs import TemporaryDirectory, InTemporaryDirectory
4+
from .config import NUMPY_MMAP
5+
from .onetime import OneTimeProperty, setattr_on_read
6+
from .tmpdirs import TemporaryDirectory, InTemporaryDirectory

nipype/workflows/dmri/fsl/artifacts.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# coding: utf-8
33
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
44
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
from __future__ import division
6-
7-
from nipype.utils import NUMPY_MMAP
5+
from __future__ import print_function, division, unicode_literals, absolute_import
86

97
from ....interfaces.io import JSONFileGrabber
108
from ....interfaces import utility as niu
119
from ....interfaces import ants
1210
from ....interfaces import fsl
1311
from ....pipeline import engine as pe
12+
from ...data import get_flirt_schedule
13+
1414
from .utils import (b0_indices, time_avg, apply_all_corrections, b0_average,
1515
hmc_split, dwi_flirt, eddy_rotate_bvecs, rotate_bvecs,
1616
insert_mat, extract_bval, recompose_dwi, recompose_xfm,
@@ -354,8 +354,6 @@ def hmc_pipeline(name='motion_correct'):
354354
outputnode.out_xfms - list of transformation matrices
355355
356356
"""
357-
from nipype.workflows.data import get_flirt_schedule
358-
359357
params = dict(dof=6, bgvalue=0, save_log=True, no_search=True,
360358
# cost='mutualinfo', cost_func='mutualinfo', bins=64,
361359
schedule=get_flirt_schedule('hmc'))
@@ -456,7 +454,6 @@ def ecc_pipeline(name='eddy_correct'):
456454
outputnode.out_xfms - list of transformation matrices
457455
"""
458456

459-
from nipype.workflows.data import get_flirt_schedule
460457
params = dict(dof=12, no_search=True, interp='spline', bgvalue=0,
461458
schedule=get_flirt_schedule('ecc'))
462459
# cost='normmi', cost_func='normmi', bins=64,
@@ -903,6 +900,7 @@ def _xfm_jacobian(in_xfm):
903900

904901
def _get_zoom(in_file, enc_dir):
905902
import nibabel as nb
903+
from nipype.utils import NUMPY_MMAP
906904

907905
zooms = nb.load(in_file, mmap=NUMPY_MMAP).header.get_zooms()
908906

nipype/workflows/smri/freesurfer/autorecon1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
2-
3-
from nipype.utils import NUMPY_MMAP
4-
from nipype.interfaces.utility import Function,IdentityInterface
5-
import nipype.pipeline.engine as pe # pypeline engine
6-
from nipype.interfaces.freesurfer import *
2+
from __future__ import print_function, division, unicode_literals, absolute_import
3+
from ....utils import NUMPY_MMAP
4+
from ....pipeline import engine as pe
5+
from ....interfaces.utility import Function, IdentityInterface
6+
from ....interfaces.freesurfer import *
77
from .utils import copy_file
88

99

nipype/workflows/smri/freesurfer/autorecon2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
from nipype.interfaces.utility import Function, IdentityInterface, Merge
3-
import nipype.pipeline.engine as pe # pypeline engine
4-
from nipype.interfaces.freesurfer import *
2+
from __future__ import print_function, division, unicode_literals, absolute_import
3+
from ....interfaces.utility import Function, IdentityInterface, Merge
4+
from ....pipeline import engine as pe
5+
from ....interfaces.freesurfer import *
56
from .utils import copy_file
67

78
def copy_ltas(in_file, subjects_dir, subject_id, long_template):

nipype/workflows/smri/freesurfer/autorecon3.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
from nipype.interfaces.utility import IdentityInterface, Merge, Function
3-
import nipype.pipeline.engine as pe # pypeline engine
4-
from nipype.interfaces.freesurfer import *
2+
from __future__ import print_function, division, unicode_literals, absolute_import
3+
from ....interfaces.utility import IdentityInterface, Merge, Function
4+
from ....pipeline import engine as pe
5+
from ....interfaces.freesurfer import *
56
from .ba_maps import create_ba_maps_wf
6-
from nipype.interfaces.io import DataGrabber
7+
from ....interfaces.io import DataGrabber
78

89
def create_AutoRecon3(name="AutoRecon3", qcache=False, plugin_args=None,
910
th3=True, exvivo=True, entorhinal=True, fsvernum=5.3):

nipype/workflows/smri/freesurfer/ba_maps.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# -*- coding: utf-8 -*-
2+
from __future__ import print_function, division, unicode_literals, absolute_import
23
import os
3-
import nipype
4-
from nipype.interfaces.utility import Function,IdentityInterface
5-
import nipype.pipeline.engine as pe # pypeline engine
6-
from nipype.interfaces.freesurfer import *
7-
from nipype.interfaces.io import DataGrabber
8-
from nipype.interfaces.utility import Merge
4+
from ....interfaces.utility import Function, IdentityInterface
5+
from ....pipeline import engine as pe # pypeline engine
6+
from ....interfaces.freesurfer import *
7+
from ....interfaces.io import DataGrabber
8+
from ....interfaces.utility import Merge
99

1010
def create_ba_maps_wf(name="Brodmann_Area_Maps", th3=True, exvivo=True,
1111
entorhinal=True):

nipype/workflows/smri/freesurfer/recon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from __future__ import print_function, division, unicode_literals, absolute_import
23
from ....pipeline import engine as pe
34
from ....interfaces import freesurfer as fs
45
from ....interfaces import utility as niu
@@ -206,7 +207,6 @@ def setconfig(reg_template=None,
206207
awk_file=None,
207208
rb_date=None):
208209
"""Set optional configurations to the default"""
209-
from nipype.workflows.smri.freesurfer.utils import getdefaultconfig
210210
def checkarg(arg, default):
211211
"""Returns the value if defined; otherwise default"""
212212
if arg:

nipype/workflows/smri/niftyreg/groupwise.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
23
# vi: set ft=python sts=4 ts=4 sw=4 et:
34

@@ -6,10 +7,11 @@
67
pipelines. Including linear and non-linear image co-registration
78
"""
89

10+
from __future__ import print_function, division, unicode_literals, absolute_import
911
from builtins import str, range
10-
import nipype.interfaces.utility as niu
11-
import nipype.interfaces.niftyreg as niftyreg
12-
import nipype.pipeline.engine as pe
12+
from ....interfaces import utility as niu
13+
from ....interfaces import niftyreg as niftyreg
14+
from ....pipeline import engine as pe
1315

1416

1517
def create_linear_gw_step(name="linear_gw_niftyreg",

0 commit comments

Comments
 (0)