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

Conversation

effigies
Copy link
Member

@effigies effigies commented Jun 1, 2017

With our (FMRIPREP/MRIQC) mismatched release cycles, we're running into the situation where correctly managing dependencies puts an undue burden on users (at least those installing natively, rather than running the Docker/Singularity images). We're attempting to move to include nipype as a submodule in niworkflows. Our projects will then import from niworkflows.nipype, which will avoid clashing with other installs of nipype.

Absolute imports assume that the root module is named nipype, where relative imports will permit (relatively) easy use as a submodule.

This should not affect the actual behavior of nipype at all, but will require that future PRs refrain from using absolute imports.

Changes proposed in this pull request:

  • Move to relative imports in non-testing code

@chrisgorgo
Copy link
Member

pycharm is showing me many more occurences of "from nipype" in non-testing code:
image

@effigies
Copy link
Member Author

effigies commented Jun 1, 2017

The slicer modules are auto-generated. It looks like the generating script has been updated, I just didn't take the time to figure out how to run it.

Edit: And I believe the other instances are in doctests or functions that import locally. I think those have to be absolute.

@codecov-io
Copy link

codecov-io commented Jun 1, 2017

Codecov Report

Merging #2059 into master will increase coverage by <.01%.
The diff coverage is 97.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2059      +/-   ##
==========================================
+ Coverage   72.17%   72.17%   +<.01%     
==========================================
  Files        1136     1136              
  Lines       57147    57150       +3     
  Branches     8185     8185              
==========================================
+ Hits        41243    41249       +6     
+ Misses      14617    14614       -3     
  Partials     1287     1287
Flag Coverage Δ
#smoketests 72.17% <97.87%> (ø) ⬆️
#unittests 69.78% <97.87%> (ø) ⬆️
Impacted Files Coverage Δ
nipype/workflows/smri/freesurfer/ba_maps.py 90.27% <100%> (ø) ⬆️
nipype/workflows/smri/freesurfer/autorecon2.py 71.26% <100%> (+0.11%) ⬆️
nipype/utils/__init__.py 100% <100%> (ø) ⬆️
nipype/algorithms/metrics.py 53.47% <100%> (ø) ⬆️
nipype/interfaces/utility/wrappers.py 86.11% <100%> (-0.26%) ⬇️
nipype/algorithms/icc.py 58.44% <100%> (ø) ⬆️
nipype/workflows/smri/freesurfer/autorecon1.py 38.42% <100%> (+0.28%) ⬆️
nipype/workflows/smri/freesurfer/autorecon3.py 69.09% <100%> (+0.1%) ⬆️
nipype/algorithms/misc.py 44.22% <100%> (ø) ⬆️
nipype/interfaces/petpvc.py 55.55% <100%> (+1.85%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a61e455...aaef1f3. Read the comment docs.

@chrisgorgo
Copy link
Member

I think there are still some imports apart from the autogenerated classes (in dipy and petpvc for example).

@effigies effigies force-pushed the relative_imports branch from f5056c4 to 891f69f Compare June 1, 2017 19:38
@effigies effigies force-pushed the relative_imports branch from 891f69f to 10c641d Compare June 1, 2017 20:17
@effigies
Copy link
Member Author

effigies commented Jun 1, 2017

I think I got all of them now.

Copy link
Contributor

@oesteban oesteban left a comment

Choose a reason for hiding this comment

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

LGTM, only make sure those from __future__ import absolute_import are there (for python 2 to work equivalently)

traits,
OutputMultiPath
)
from ..base import (TraitedSpec, CommandLineInputSpec, CommandLine,
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

@@ -54,7 +54,7 @@

"""

from nipype.interfaces.base import (
from ..base import (
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

@@ -16,8 +16,8 @@
See the docstrings of the individual classes for examples.
"""

from nipype.interfaces.niftyreg.base import no_nifty_package
from nipype.interfaces.niftyfit.base import NiftyFitCommand
from ..niftyreg.base import no_nifty_package
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

@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
Copy link
Contributor

Choose a reason for hiding this comment

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

Why removing this?

@@ -4,13 +4,13 @@
# vi: set ft=python sts=4 ts=4 sw=4 et:
from __future__ import division

from nipype.utils import NUMPY_MMAP

from ....interfaces.io import JSONFileGrabber
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 nipype.interfaces.utility import Function,IdentityInterface
import nipype.pipeline.engine as pe # pypeline engine
from nipype.interfaces.freesurfer import *
from ....utils import NUMPY_MMAP
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 nipype.interfaces.utility import Function, IdentityInterface, Merge
import nipype.pipeline.engine as pe # pypeline engine
from nipype.interfaces.freesurfer import *
from ....interfaces.utility import Function, IdentityInterface, Merge
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 nipype.interfaces.utility import IdentityInterface, Merge, Function
import nipype.pipeline.engine as pe # pypeline engine
from nipype.interfaces.freesurfer import *
from ....interfaces.utility import IdentityInterface, Merge, Function
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 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

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

@effigies
Copy link
Member Author

effigies commented Jun 1, 2017

I thought from __future__ import absolute_import was for if you wanted to import within the package using absolute import paths. If we're eliminating them, it seemed unnecessary.

Instead it seems that it does the opposite, always preferring an installed package to the local package. Which makes me wonder why we were using absolute imports for within-package imports at all.

@effigies
Copy link
Member Author

effigies commented Jun 2, 2017

@oesteban Updated.

@satra satra merged commit ed9af31 into nipy:master Jun 3, 2017
@effigies effigies deleted the relative_imports branch October 5, 2017 20:29
@satra satra added this to the 0.14.0 milestone Oct 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants