diff --git a/.gitignore b/.gitignore index 9075048..663482c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ README.html __pycache__ VERSION Dockerfile-* -Dockerfile \ No newline at end of file +Dockerfile +senpy_data \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7999828..be9bfbe 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,12 +7,14 @@ stages: - test - publish + - test_image - deploy variables: KUBENS: senpy LATEST_IMAGE: "${HUB_REPO}:${CI_COMMIT_SHORT_SHA}" SENPY_DATA: "/senpy-data/" # This is configured in the CI job + NLTK_DATA: "/senpy-data/nltk" # Store NLTK downloaded data docker: stage: publish @@ -51,18 +53,30 @@ docker-latest: refs: - master +testimage: + tags: + - docker + stage: test_image + image: "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" + script: + - python -m senpy --no-run --test + testpy37: tags: - docker + variables: + SENPY_STRICT: "false" image: python:3.7 stage: test script: - - pip install -r requirements.txt -r test-requirements.txt -r extra-requirements.txt + - pip install -r requirements.txt -r test-requirements.txt - python setup.py test testpy310: tags: - docker + variables: + SENPY_STRICT: "true" image: python:3.10 stage: test script: @@ -74,7 +88,7 @@ push_pypi: - tags tags: - docker - image: python:3.7 + image: python:3.10 stage: publish script: - echo $CI_COMMIT_TAG > senpy/VERSION @@ -87,7 +101,7 @@ check_pypi: - tags tags: - docker - image: python:3.7 + image: python:3.10 stage: deploy script: - pip install senpy==$CI_COMMIT_TAG diff --git a/README.rst b/README.rst index 918e059..9bc9ccf 100644 --- a/README.rst +++ b/README.rst @@ -58,7 +58,7 @@ Its code is pure Python, and the only limitations are imposed by its dependencie Currently, the CI/CD pipeline tests the code on: -* GNU/Linux with Python versions 3.4, 3.5, 3.6 and 3.7 +* GNU/Linux with Python versions 3.7+ (3.10+ recommended for all plugins) * MacOS and homebrew's python3 * Windows 10 and chocolatey's python3 diff --git a/extra-requirements.txt b/extra-requirements.txt index 748ccf8..79ac7ea 100644 --- a/extra-requirements.txt +++ b/extra-requirements.txt @@ -2,5 +2,5 @@ gsitk>0.1.9.1 flask_cors==3.0.10 Pattern==3.6 lxml==4.9.3 -pandas~=2 +pandas==2.1.1 textblob==0.17.1 diff --git a/senpy/__main__.py b/senpy/__main__.py index 4b9e920..d063297 100644 --- a/senpy/__main__.py +++ b/senpy/__main__.py @@ -23,6 +23,7 @@ from flask import Flask from senpy.extensions import Senpy from senpy.utils import easy_test from senpy.plugins import list_dependencies +from senpy import config import logging import os @@ -95,7 +96,7 @@ def main(): parser.add_argument( '--strict', action='store_true', - default=False, + default=config.strict, help='Fail if optional plugins cannot be loaded.') parser.add_argument( '--test', diff --git a/senpy/config.py b/senpy/config.py new file mode 100644 index 0000000..f3a3674 --- /dev/null +++ b/senpy/config.py @@ -0,0 +1,7 @@ +import os + +strict = os.environ.get('SENPY_STRICT', '').lower() not in ["", "false", "f"] +data_folder = os.environ.get('SENPY_DATA', None) +if data_folder: + data_folder = os.path.abspath(data_folder) +testing = os.environ.get('SENPY_TESTING', "") != "" diff --git a/senpy/plugins/__init__.py b/senpy/plugins/__init__.py index dd1a3b6..d78c97a 100644 --- a/senpy/plugins/__init__.py +++ b/senpy/plugins/__init__.py @@ -46,6 +46,7 @@ from .. import models, utils from .. import api from .. import gsitk_compat from .. import testing +from .. import config logger = logging.getLogger(__name__) @@ -75,7 +76,7 @@ class PluginMeta(models.BaseMeta): cls = super(PluginMeta, mcs).__new__(mcs, name, bases, attrs) if alias in mcs._classes: - if os.environ.get('SENPY_TESTING', ""): + if config.testing: raise Exception( ('The type of plugin {} already exists. ' 'Please, choose a different name').format(name)) @@ -123,7 +124,7 @@ class Plugin(with_metaclass(PluginMeta, models.Plugin)): os.path.dirname(inspect.getfile(self.__class__))) if not data_folder: - data_folder = os.environ['SENPY_DATA'] + data_folder = config.data_folder if not data_folder: data_folder = os.getcwd() diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 6fa98b6..2760e0f 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -27,6 +27,7 @@ from senpy.models import Results, Entry, EmotionSet, Emotion, Plugins from senpy import plugins from senpy.plugins.postprocessing.emotion.centroids import CentroidConversion from senpy.gsitk_compat import GSITK_AVAILABLE +from senpy import config import pandas as pd @@ -386,7 +387,7 @@ class PluginsTest(TestCase): def make_mini_test(fpath): def mini_test(self): - for plugin in plugins.from_path(fpath, install=True): + for plugin in plugins.from_path(fpath, install=True, strict=config.strict): plugin.test() return mini_test