From 58607f9c04e6bb755e3b131d68f43d5beb5607a8 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Wed, 15 Feb 2023 08:47:16 -0500 Subject: [PATCH] Replace relative imports with absolute ones (#206) * Replace relative imports with absolute ones. * Run isort. * Remove comments between imports. --- aslprep/__about__.py | 2 +- aslprep/__init__.py | 2 +- aslprep/__main__.py | 4 +- aslprep/cli/parser.py | 14 +++---- aslprep/cli/run.py | 16 ++++---- aslprep/cli/version.py | 2 +- aslprep/cli/workflow.py | 17 +++++---- aslprep/config.py | 12 +++--- aslprep/interfaces/__init__.py | 21 ++++++---- aslprep/interfaces/confounds.py | 2 +- aslprep/interfaces/reports.py | 2 +- aslprep/utils/__init__.py | 1 + aslprep/utils/bids.py | 2 +- aslprep/utils/sentry.py | 4 +- aslprep/workflows/asl/__init__.py | 20 +++++----- aslprep/workflows/asl/base.py | 55 +++++++++++++-------------- aslprep/workflows/asl/cbf.py | 16 ++++---- aslprep/workflows/asl/confounds.py | 12 +++--- aslprep/workflows/asl/ge_utils.py | 30 +++++++-------- aslprep/workflows/asl/gecbf.py | 24 ++++++------ aslprep/workflows/asl/hmc.py | 8 ++-- aslprep/workflows/asl/outputs.py | 26 ++++++------- aslprep/workflows/asl/registration.py | 36 +++++++++--------- aslprep/workflows/asl/resampling.py | 38 +++++++++--------- aslprep/workflows/asl/stc.py | 6 +-- aslprep/workflows/asl/t2s.py | 6 +-- aslprep/workflows/base.py | 26 ++++++------- scripts/generate_reference_mask.py | 2 +- 28 files changed, 211 insertions(+), 195 deletions(-) diff --git a/aslprep/__about__.py b/aslprep/__about__.py index c583d4286..0440dff25 100644 --- a/aslprep/__about__.py +++ b/aslprep/__about__.py @@ -1,7 +1,7 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: """Base module variables.""" -from ._version import get_versions +from aslprep._version import get_versions __version__ = get_versions()["version"] del get_versions diff --git a/aslprep/__init__.py b/aslprep/__init__.py index cc5efa7e0..456dec29a 100644 --- a/aslprep/__init__.py +++ b/aslprep/__init__.py @@ -2,7 +2,7 @@ # vi: set ft=python sts=4 ts=4 sw=4 et: """Top-module metadata.""" -from .__about__ import __copyright__, __credits__, __packagename__, __version__ +from aslprep.__about__ import __copyright__, __credits__, __packagename__, __version__ __all__ = [ "__copyright__", diff --git a/aslprep/__main__.py b/aslprep/__main__.py index 992789d36..95701f37e 100644 --- a/aslprep/__main__.py +++ b/aslprep/__main__.py @@ -1,9 +1,9 @@ -from .cli.run import main +from aslprep.cli.run import main if __name__ == "__main__": import sys - from . import __name__ as module + from aslprep import __name__ as module # `python -m ` typically displays the command as __main__.py if "__main__.py" in sys.argv[0]: diff --git a/aslprep/cli/parser.py b/aslprep/cli/parser.py index 16d9f0ed7..6dbc20bd3 100644 --- a/aslprep/cli/parser.py +++ b/aslprep/cli/parser.py @@ -3,7 +3,7 @@ """Parser.""" import sys -from .. import config +from aslprep import config def _build_parser(): @@ -14,8 +14,8 @@ def _build_parser(): from packaging.version import Version - from ..niworkflows.utils.spaces import OutputReferencesAction, Reference - from .version import check_latest, is_flagged + from aslprep.cli.version import check_latest, is_flagged + from aslprep.niworkflows.utils.spaces import OutputReferencesAction, Reference def _path_exists(path, parser): """Ensure a given path exists.""" @@ -47,7 +47,7 @@ def _drop_sub(value): return value[4:] if value.startswith("sub-") else value def _filter_pybids_none_any(dct): - from ..pybids import layout + from aslprep.pybids import layout return {k: layout.Query.ANY if v == "*" else v for k, v in dct.items()} @@ -481,7 +481,7 @@ def parse_args(args=None, namespace=None): """Parse args and run further checks on the command line.""" import logging - from ..niworkflows.utils.spaces import Reference, SpatialReferences + from aslprep.niworkflows.utils.spaces import Reference, SpatialReferences parser = _build_parser() opts = parser.parse_args(args, namespace) @@ -545,7 +545,7 @@ def parse_args(args=None, namespace=None): # Wipe out existing work_dir if opts.clean_workdir and work_dir.exists(): - from ..niworkflows.utils.misc import clean_directory + from aslprep.niworkflows.utils.misc import clean_directory build_log.info(f"Clearing previous aslprep working directory: {work_dir}") if not clean_directory(work_dir): @@ -569,7 +569,7 @@ def parse_args(args=None, namespace=None): # Validate inputs if not opts.skip_bids_validation: - from ..utils.bids import validate_input_dir + from aslprep.utils.bids import validate_input_dir build_log.info( "Making sure the input data is BIDS compliant (warnings can be ignored in most " diff --git a/aslprep/cli/run.py b/aslprep/cli/run.py index 44c49411b..e1a1866ea 100644 --- a/aslprep/cli/run.py +++ b/aslprep/cli/run.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ASL preprocessing workflow.""" -from .. import config +from aslprep import config def main(): @@ -12,8 +12,8 @@ def main(): from os import EX_SOFTWARE from pathlib import Path - from ..utils.bids import write_derivative_description - from .parser import parse_args + from aslprep.cli.parser import parse_args + from aslprep.utils.bids import write_derivative_description parse_args() @@ -21,7 +21,7 @@ def main(): if not config.execution.notrack: import sentry_sdk - from ..utils.sentry import sentry_setup + from aslprep.utils.sentry import sentry_setup sentry_setup() @@ -35,7 +35,7 @@ def main(): # Because Python on Linux does not ever free virtual memory (VM), running the # workflow construction jailed within a process preempts excessive VM buildup. with Manager() as mgr: - from .workflow import build_workflow + from aslprep.cli.workflow import build_workflow retval = mgr.dict() p = Process(target=build_workflow, args=(str(config_file), retval)) @@ -62,7 +62,7 @@ def main(): # Generate boilerplate with Manager() as mgr: - from .workflow import build_boilerplate + from aslprep.cli.workflow import build_boilerplate p = Process(target=build_boilerplate, args=(str(config_file), aslprep_wf)) p.start() @@ -92,7 +92,7 @@ def main(): aslprep_wf.run(**config.nipype.get_plugin()) except Exception as e: if not config.execution.notrack: - from ..utils.sentry import process_crashfile + from aslprep.utils.sentry import process_crashfile crashfolders = [ config.execution.output_dir @@ -137,7 +137,7 @@ def main(): finally: from pkg_resources import resource_filename as pkgrf - from ..niworkflows.reports import generate_reports + from aslprep.niworkflows.reports import generate_reports # Generate reports phase failed_reports = generate_reports( diff --git a/aslprep/cli/version.py b/aslprep/cli/version.py index 4325767b7..63d10d9a9 100644 --- a/aslprep/cli/version.py +++ b/aslprep/cli/version.py @@ -7,7 +7,7 @@ import requests -from .. import __version__ +from aslprep import __version__ RELEASE_EXPIRY_DAYS = 14 DATE_FMT = "%Y%m%d" diff --git a/aslprep/cli/workflow.py b/aslprep/cli/workflow.py index 381ea8cdf..c2173fbb2 100644 --- a/aslprep/cli/workflow.py +++ b/aslprep/cli/workflow.py @@ -12,12 +12,15 @@ def build_workflow(config_file, retval): """Create the Nipype Workflow that supports the whole execution graph.""" - from .. import config - from ..niworkflows.reports import generate_reports - from ..niworkflows.utils.bids import check_pipeline_version, collect_participants - from ..niworkflows.utils.misc import check_valid_fs_license - from ..utils.misc import check_deps - from ..workflows.base import init_aslprep_wf + from aslprep import config + from aslprep.niworkflows.reports import generate_reports + from aslprep.niworkflows.utils.bids import ( + check_pipeline_version, + collect_participants, + ) + from aslprep.niworkflows.utils.misc import check_valid_fs_license + from aslprep.utils.misc import check_deps + from aslprep.workflows.base import init_aslprep_wf config.load(config_file) build_log = config.loggers.workflow @@ -108,7 +111,7 @@ def build_workflow(config_file, retval): def build_boilerplate(config_file, workflow): """Write boilerplate in an isolated process.""" - from .. import config + from aslprep import config config.load(config_file) logs_path = config.execution.output_dir / "aslprep" / "logs" diff --git a/aslprep/config.py b/aslprep/config.py index bf53ba6bc..7d0e0ca44 100644 --- a/aslprep/config.py +++ b/aslprep/config.py @@ -42,7 +42,7 @@ config.to_filename(config_file) # Call build_workflow(config_file, retval) in a subprocess with Manager() as mgr: - from .workflow import build_workflow + from aslprep.cli import build_workflow retval = mgr.dict() p = Process(target=build_workflow, args=(str(config_file), retval)) p.start() @@ -87,7 +87,7 @@ from nipype import logging as nlogging from templateflow import __version__ as _tf_ver - from . import __version__ + from aslprep import __version__ if not hasattr(sys, "_is_pytest_session"): sys._is_pytest_session = False # Trick to avoid sklearn's FutureWarnings @@ -99,12 +99,12 @@ os.getenv("aslprep_DEV", "0").lower() in ("1", "on", "true", "y", "yes"), ) ): - from ._warnings import logging + from aslprep._warnings import logging os.environ["PYTHONWARNINGS"] = "ignore" elif os.getenv("aslprep_WARNINGS", "0").lower() in ("1", "on", "true", "y", "yes"): # allow disabling warnings on development versions - from ._warnings import logging + from aslprep._warnings import logging else: import logging @@ -191,7 +191,7 @@ def load(cls, settings, init=True): @classmethod def get(cls): """Return defined settings.""" - from .niworkflows.utils.spaces import Reference, SpatialReferences + from aslprep.niworkflows.utils.spaces import Reference, SpatialReferences out = {} for k, v in cls.__dict__.items(): @@ -600,7 +600,7 @@ def to_filename(filename): def init_spaces(checkpoint=True): """Initialize the :attr:`~workflow.spaces` setting.""" - from .niworkflows.utils.spaces import Reference, SpatialReferences + from aslprep.niworkflows.utils.spaces import Reference, SpatialReferences spaces = execution.output_spaces or SpatialReferences() if not isinstance(spaces, SpatialReferences): diff --git a/aslprep/interfaces/__init__.py b/aslprep/interfaces/__init__.py index 33dd4906e..1ff4d5e9a 100644 --- a/aslprep/interfaces/__init__.py +++ b/aslprep/interfaces/__init__.py @@ -1,12 +1,19 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: - -# Load modules for compatibility -from ..niworkflows.interfaces import bids, cifti, freesurfer, images, itk, surf, utils -from ..niworkflows.interfaces.plotting import CBFSummary, CBFtsSummary -from .confounds import ASLSummary, GatherConfounds -from .multiecho import T2SMap -from .reports import AboutSummary, FunctionalSummary, SubjectSummary +"""Nipype interfaces for aslprep.""" +from aslprep.interfaces.confounds import ASLSummary, GatherConfounds +from aslprep.interfaces.multiecho import T2SMap +from aslprep.interfaces.reports import AboutSummary, FunctionalSummary, SubjectSummary +from aslprep.niworkflows.interfaces import ( + bids, + cifti, + freesurfer, + images, + itk, + surf, + utils, +) +from aslprep.niworkflows.interfaces.plotting import CBFSummary, CBFtsSummary class DerivativesDataSink(bids.DerivativesDataSink): diff --git a/aslprep/interfaces/confounds.py b/aslprep/interfaces/confounds.py index 158758b2f..f8dde57e4 100644 --- a/aslprep/interfaces/confounds.py +++ b/aslprep/interfaces/confounds.py @@ -201,7 +201,7 @@ class ASLSummary(SimpleInterface): output_spec = ASLSummaryOutputSpec def _run_interface(self, runtime): - from ..niworkflows.viz.plots import ASLPlot + from aslprep.niworkflows.viz.plots import ASLPlot self._results["out_file"] = fname_presuffix( self.inputs.in_func, suffix="_aslplot.svg", use_ext=False, newpath=runtime.cwd diff --git a/aslprep/interfaces/reports.py b/aslprep/interfaces/reports.py index cc71613f3..26bcc1e38 100644 --- a/aslprep/interfaces/reports.py +++ b/aslprep/interfaces/reports.py @@ -18,7 +18,7 @@ traits, ) -from ..smriprep.interfaces.freesurfer import ReconAll +from aslprep.smriprep.interfaces.freesurfer import ReconAll SUBJECT_TEMPLATE = """\ \t