Skip to content

ENH: Reduce within-package absolute imports #2059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nipype/algorithms/icc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scipy.linalg import pinv
from ..interfaces.base import BaseInterfaceInputSpec, TraitedSpec, \
BaseInterface, traits, File
from nipype.utils import NUMPY_MMAP
from ..utils import NUMPY_MMAP


class ICCInputSpec(BaseInterfaceInputSpec):
Expand Down
2 changes: 1 addition & 1 deletion nipype/algorithms/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
InputMultiPath,
BaseInterfaceInputSpec, isdefined)
from nipype.utils import NUMPY_MMAP
from ..utils import NUMPY_MMAP

iflogger = logging.getLogger('interface')

Expand Down
2 changes: 1 addition & 1 deletion nipype/algorithms/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
BaseInterfaceInputSpec, isdefined,
DynamicTraitedSpec, Undefined)
from ..utils.filemanip import fname_presuffix, split_filename
from nipype.utils import NUMPY_MMAP
from ..utils import NUMPY_MMAP

from . import confounds

Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/dipy/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import nibabel as nb
import numpy as np

from ...utils import NUMPY_MMAP

from ... import logging
from ..base import (traits, TraitedSpec, File, isdefined)
from .base import DipyBaseInterface
Expand Down Expand Up @@ -179,7 +181,6 @@ def resample_proxy(in_file, order=3, new_zooms=None, out_file=None):
Performs regridding of an image to set isotropic voxel sizes using dipy.
"""
from dipy.align.reslice import reslice
from nipype.utils import NUMPY_MMAP

if out_file is None:
fname, fext = op.splitext(op.basename(in_file))
Expand Down Expand Up @@ -223,7 +224,6 @@ def nlmeans_proxy(in_file, settings,
from dipy.denoise.nlmeans import nlmeans
from scipy.ndimage.morphology import binary_erosion
from scipy import ndimage
from nipype.utils import NUMPY_MMAP

if out_file is None:
fname, fext = op.splitext(op.basename(in_file))
Expand Down
13 changes: 4 additions & 9 deletions nipype/interfaces/fsl/ICA_AROMA.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
... '../../testing/data'))
>>> os.chdir(datadir)
"""
from nipype.interfaces.base import (
TraitedSpec,
CommandLineInputSpec,
CommandLine,
File,
Directory,
traits,
OutputMultiPath
)
from __future__ import print_function, division, unicode_literals, absolute_import
from ..base import (TraitedSpec, CommandLineInputSpec, CommandLine,
File, Directory, traits)
import os


class ICA_AROMAInputSpec(CommandLineInputSpec):
feat_dir = Directory(exists=True, mandatory=True,
argstr='-feat %s',
Expand Down
11 changes: 5 additions & 6 deletions nipype/interfaces/fsl/fix.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""The fix module provides classes for interfacing with the `FSL FIX
Expand Down Expand Up @@ -53,8 +54,9 @@
outgraph = fix_pipeline.run()

"""
from __future__ import print_function, division, unicode_literals, absolute_import

from nipype.interfaces.base import (
from ..base import (
TraitedSpec,
CommandLineInputSpec,
CommandLine,
Expand All @@ -64,13 +66,10 @@
BaseInterfaceInputSpec,
traits
)
from nipype.interfaces.traits_extension import (
Directory,
File,
isdefined
)
from ..traits_extension import Directory, File, isdefined
import os


class TrainingSetCreatorInputSpec(BaseInterfaceInputSpec):
mel_icas_in = InputMultiPath(Directory(exists=True), copyfile=False,
desc='Melodic output directories',
Expand Down
6 changes: 4 additions & 2 deletions nipype/interfaces/niftyseg/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:

Expand All @@ -15,9 +16,10 @@
--------
See the docstrings of the individual classes for examples.
"""
from __future__ import print_function, division, unicode_literals, absolute_import

from nipype.interfaces.niftyreg.base import no_nifty_package
from nipype.interfaces.niftyfit.base import NiftyFitCommand
from ..niftyreg.base import no_nifty_package
from ..niftyfit.base import NiftyFitCommand
import subprocess
import warnings

Expand Down
5 changes: 2 additions & 3 deletions nipype/interfaces/petpvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import os

from .base import TraitedSpec, CommandLineInputSpec, CommandLine, File, isdefined, traits
from ..external.due import due, Doi, BibTeX
from ..utils.filemanip import fname_presuffix
from ..external.due import BibTeX

pvc_methods = ['GTM',
'IY',
Expand Down Expand Up @@ -200,8 +201,6 @@ def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True,
New filename based on given parameters.

"""
from nipype.utils.filemanip import fname_presuffix

if basename == '':
msg = 'Unable to generate filename for command %s. ' % self.cmd
msg += 'basename is not set!'
Expand Down
6 changes: 2 additions & 4 deletions nipype/interfaces/utility/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

from builtins import str, bytes

from nipype import logging
from ... import logging
from ..base import (traits, DynamicTraitedSpec, Undefined, isdefined, runtime_profile,
BaseInterfaceInputSpec)
BaseInterfaceInputSpec, get_max_resources_used)
from ..io import IOBase, add_traits
from ...utils.filemanip import filename_to_list
from ...utils.misc import getsource, create_function_from_source
Expand Down Expand Up @@ -138,7 +138,6 @@ def _add_output_traits(self, base):

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

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

# Profile resources if set
if runtime_profile:
from nipype.interfaces.base import get_max_resources_used
import multiprocessing
# Init communication queue and proc objs
queue = multiprocessing.Queue()
Expand Down
3 changes: 1 addition & 2 deletions nipype/pipeline/engine/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
Expand All @@ -24,7 +23,7 @@
import pickle
from functools import reduce
import numpy as np
from nipype.utils.misc import package_check
from ...utils.misc import package_check

package_check('networkx', '1.3')

Expand Down
6 changes: 3 additions & 3 deletions nipype/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from nipype.utils.config import NUMPY_MMAP
from nipype.utils.onetime import OneTimeProperty, setattr_on_read
from nipype.utils.tmpdirs import TemporaryDirectory, InTemporaryDirectory
from .config import NUMPY_MMAP
from .onetime import OneTimeProperty, setattr_on_read
from .tmpdirs import TemporaryDirectory, InTemporaryDirectory
10 changes: 4 additions & 6 deletions nipype/workflows/dmri/fsl/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# coding: utf-8
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
from __future__ import division

from nipype.utils import NUMPY_MMAP
from __future__ import print_function, division, unicode_literals, absolute_import

from ....interfaces.io import JSONFileGrabber
from ....interfaces import utility as niu
from ....interfaces import ants
from ....interfaces import fsl
from ....pipeline import engine as pe
from ...data import get_flirt_schedule

from .utils import (b0_indices, time_avg, apply_all_corrections, b0_average,
hmc_split, dwi_flirt, eddy_rotate_bvecs, rotate_bvecs,
insert_mat, extract_bval, recompose_dwi, recompose_xfm,
Expand Down Expand Up @@ -354,8 +354,6 @@ def hmc_pipeline(name='motion_correct'):
outputnode.out_xfms - list of transformation matrices

"""
from nipype.workflows.data import get_flirt_schedule

params = dict(dof=6, bgvalue=0, save_log=True, no_search=True,
# cost='mutualinfo', cost_func='mutualinfo', bins=64,
schedule=get_flirt_schedule('hmc'))
Expand Down Expand Up @@ -456,7 +454,6 @@ def ecc_pipeline(name='eddy_correct'):
outputnode.out_xfms - list of transformation matrices
"""

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

def _get_zoom(in_file, enc_dir):
import nibabel as nb
from nipype.utils import NUMPY_MMAP

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

Expand Down
10 changes: 5 additions & 5 deletions nipype/workflows/smri/freesurfer/autorecon1.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

from nipype.utils import NUMPY_MMAP
from nipype.interfaces.utility import Function,IdentityInterface
import nipype.pipeline.engine as pe # pypeline engine
from nipype.interfaces.freesurfer import *
from __future__ import print_function, division, unicode_literals, absolute_import
from ....utils import NUMPY_MMAP
from ....pipeline import engine as pe
from ....interfaces.utility import Function, IdentityInterface
from ....interfaces.freesurfer import *
from .utils import copy_file


Expand Down
7 changes: 4 additions & 3 deletions nipype/workflows/smri/freesurfer/autorecon2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from nipype.interfaces.utility import Function, IdentityInterface, Merge
import nipype.pipeline.engine as pe # pypeline engine
from nipype.interfaces.freesurfer import *
from __future__ import print_function, division, unicode_literals, absolute_import
from ....interfaces.utility import Function, IdentityInterface, Merge
from ....pipeline import engine as pe
from ....interfaces.freesurfer import *
from .utils import copy_file

def copy_ltas(in_file, subjects_dir, subject_id, long_template):
Expand Down
9 changes: 5 additions & 4 deletions nipype/workflows/smri/freesurfer/autorecon3.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
from nipype.interfaces.utility import IdentityInterface, Merge, Function
import nipype.pipeline.engine as pe # pypeline engine
from nipype.interfaces.freesurfer import *
from __future__ import print_function, division, unicode_literals, absolute_import
from ....interfaces.utility import IdentityInterface, Merge, Function
from ....pipeline import engine as pe
from ....interfaces.freesurfer import *
from .ba_maps import create_ba_maps_wf
from nipype.interfaces.io import DataGrabber
from ....interfaces.io import DataGrabber

def create_AutoRecon3(name="AutoRecon3", qcache=False, plugin_args=None,
th3=True, exvivo=True, entorhinal=True, fsvernum=5.3):
Expand Down
12 changes: 6 additions & 6 deletions nipype/workflows/smri/freesurfer/ba_maps.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, unicode_literals, absolute_import
import os
import nipype
from nipype.interfaces.utility import Function,IdentityInterface
import nipype.pipeline.engine as pe # pypeline engine
from nipype.interfaces.freesurfer import *
from nipype.interfaces.io import DataGrabber
from nipype.interfaces.utility import Merge
from ....interfaces.utility import Function, IdentityInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for backwards compatibility, make sure to add from __future__ import absolute_import before this

from ....pipeline import engine as pe # pypeline engine
from ....interfaces.freesurfer import *
from ....interfaces.io import DataGrabber
from ....interfaces.utility import Merge

def create_ba_maps_wf(name="Brodmann_Area_Maps", th3=True, exvivo=True,
entorhinal=True):
Expand Down
2 changes: 1 addition & 1 deletion nipype/workflows/smri/freesurfer/recon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, unicode_literals, absolute_import
from ....pipeline import engine as pe
from ....interfaces import freesurfer as fs
from ....interfaces import utility as niu
Expand Down Expand Up @@ -206,7 +207,6 @@ def setconfig(reg_template=None,
awk_file=None,
rb_date=None):
"""Set optional configurations to the default"""
from nipype.workflows.smri.freesurfer.utils import getdefaultconfig
def checkarg(arg, default):
"""Returns the value if defined; otherwise default"""
if arg:
Expand Down
8 changes: 5 additions & 3 deletions nipype/workflows/smri/niftyreg/groupwise.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:

Expand All @@ -6,10 +7,11 @@
pipelines. Including linear and non-linear image co-registration
"""

from __future__ import print_function, division, unicode_literals, absolute_import
from builtins import str, range
import nipype.interfaces.utility as niu
import nipype.interfaces.niftyreg as niftyreg
import nipype.pipeline.engine as pe
from ....interfaces import utility as niu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for backwards compatibility, make sure to add from __future__ import absolute_import before this

from ....interfaces import niftyreg as niftyreg
from ....pipeline import engine as pe


def create_linear_gw_step(name="linear_gw_niftyreg",
Expand Down