diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2eb8d0f..53b55cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,16 +9,17 @@ phonemizer-build: - conda create --name phonemizer-ci python=3 2> /dev/null || true - conda activate phonemizer-ci - # install the phonemizer - - pip install coverage - - python setup.py build + # install dependencies for testing + - pip install --upgrade pytest coverage + + # install phonemizer - python setup.py install .phonemizer-test: &phonemizer-test # run the unit tests within the CI environment - conda activate phonemizer-ci - phonemize --version -- python setup.py test +- coverage run && coverage report phonemizer-test-espeak-1-48-04: stage: test diff --git a/.travis.yml b/.travis.yml index 6e26c6e..05cc9ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,15 +20,15 @@ before_install: install: - pip install --upgrade pip - - pip install pytest-cov codecov joblib segments - - python setup.py build - python setup.py install + - pip install --upgrade pytest coverage codecov script: - phonemize --version - - python setup.py test + - pytest after_success: + - coverage run - codecov cache: diff --git a/CHANGELOG.md b/CHANGELOG.md index b02ecb5..4b25823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ Version numbers follow [semantic versioning](https://semver.org) +## not yet released + +* **bugfixes** + + Fixed installation from source (bug introduced in 2.2.1, see + issue [#52](https://github.com/bootphon/phonemizer/issues/52). + ## phonemizer-2.2.1 * **improvements** diff --git a/Dockerfile b/Dockerfile index 97667f3..ab0bad6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use this file to build a docker image of phonemizer (using -# festival-2.5 and espeak-ng-1.49.2 from ubuntu repo): +# festival-2.5.0 and espeak-ng-1.50 from ubuntu repo): # # sudo docker build -t phonemizer . # @@ -12,11 +12,11 @@ # Use an official Ubuntu as a parent image -FROM ubuntu:18.04 +FROM ubuntu:20.04 ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 -# Set the working directory to /phonemizer +# set the working directory to /phonemizer WORKDIR /phonemizer # install dependencies @@ -30,15 +30,17 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y \ python3-pip && \ apt-get clean -# Pytest needs to be installed through pip to make sure we have a recent version -RUN pip3 install pytest pytest-cov +# pytest needs to be installed through pip to make sure we have a recent version +RUN pip3 install pytest -# Tests expect python to be available as executable 'python' not 'python3' +# tests expect python to be available as executable 'python' not 'python3' RUN ln -s /usr/bin/python3 /usr/bin/python +# copy the phonemizer code within the docker image +COPY . /phonemizer + # install phonemizer and run the tests -RUN git clone https://github.com/bootphon/phonemizer.git && \ - cd phonemizer && \ +RUN cd /phonemizer && \ python3 setup.py install && \ phonemize --version && \ python3 -m pytest -v test diff --git a/README.md b/README.md index 147583c..6457f16 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,7 @@ the phonemizer. $ git clone https://github.com/bootphon/phonemizer $ cd phonemizer - $ python setup.py build $ [sudo] python setup.py install - $ python setup.py test # optionally run the tests If you experiment an error such as `ImportError: No module named setuptools` during installation, refeer to [issue @@ -89,6 +87,15 @@ Then run an interactive session with: $ sudo docker run -it phonemizer /bin/bash +### Testing + +When installed from sources or whithin a Docker image, you can run the tests +suite from the root `phonemizer` folder (once you installed `pytest`): + + $ pip install pytest + $ pytest + + ## Python usage In Python import the `phonemize` function with `from phonemizer import diff --git a/phonemizer/__init__.py b/phonemizer/__init__.py index 217f81d..73e4224 100644 --- a/phonemizer/__init__.py +++ b/phonemizer/__init__.py @@ -14,6 +14,21 @@ # along with phonologizer. If not, see . """Multilingual text to phones converter""" -from .phonemize import phonemize __version__ = '2.2.1' + + +try: # pragma: nocover + # This variable is injected in the __builtins__ by the build process. In + # that case we don't want to import phonemize as there are missing + # dependencies. + __PHONEMIZER_SETUP__ +except NameError: + __PHONEMIZER_SETUP__ = False + + +if __PHONEMIZER_SETUP__: # pragma: nocover + import sys + sys.stderr.write('Partial import of phonemizer during the build process.\n') +else: + from .phonemize import phonemize diff --git a/setup.cfg b/setup.cfg index 427cf1d..a09d993 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,15 +1,22 @@ -[aliases] -test=pytest - [tool:pytest] -addopts = --verbose --doctest-modules --cov=phonemizer --cov-report=html --cov-report=term:skip-covered +minversion = 5.0 testpaths = test python_files = test/*.py +filterwarnings = + # ignore some deprecation warnings (on regexp escape sequence) for segments + # module and its dependencies + ignore::DeprecationWarning:.*segments.* + ignore::DeprecationWarning:.*csvw.* + ignore::DeprecationWarning:.*clldutils.* [build_sphinx] source-dir = doc/source build-dir = doc/build +[coverage:run] +command_line = -m pytest +source = phonemizer + [coverage:report] exclude_lines = pragma: nocover diff --git a/setup.py b/setup.py index 153046b..954015a 100755 --- a/setup.py +++ b/setup.py @@ -16,10 +16,20 @@ # along with phonemizer. If not, see . """Setup script for the phonemizer package""" +import builtins import codecs import setuptools + + +# This is a bit hackish: we are setting a global variable so that the main +# phonemizer __init__ can detect if it is being loaded by the setup routine, to +# avoid attempting to load components that aren't built yet. +builtins.__PHONEMIZER_SETUP__ = True + + import phonemizer + setuptools.setup( # general description name='phonemizer', @@ -28,8 +38,6 @@ # python package dependancies install_requires=['joblib', 'segments', 'attrs>=18.1'], - setup_requires=['pytest-runner'], - tests_require=['pytest', 'pytest-cov'], # include Python code and any files in phonemizer/share packages=setuptools.find_packages(),