From 4a1fec8328d204aa4de6c1b4b4a4be0867bdfcf1 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 2 Mar 2017 22:27:06 -0800 Subject: [PATCH] Improvements to macOS test and work on homebrew tap autobrew Squashed commits: [3f06c1e] Try setting up homebrew tap autobuilding [01532f1] Strict mode error in brew --- .gitignore | 5 ++++ .travis.yml | 44 +++++++++++++++++---------------- .travis/linux_before_install.sh | 22 +++++++++++++++++ .travis/osx_before_install.sh | 14 +++++++++++ tests/conftest.py | 10 ++++++++ tests/test_main.py | 4 +++ 6 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 .travis/linux_before_install.sh create mode 100644 .travis/osx_before_install.sh diff --git a/.gitignore b/.gitignore index 6cfcc451..63265f5b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ venv*/ pyvenv.cfg tasks.py +.bash_history +.ruffus_history.sqlite # Package building *.egg-info/ @@ -27,8 +29,11 @@ htmlcov/ # Testing log/ /*.pdf +/*.qdf +*.ipynb .ipynb_checkpoints/ tests/cache/ tests/output/ tests/resources/private/ tmp/ +pdfbox-app*.jar \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index e287d3a7..a3a78740 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -sudo: required dist: trusty language: python cache: @@ -6,33 +5,36 @@ cache: directories: - packages - tests/cache + - $HOME/Library/Caches/Homebrew -python: -- '3.4' -- '3.5' -- '3.6' - -os: -- linux +matrix: + include: + - os: linux + sudo: required + language: python + python: 3.4 + - os: linux + sudo: required + language: python + python: 3.5 + - os: linux + sudo: required + language: python + python: 3.6 + - os: osx + osx_image: xcode8 + language: generic before_cache: - rm -f $HOME/.cache/pip/log/debug.log before_install: -- sudo add-apt-repository ppa:vshn/ghostscript -y -- sudo add-apt-repository ppa:heyarje/libav-11 -y -- sudo apt-get update -qq -- sudo apt-get install -y ghostscript tesseract-ocr tesseract-ocr-deu tesseract-ocr-eng - tesseract-ocr-fra qpdf poppler-utils libavformat56 libavcodec56 libavutil54 libffi-dev -- pip install --upgrade pip -- mkdir -p packages -- "[ -f packages/unpaper_6.1-1.deb ] || wget -q https://dl.dropboxusercontent.com/u/28971240/unpaper_6.1-1.deb - -O packages/unpaper_6.1-1.deb" -- sudo dpkg -i packages/unpaper_6.1-1.deb +- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then bash .travis/linux_before_install.sh ; fi +- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then bash .travis/osx_before_install.sh ; fi install: -- pip install . -- pip install -r requirements.txt -r test_requirements.txt +- pip3 install . +- pip3 install -r requirements.txt -r test_requirements.txt script: - mv ocrmypdf dont_import_this_ocrmypdf @@ -51,5 +53,5 @@ deploy: on: branch: master tags: true - condition: $TRAVIS_PYTHON_VERSION = "3.6" + condition: $TRAVIS_PYTHON_VERSION == "3.6" && $TRAVIS_OS_NAME == "linux" skip_upload_docs: true diff --git a/.travis/linux_before_install.sh b/.travis/linux_before_install.sh new file mode 100644 index 00000000..8d48c35b --- /dev/null +++ b/.travis/linux_before_install.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +sudo add-apt-repository ppa:vshn/ghostscript -y +sudo add-apt-repository ppa:heyarje/libav-11 -y +sudo apt-get update -qq +sudo apt-get install -y \ + ghostscript \ + tesseract-ocr \ + tesseract-ocr-deu \ + tesseract-ocr-eng \ + tesseract-ocr-fra \ + qpdf \ + poppler-utils \ + libavformat56 \ + libavcodec56 \ + libavutil54 \ + libffi-dev + +pip install --upgrade pip +mkdir -p packages +[ -f packages/unpaper_6.1-1.deb ] || wget -q https://dl.dropboxusercontent.com/u/28971240/unpaper_6.1-1.deb -O packages/unpaper_6.1-1.deb +sudo dpkg -i packages/unpaper_6.1-1.deb \ No newline at end of file diff --git a/.travis/osx_before_install.sh b/.travis/osx_before_install.sh new file mode 100644 index 00000000..876c019d --- /dev/null +++ b/.travis/osx_before_install.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +brew update + +brew install libpng openjpeg jbig2dec libtiff # image libraries +brew install qpdf +brew install ghostscript +brew install python3 +brew install libxml2 libffi leptonica +brew install unpaper # optional +brew install tesseract + +pip3 install --upgrade pip +pip3 install wheel \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 15ff0aac..f30af4e1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,6 +22,11 @@ def is_linux(): return platform.system() == 'Linux' +@pytest.helpers.register +def is_macos(): + return platform.system() == 'Darwin' + + @pytest.helpers.register def running_in_docker(): # Docker creates a file named /.dockerenv (newer versions) or @@ -29,6 +34,11 @@ def running_in_docker(): return os.path.exists('/.dockerenv') or os.path.exists('/.dockerinit') +@pytest.helpers.register +def running_in_travis(): + return os.environ.get('TRAVIS') == 'true' + + TESTS_ROOT = os.path.abspath(os.path.dirname(__file__)) SPOOF_PATH = os.path.join(TESTS_ROOT, 'spoof') PROJECT_ROOT = os.path.dirname(TESTS_ROOT) diff --git a/tests/test_main.py b/tests/test_main.py index f986fe4d..0931828a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -409,10 +409,14 @@ def test_force_ocr_on_pdf_with_no_images(spoof_tesseract_crash, resources, assert not os.path.exists(no_outpdf) +@pytest.mark.skipif( + pytest.helpers.is_macos() and pytest.helpers.running_in_travis(), + reason="takes too long to install language packs in Travis macOS homebrew") def test_french(spoof_tesseract_cache, resources, outpdf): p, out, err = run_ocrmypdf( resources / 'francais.pdf', outpdf, '-l', 'fra', env=spoof_tesseract_cache) + print(os.environ) assert p.returncode == ExitCode.ok, \ "This test may fail if Tesseract language packs are missing"