mirror of
				https://github.com/gsi-upm/senpy
				synced 2025-11-04 09:18:16 +00:00 
			
		
		
		
	Fix installation
* Remove '--use-wheel' flag * Remove pip dependency * Make GSITK an optional dependency
This commit is contained in:
		@@ -21,8 +21,8 @@ ONBUILD WORKDIR /senpy-plugins/
 | 
			
		||||
 | 
			
		||||
WORKDIR /usr/src/app
 | 
			
		||||
COPY test-requirements.txt requirements.txt /usr/src/app/
 | 
			
		||||
RUN pip install --no-cache-dir --use-wheel -r test-requirements.txt -r requirements.txt
 | 
			
		||||
RUN pip install --no-cache-dir -r test-requirements.txt -r requirements.txt
 | 
			
		||||
COPY . /usr/src/app/
 | 
			
		||||
RUN pip install --no-cache-dir --no-index --no-deps --editable .
 | 
			
		||||
RUN pip install --no-cache-dir --editable '/usr/src/app[evaluation]'
 | 
			
		||||
 | 
			
		||||
ENTRYPOINT ["python", "-m", "senpy", "-f", "/senpy-plugins/", "--host", "0.0.0.0"]
 | 
			
		||||
 
 | 
			
		||||
@@ -17,15 +17,19 @@ import copy
 | 
			
		||||
import errno
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from gsitk.datasets.datasets import DatasetManager
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    from gsitk.datasets.datasets import DatasetManager
 | 
			
		||||
    GSITK_AVAILABLE = True
 | 
			
		||||
except ImportError:
 | 
			
		||||
    logger.warn('GSITK is not installed. Some functions will be unavailable.')
 | 
			
		||||
    GSITK_AVAILABLE = False
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Senpy(object):
 | 
			
		||||
    """ Default Senpy extension for Flask """
 | 
			
		||||
 | 
			
		||||
    def __init__(self,
 | 
			
		||||
                 app=None,
 | 
			
		||||
                 plugin_folder=".",
 | 
			
		||||
@@ -44,7 +48,6 @@ class Senpy(object):
 | 
			
		||||
 | 
			
		||||
        self._default = None
 | 
			
		||||
        self._plugins = {}
 | 
			
		||||
        self._dm = DatasetManager()
 | 
			
		||||
        if plugin_folder:
 | 
			
		||||
            self.add_folder(plugin_folder)
 | 
			
		||||
 | 
			
		||||
@@ -200,13 +203,17 @@ class Senpy(object):
 | 
			
		||||
                raise Error(
 | 
			
		||||
                    status=404,
 | 
			
		||||
                    message="The dataset '{}' is not valid".format(dataset))
 | 
			
		||||
        datasets = self._dm.prepare_datasets(datasets_name)
 | 
			
		||||
        dm = DatasetManager()
 | 
			
		||||
        datasets = dm.prepare_datasets(datasets_name)
 | 
			
		||||
        return datasets
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def datasets(self):
 | 
			
		||||
        if not GSITK_AVAILABLE:
 | 
			
		||||
            raise Exception('GSITK is not available. Install it to use this function.')
 | 
			
		||||
        self._dataset_list = {}
 | 
			
		||||
        for item in self._dm.get_datasets():
 | 
			
		||||
        dm = DatasetManager()
 | 
			
		||||
        for item in dm.get_datasets():
 | 
			
		||||
            for key in item:
 | 
			
		||||
                if key in self._dataset_list:
 | 
			
		||||
                    continue
 | 
			
		||||
@@ -216,7 +223,8 @@ class Senpy(object):
 | 
			
		||||
        return self._dataset_list
 | 
			
		||||
 | 
			
		||||
    def evaluate(self, params):
 | 
			
		||||
 | 
			
		||||
        if not GSITK_AVAILABLE:
 | 
			
		||||
            raise Exception('GSITK is not available. Install it to use this function.')
 | 
			
		||||
        logger.debug("evaluating request: {}".format(params))
 | 
			
		||||
        results = AggregatedEvaluation()
 | 
			
		||||
        results.parameters = params
 | 
			
		||||
 
 | 
			
		||||
@@ -19,16 +19,22 @@ import importlib
 | 
			
		||||
import yaml
 | 
			
		||||
import threading
 | 
			
		||||
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
from .. import models, utils
 | 
			
		||||
from .. import api
 | 
			
		||||
 | 
			
		||||
from gsitk.evaluation.evaluation import Evaluation as Eval
 | 
			
		||||
from sklearn.pipeline import Pipeline
 | 
			
		||||
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    from gsitk.evaluation.evaluation import Evaluation as Eval
 | 
			
		||||
    from sklearn.pipeline import Pipeline
 | 
			
		||||
    GSITK_AVAILABLE = True
 | 
			
		||||
except ImportError:
 | 
			
		||||
    logger.warn('GSITK is not installed. Some functions will be unavailable.')
 | 
			
		||||
    GSITK_AVAILABLE = False
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PluginMeta(models.BaseMeta):
 | 
			
		||||
    _classes = {}
 | 
			
		||||
@@ -461,7 +467,7 @@ def install_deps(*plugins):
 | 
			
		||||
    for info in plugins:
 | 
			
		||||
        requirements = info.get('requirements', [])
 | 
			
		||||
        if requirements:
 | 
			
		||||
            pip_args = [sys.executable, '-m', 'pip', 'install', '--use-wheel']
 | 
			
		||||
            pip_args = [sys.executable, '-m', 'pip', 'install']
 | 
			
		||||
            for req in requirements:
 | 
			
		||||
                pip_args.append(req)
 | 
			
		||||
            logger.info('Installing requirements: ' + str(requirements))
 | 
			
		||||
@@ -586,6 +592,9 @@ def _from_loaded_module(module, info=None, **kwargs):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def evaluate(plugins, datasets, **kwargs):
 | 
			
		||||
    if not GSITK_AVAILABLE:
 | 
			
		||||
        raise Exception('GSITK is not available. Install it to use this function.')
 | 
			
		||||
 | 
			
		||||
    ev = Eval(tuples=None,
 | 
			
		||||
              datasets=datasets,
 | 
			
		||||
              pipelines=[plugin.as_pipe() for plugin in plugins])
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								setup.py
									
									
									
									
									
								
							@@ -1,24 +1,20 @@
 | 
			
		||||
import pip
 | 
			
		||||
from setuptools import setup
 | 
			
		||||
# parse_requirements() returns generator of pip.req.InstallRequirement objects
 | 
			
		||||
from pip.req import parse_requirements
 | 
			
		||||
 | 
			
		||||
with open('senpy/VERSION') as f:
 | 
			
		||||
    __version__ = f.read().strip()
 | 
			
		||||
    assert __version__
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    install_reqs = parse_requirements(
 | 
			
		||||
        "requirements.txt", session=pip.download.PipSession())
 | 
			
		||||
    test_reqs = parse_requirements(
 | 
			
		||||
        "test-requirements.txt", session=pip.download.PipSession())
 | 
			
		||||
except AttributeError:
 | 
			
		||||
 | 
			
		||||
def parse_requirements(filename):
 | 
			
		||||
    """ load requirements from a pip requirements file """
 | 
			
		||||
    with open(filename, 'r') as f:
 | 
			
		||||
        lineiter = list(line.strip() for line in f)
 | 
			
		||||
    return [line for line in lineiter if line and not line.startswith("#")]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
install_reqs = parse_requirements("requirements.txt")
 | 
			
		||||
test_reqs = parse_requirements("test-requirements.txt")
 | 
			
		||||
 | 
			
		||||
install_reqs = [str(ir.req) for ir in install_reqs]
 | 
			
		||||
test_reqs = [str(ir.req) for ir in test_reqs]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
setup(
 | 
			
		||||
    name='senpy',
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user