diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4dd94df..94c43ad7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,10 @@ jobs: python-version: [3.10.8, 3.11, 3.12] install_variant: ["pip"] include: - - python-version: 3.10.8 - install_variant: "rpm.fedora.34" - - python-version: 3.7 - install_variant: "deb.ubuntu.focal" + - python-version: 3.12 + install_variant: "rpm.fedora.40" + - python-version: 3.12 + install_variant: "deb.ubuntu.noble" fail-fast: false steps: @@ -56,7 +56,7 @@ jobs: # vncdotool sudo apt-get -y install xfonts-base x11vnc # pyautogui - sudo apt-get -y install scrot + sudo apt-get -y install gnome-screenshot if: matrix.install_variant == 'pip' - name: Install any dependencies and build the package run: pip --default-timeout=60 install -r packaging/pip_requirements.txt @@ -74,13 +74,14 @@ jobs: sleep 3 - name: Run current semi-isolation semi-integration tests (to be separated in the future) run: | - if [[ ${{ matrix.python-version }} == '3.10.8' ]]; then export DISABLE_AUTOPY=1; fi - if [[ ${{ matrix.python-version }} == '3.11' ]]; then export DISABLE_AUTOPY=1; fi - if [[ ${{ matrix.python-version }} == '3.12' ]]; then export DISABLE_AUTOPY=1; fi - if [[ ${{ matrix.install_variant }} != "pip" ]]; then cd packaging && bash packager_docker.sh; + if [[ "${{ matrix.python-version }}" == "3.10.8" ]]; then export DISABLE_AUTOPY=1; fi + if [[ "${{ matrix.python-version }}" == "3.11" ]]; then export DISABLE_AUTOPY=1; fi + if [[ "${{ matrix.python-version }}" == "3.12" ]]; then export DISABLE_AUTOPY=1; fi + if [[ "${{ matrix.install_variant }}" != "pip" ]]; then cd packaging && bash packager_docker.sh; else cd tests && bash coverage_analysis.sh; fi env: INSTALL_VARIANT: ${{ matrix.install_variant }} + TESSDATA_PREFIX: /usr/share/tesseract-ocr/4.00/tessdata/ - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: diff --git a/packaging/packager_deb.sh b/packaging/packager_deb.sh index 0fd33adf..263f67e5 100644 --- a/packaging/packager_deb.sh +++ b/packaging/packager_deb.sh @@ -5,46 +5,58 @@ readonly distro="${DISTRO:-ubuntu}" readonly distro_version="${VERSION:-xenial}" readonly distro_root="${ROOT:-$HOME}" -# deb dependencies export DEBIAN_FRONTEND=noninteractive apt-get update -# python3 -apt-get -y install python3 python3-coverage -# python-imaging -apt-get -y install python3-pil -# pip dependencies (for dependencies not available as DEB) +echo "------------- python3 -------------" +apt-get -y install python3 python3-venv +echo "----- pip dependencies (for dependencies not available as DEB) -----" apt-get -y install gcc libx11-dev libxtst-dev python3-dev libpng-dev python3-pip +echo "----- create a venv to use that as the python env (needed for python 3.12 compatibility specific to Ubuntu) -----" +python3 -m venv docker_venv --system-site-packages +source docker_venv/bin/activate +echo "------------- upgrade pip -------------" pip3 install --upgrade pip -# contour, template, feature, cascade, text matching +echo "------------ install coverage ------------" +pip3 install coverage + +echo "------------- python-imaging -------------" +apt-get -y install python3-pil + +echo "------------- contour, template, feature, and cascade matching -------------" apt-get -y install python3-numpy if [[ $distro_version == "xenial" ]]; then export DISABLE_OPENCV=1 else apt-get -y install python3-opencv fi -# text matching + +echo "------------- text matching -------------" if [[ $distro_version == "xenial" ]]; then export DISABLE_OCR=1 else apt-get -y install tesseract-ocr libtesseract-dev apt-get -y install g++ pkg-config - pip3 install pytesseract==0.3.4 tesserocr==2.5.1 + pip3 install pytesseract==0.3.13 tesserocr==2.7.1 +fi + +echo "------------- deep learning -------------" +pip3 install torch==2.2.0 torchvision==0.17.0 + +echo "------------- display controlling -------------" +if [[ -n "$DISABLE_AUTOPY" && "$DISABLE_AUTOPY" == "1" ]]; then + export DISABLE_AUTOPY=1 +else + pip3 install autopy fi -# deep learning -pip3 install torch==1.8.1 torchvision==0.9.1 -# screen controlling -pip3 install autopy==4.0.0 -# TODO: vncdotool doesn't control its Twisted which doesn't control its "incremental" dependency -pip3 install incremental==22.10.0 pip3 install vncdotool==0.12.0 apt-get -y install xdotool x11-apps imagemagick -apt-get -y install python3-tk scrot -# TODO: install PyScreeze separately to replace the one PyAutoGUI will install which is incompatible with the current Pillow version -pip3 install pyscreeze==0.1.28 -pip3 install pyautogui==0.9.53 +# NOTE: Must install tkinter here to use MouseInfo +apt-get -y install python3-tk +apt-get -y install gnome-screenshot +pip3 install pyautogui==0.9.54 apt-get -y install x11vnc -# deb packaging and installing of current guibot source +echo "------------- deb packaging and installing of current guibot source -------------" apt-get -y install dh-make dh-python debhelper python3-all devscripts NAME=$(sed -n 's/^Package:[ \t]*//p' "$distro_root/guibot/packaging/debian/control") CHANGELOG_REVS=($(sed -n -e 's/^guibot[ \t]*(\([0-9]*.[0-9]*\)-[0-9]*).*/\1/p' "$distro_root/guibot/packaging/debian/changelog")) @@ -56,7 +68,7 @@ cp ../${NAME}_${VERSION}*.deb "$distro_root/guibot" apt-get -y install "$distro_root/guibot/"${NAME}_${VERSION}*.deb rm -fr "$distro_root/$NAME-$VERSION" -# virtual display +echo "------------- virtual display -------------" apt-get -y install xvfb vim-common export DISPLAY=:99.0 Xvfb :99 -screen 0 1024x768x24 &> /tmp/xvfb.log & @@ -64,12 +76,20 @@ touch /root/.Xauthority xauth add ${HOST}:99 . $(xxd -l 16 -p /dev/urandom) sleep 3 # give xvfb some time to start -# unit tests +echo " -------- set tesseract data environment -------- " +export TESSDATA_PREFIX="/usr/share/tesseract-ocr/5/tessdata" +echo "Tesseract data prefix: $TESSDATA_PREFIX" + +echo "------------ dump for environment variables and python path ------------" +printenv +python3 -c "import sys; print(sys.prefix)" + +echo "------------- unit tests -------------" apt-get install -y python3-pyqt5 export XDG_RUNTIME_DIR="/tmp/runtime-root" mkdir /tmp/runtime-root chmod 0700 /tmp/runtime-root cd /usr/lib/python3/dist-packages/guibot/tests -LIBPATH=".." COVERAGE="python3-coverage" sh coverage_analysis.sh +LIBPATH=".." COVERAGE="coverage" sh coverage_analysis.sh exit 0 diff --git a/packaging/packager_docker.sh b/packaging/packager_docker.sh index 9d700e08..8461707a 100644 --- a/packaging/packager_docker.sh +++ b/packaging/packager_docker.sh @@ -7,12 +7,12 @@ readonly version=$(echo $install_variant | cut -d '.' -f 3) if [ "$packager" == "rpm" ]; then sudo docker run \ - -e DISTRO="$distro" -e VERSION="$version" -e ROOT="/" \ + -e DISTRO="$distro" -e VERSION="$version" -e ROOT="/" -e DISABLE_AUTOPY="1" \ -v $(pwd)/..:/guibot:rw $distro:$version \ /bin/bash /guibot/packaging/packager_rpm.sh elif [ "$packager" == "deb" ]; then sudo docker run \ - -e DISTRO="$distro" -e VERSION="$version" -e ROOT="/" \ + -e DISTRO="$distro" -e VERSION="$version" -e ROOT="/" -e DISABLE_AUTOPY="1" \ -v $(pwd)/..:/guibot:rw $distro:$version \ /bin/bash /guibot/packaging/packager_deb.sh fi diff --git a/packaging/packager_rpm.sh b/packaging/packager_rpm.sh index 15646b7f..db63e7de 100644 --- a/packaging/packager_rpm.sh +++ b/packaging/packager_rpm.sh @@ -5,40 +5,43 @@ readonly distro="${DISTRO:-fedora}" readonly distro_version="${VERSION:-30}" readonly distro_root="${ROOT:-$HOME}" -# rpm dependencies -# python3 -dnf -y install python3 python3-coverage -# python-imaging +dnf -y update +echo "------------- python3 -------------" +dnf -y install python3 python3-coverage python3-devel +echo "------------- python-imaging -------------" dnf -y install python3-pillow -# pip dependencies (for dependencies not available as RPM) +echo "------------- pip dependencies (for dependencies not available as RPM) -------------" dnf -y install gcc libX11-devel libXtst-devel python3-devel libpng-devel python3-pip redhat-rpm-config +echo "------------- upgrade pip -------------" pip3 install --upgrade pip -# contour, template, feature, cascade, text matching + +echo "------------- contour, template, feature, and cascade matching -------------" dnf -y install python3-numpy python3-opencv -# text matching + +echo "------------- text matching -------------" dnf -y install tesseract tesseract-devel dnf -y install gcc-c++ -pip3 install pytesseract==0.3.4 tesserocr==2.5.1 -# deep learning -pip3 install torch==1.8.1 torchvision==0.9.1 -# screen controlling -if (( distro_version <= 32 )); then - pip3 install autopy==4.0.0 -else +pip3 install pytesseract==0.3.13 tesserocr==2.7.1 + +echo "------------- deep learning -------------" +dnf -y install python3-torch python3-torch-devel +# TODO: python3-torchvision version available is broken (no module found) +pip3 install torchvision==0.17.0 + +echo "------------- display controlling -------------" +if [[ -n "$DISABLE_AUTOPY" && "$DISABLE_AUTOPY" == "1" && $distro_version -gt 32 ]]; then export DISABLE_AUTOPY=1 +else + pip3 install autopy fi -# TODO: vncdotool doesn't control its Twisted which doesn't control its "incremental" dependency -pip3 install incremental==22.10.0 pip3 install vncdotool==0.12.0 dnf -y install xdotool xwd ImageMagick -# NOTE: PyAutoGUI's scrot dependencies are broken on Fedora 33- so we don't support these -dnf -y install python3-tkinter scrot -# TODO: install PyScreeze separately to replace the one PyAutoGUI will install which is incompatible with the current Pillow version -pip3 install pyscreeze==0.1.28 -pip3 install pyautogui==0.9.53 +# NOTE: No need for installing tkinter here because it's a dependency from torch (it is installed with it) +dnf -y install gnome-screenshot +pip3 install pyautogui==0.9.54 dnf -y install x11vnc -# rpm packaging and installing of current guibot source +echo "------ rpm packaging and installing of current guibot source ------" dnf -y install rpm-build NAME=$(sed -n 's/^Name:[ \t]*//p' "$distro_root/guibot/packaging/guibot.spec") VERSION=$(sed -n 's/^Version:[ \t]*//p' "$distro_root/guibot/packaging/guibot.spec") @@ -50,7 +53,7 @@ cp ~/rpmbuild/RPMS/x86_64/python3-$NAME-$VERSION*.rpm "$distro_root/guibot" dnf -y install "$distro_root/guibot/python3-"$NAME-$VERSION*.rpm rm -fr "$distro_root/$NAME-$VERSION" -# virtual display +echo "------------- virtual display -------------" dnf install -y xorg-x11-server-Xvfb vim-common export DISPLAY=:99.0 Xvfb :99 -screen 0 1024x768x24 &> /tmp/xvfb.log & @@ -58,7 +61,15 @@ touch /root/.Xauthority xauth add ${HOST}:99 . $(xxd -l 16 -p /dev/urandom) sleep 3 # give xvfb some time to start -# unit tests +echo " -------- set tesseract data environment variable -------- " +export TESSDATA_PREFIX="/usr/share/tesseract/tessdata/" +echo "Tesseract data prefix: $TESSDATA_PREFIX" + +echo "------------ dump for environment variables and python path ------------" +printenv +python3 -c "import sys; print(sys.prefix)" + +echo "------------- unit tests -------------" dnf install -y python3-PyQt5 cd /lib/python3*/site-packages/guibot/tests if (( distro_version <= 30 )); then diff --git a/packaging/pip_requirements.txt b/packaging/pip_requirements.txt index 5a4636c0..3352ac4f 100644 --- a/packaging/pip_requirements.txt +++ b/packaging/pip_requirements.txt @@ -5,17 +5,15 @@ Pillow==10.3.0; python_version >= '3.12' # backends autopy==4.0.0; python_version <= '3.8' and platform_python_implementation != "PyPy" # OCR is currently not tested on Windows due to custom Tesseract OCR installers -pytesseract==0.3.4; sys_platform != 'win32' -tesserocr==2.5.1; sys_platform != 'win32' +pytesseract==0.3.13; sys_platform != 'win32' +tesserocr==2.7.1; sys_platform != 'win32' # TODO: OpenCV and PyTorch don't control their "numpy" dependency numpy==1.26.4; platform_python_implementation != "PyPy" opencv-contrib-python==4.5.5.62; platform_python_implementation != "PyPy" torch==2.2.0; 'generic' not in platform_release and platform_python_implementation != "PyPy" torchvision==0.17.0 ; 'generic' not in platform_release and platform_python_implementation != "PyPy" vncdotool==0.12.0; sys_platform != 'win32' and platform_python_implementation != "PyPy" -pyautogui==0.9.53; platform_python_implementation != "PyPy" -# NOTE: These decared version of Pillow has issues with the latest Pyscreeze 0.1.30 thus there is a restrain on Pyscreeze installation -pyscreeze==0.1.28 +pyautogui==0.9.54; platform_python_implementation != "PyPy" # optional proxy guibot interface deps serpent==1.40 diff --git a/tests/coverage_analysis.sh b/tests/coverage_analysis.sh index a6eadc9b..c5a9c333 100755 --- a/tests/coverage_analysis.sh +++ b/tests/coverage_analysis.sh @@ -6,6 +6,7 @@ readonly libpath="${LIBPATH:-../guibot}" readonly coverage="${COVERAGE:-coverage3}" readonly submit="${SUBMIT:-0}" +echo "---- running tests with $coverage ----" $coverage run --source="$libpath" -m unittest discover -v -s ../tests/ # use -i to ignore errors from pythong cache files and other traced dependencies $coverage report -m -i diff --git a/tests/test_finder.py b/tests/test_finder.py index 531c83ce..73f0c397 100644 --- a/tests/test_finder.py +++ b/tests/test_finder.py @@ -692,6 +692,11 @@ def test_text_nomatch(self) -> None: # TODO: deprecate OpenCV 3.X versions after time if cv2.__version__.startswith("3.") and tdetect == "east": continue + # TODO: OpenCV version 4.6.0 and above fails here on docker CIs (C++ exception) with tesseract + if ocr == "tesseract": + cv_version = [int(v) for v in cv2.__version__.split(".")] + if cv_version[0] >= 4 and cv_version[1] >= 6: + continue finder.configure_backend(tdetect, "tdetect") finder.configure_backend(ocr, "ocr")