Skip to content

Commit

Permalink
Merge pull request #84 from AGrigis/ag-extplugins2
Browse files Browse the repository at this point in the history
External plugins mechanism
  • Loading branch information
sfarrens committed Mar 21, 2019
2 parents f302efd + 140c1ff commit d5a1293
Show file tree
Hide file tree
Showing 50 changed files with 139 additions and 3,976 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ install:
- pip install sklearn
- pip install nibabel
- pip install progressbar2
- pip install astropy
- pip install astropy==2.0.8
- pip install PyWavelets
- pip install git+https://github.com/CEA-COSMIC/ModOpt@master
- pip install -b $TRAVIS_BUILD_DIR/build -t $TRAVIS_BUILD_DIR/install --no-clean .
- pip install modopt
- pip install git+https://github.com/CEA-COSMIC/pysap-mri@master
- pip install git+https://github.com/CEA-COSMIC/pysap-astro@master
- pip install -b $TRAVIS_BUILD_DIR/build -t $TRAVIS_BUILD_DIR/install --no-clean --no-deps .
- ls $TRAVIS_BUILD_DIR/install
- ldd $TRAVIS_BUILD_DIR/install/pysparse.so
- export PYTHONPATH=$TRAVIS_BUILD_DIR/install:$PYTHONPATH
Expand Down
8 changes: 4 additions & 4 deletions examples/mri/cartesian_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
# Package import
import pysap
from pysap.data import get_sample_data
from pysap.numerics.reconstruct import sparse_rec_fista
from pysap.numerics.reconstruct import sparse_rec_condatvu
from pysap.numerics.utils import generate_operators
from pysap.numerics.utils import convert_mask_to_locations
from pysap.plugins.mri.numerics.reconstruct import sparse_rec_fista
from pysap.plugins.mri.numerics.reconstruct import sparse_rec_condatvu
from pysap.plugins.mri.numerics.utils import generate_operators
from pysap.plugins.mri.numerics.utils import convert_mask_to_locations

# Third party import
import numpy as np
Expand Down
12 changes: 6 additions & 6 deletions examples/mri/dictionary_learning_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# Package import
import pysap
from pysap.data import get_sample_data
from pysap.numerics.fourier import FFT2
from pysap.numerics.gradient import GradAnalysis2
from pysap.numerics.reconstruct import sparse_rec_condatvu
from pysap.numerics.proximity import Threshold
from pysap.numerics.utils import convert_mask_to_locations
from pysap.numerics.cost import DualGapCost
from mri.numerics.fourier import FFT2
from mri.numerics.gradient import GradAnalysis2
from mri.numerics.reconstruct import sparse_rec_condatvu
from mri.numerics.proximity import Threshold
from mri.numerics.utils import convert_mask_to_locations
from mri.numerics.cost import DualGapCost
from pysap.plugins.mri.dictionary_learning.utils import learn_dictionary
from pysap.plugins.mri.dictionary_learning.utils import min_max_normalize
from pysap.plugins.mri.dictionary_learning.linear import DictionaryLearning
Expand Down
8 changes: 4 additions & 4 deletions examples/mri/gridsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

# Package import
from pysap.data import get_sample_data
from pysap.numerics.gridsearch import grid_search
from pysap.numerics.reconstruct import sparse_rec_condatvu
from pysap.numerics.reconstruct import sparse_rec_fista
from pysap.numerics.utils import convert_mask_to_locations
from mri.numerics.gridsearch import grid_search
from mri.numerics.reconstruct import sparse_rec_condatvu
from mri.numerics.reconstruct import sparse_rec_fista
from mri.numerics.utils import convert_mask_to_locations


#############################################################################
Expand Down
10 changes: 5 additions & 5 deletions examples/mri/non_cartesian_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# Package import
import pysap
from pysap.data import get_sample_data
from pysap.numerics.fourier import NFFT
from pysap.numerics.reconstruct import sparse_rec_fista
from pysap.numerics.reconstruct import sparse_rec_condatvu
from pysap.numerics.utils import generate_operators
from pysap.numerics.utils import convert_mask_to_locations
from mri.numerics.fourier import NFFT
from mri.numerics.reconstruct import sparse_rec_fista
from mri.numerics.reconstruct import sparse_rec_condatvu
from mri.numerics.utils import generate_operators
from mri.numerics.utils import convert_mask_to_locations

# Third party import
import numpy as np
Expand Down
16 changes: 8 additions & 8 deletions examples/mri/p_mri_cartesian_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
# Package import
import pysap
from pysap.data import get_sample_data
from pysap.numerics.linear import Wavelet2
from pysap.numerics.fourier import FFT2
from pysap.numerics.reconstruct import sparse_rec_fista
from pysap.numerics.reconstruct import sparse_rec_condatvu
from pysap.numerics.utils import convert_mask_to_locations
from pysap.numerics.utils import convert_locations_to_mask
from pysap.numerics.gradient import Gradient_pMRI
from pysap.numerics.proximity import Threshold
from mri.numerics.linear import Wavelet2
from mri.numerics.fourier import FFT2
from mri.numerics.reconstruct import sparse_rec_fista
from mri.numerics.reconstruct import sparse_rec_condatvu
from mri.numerics.utils import convert_mask_to_locations
from mri.numerics.utils import convert_locations_to_mask
from mri.numerics.gradient import Gradient_pMRI
from mri.numerics.proximity import Threshold

# Third party import
import numpy as np
Expand Down
12 changes: 6 additions & 6 deletions examples/mri/p_mri_non_cartesian_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
# Package import
import pysap
from pysap.data import get_sample_data
from pysap.numerics.linear import Wavelet2
from pysap.numerics.fourier import NFFT
from pysap.numerics.reconstruct import sparse_rec_fista
from pysap.numerics.reconstruct import sparse_rec_condatvu
from pysap.numerics.gradient import Gradient_pMRI
from pysap.numerics.proximity import Threshold
from mri.numerics.linear import Wavelet2
from mri.numerics.fourier import NFFT
from mri.numerics.reconstruct import sparse_rec_fista
from mri.numerics.reconstruct import sparse_rec_condatvu
from mri.numerics.gradient import Gradient_pMRI
from mri.numerics.proximity import Threshold
from pysap.plugins.mri.parallel_mri.extract_sensitivity_maps import (
extract_k_space_center_and_locations, get_Smaps)
from pysap.plugins.mri.reconstruct.utils import normalize_frequency_locations
Expand Down
81 changes: 81 additions & 0 deletions pysap/base/plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
##########################################################################
# pySAP - Copyright (C) CEA, 2017 - 2019
# Distributed under the terms of the CeCILL-B license, as published by
# the CEA-CNRS-INRIA. Refer to the LICENSE file or to
# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
# for details.
##########################################################################

# System import
import sys
import re
import os
import imp


class PluginsMetaImportHook(object):
""" A class that import a module like normal except for the plugins that
monted on the pysap plugins module. The return value from the hack call
is put into sys.modules.
"""
def __init__(self):
self.module = None

def find_module(self, name, path=None):
""" This method is called by Python if this class is on sys.path.
'name' is the fully-qualified name of the module to look for, and
'path' is either __path__ (for submodules and subpackages) or None (for
a top-level module/package).
Note that this method will be called every time an import statement
is detected (or __import__ is called), before Python's built-in
package/module-finding code kicks in.
"""
# Use this loader only on registered modules
if re.match("pysap.plugins..*", name) is None:
return None
name = name.replace("pysap.plugins.", "")
if (len(name.split(".")) == 1):
path = None

# Get parent module and associated sub module names
self.sub_name = name.split(".")[-1]
self.mod_name = name.rpartition(".")[0]

# Find the sub module and build the module path
try:
self.file, self.filename, self.stuff = imp.find_module(
self.sub_name, path)
self.path = [self.filename]
except ImportError:
return None

# Return The loader, here the object itself
return self

def load_module(self, name):
""" This method is called by Python if PluginsMetaImportHook
'find_module' does not return None. 'name' is the fully-qualified name
of the module/package that was requested.
"""
# Load the module
module = imp.load_module(name, self.file, self.filename,
self.stuff)
if self.file:
self.file.close()

# Update the module required information
module.__path__ = self.path
module.__loader__ = self
module.__package__ = name
module.__name__ = name
if self.stuff[0] == ".py":
module.__file__ = self.path[0]
else:
module.__file__ = os.path.join(self.path[0], "__init__.py")

return module


sys.meta_path.insert(0, PluginsMetaImportHook())
5 changes: 3 additions & 2 deletions pysap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def _check_python_versions():
raise ValueError("'{0}' dependency no formatted correctly.".format(
dependency))
mod_name, mod_min_version = dependency.split(operator)
if mod_name == "progressbar2":
mod_name = "progressbar"
mod_name = mod_name.replace("pysap-", "")
if mod_name == "PyWavelets":
mod_name = "pywt"
try:
mod_install_version = importlib.import_module(mod_name).__version__
except:
Expand Down
15 changes: 9 additions & 6 deletions pysap/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@
VERSION = __version__
PROVIDES = ["pysap"]
REQUIRES = [
"scipy>=1.0.0",
"scipy>=0.18.0",
"numpy>=1.11.0",
"matplotlib>=2.1.2",
"matplotlib>=2.0.0",
"future>=0.16.0",
"astropy==2.0.8",
"nibabel>=2.1.0",
"pyqtgraph>=0.10.0",
"progressbar2>=3.34.3",
"modopt>=1.1.5",
"scikit-learn>=0.19.1",
"PyWavelets>=1.0.0"
"PyWavelets>=1.0.0",
"pysap-mri==0.0.0",
"pysap-astro==0.0.0"
]
DEPENDENCY_LINKS = [
"git+https://github.com/CEA-COSMIC/pysap-mri.git#egg=pysap-mri-0.0.0",
"git+https://github.com/CEA-COSMIC/pysap-astro.git#egg=pysap-astro-0.0.0",
]
EXTRA_REQUIRES = {
"gui": {
Expand Down
11 changes: 0 additions & 11 deletions pysap/numerics/__init__.py

This file was deleted.

15 changes: 0 additions & 15 deletions pysap/numerics/cost.py

This file was deleted.

17 changes: 0 additions & 17 deletions pysap/numerics/fourier.py

This file was deleted.

17 changes: 0 additions & 17 deletions pysap/numerics/gradient.py

This file was deleted.

15 changes: 0 additions & 15 deletions pysap/numerics/gridsearch.py

This file was deleted.

16 changes: 0 additions & 16 deletions pysap/numerics/linear.py

This file was deleted.

15 changes: 0 additions & 15 deletions pysap/numerics/proximity.py

This file was deleted.

Loading

0 comments on commit d5a1293

Please sign in to comment.