Check for python-cairo
ClosedPublic

Authored by davidedmundson on Jan 14 2019, 2:50 PM.

Details

Test Plan

Works correctly when installed

Changed cmake locally to "import asdfasdf"
Got the correct error message and an aborted build

Diff Detail

Repository
R98 Breeze for Gtk
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
davidedmundson created this revision.Jan 14 2019, 2:50 PM
Restricted Application added a project: Plasma. · View Herald TranscriptJan 14 2019, 2:50 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
davidedmundson requested review of this revision.Jan 14 2019, 2:50 PM
zzag added a subscriber: zzag.Jan 14 2019, 3:12 PM

For me it fails even though I have python-cairo installed, e.g.

$ python
Python 3.7.2 (default, Jan 10 2019, 23:51:51) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
>>> cairo.__file__
'/usr/lib/python3.7/site-packages/cairo/__init__.py'
>>> 
ngraham accepted this revision.Jan 14 2019, 3:13 PM
ngraham added a subscriber: ngraham.

Works for me and CMake code looks good. For now we should probably ship this here for the 5.15 release, but maybe this should also go into ECM and then we can use it from there in subsequent releases?

This revision is now accepted and ready to land.Jan 14 2019, 3:13 PM
In D18244#392953, @zzag wrote:

For me it fails even though I have python-cairo installed, e.g.

 $ python
 Python 3.7.2 (default, Jan 10 2019, 23:51:51) 
 [GCC 8.2.1 20181127] on linux
 Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
>>> cairo.__file__
 '/usr/lib/python3.7/site-packages/cairo/__init__.py'
>>>

That's strange. Here's my output:

$  (arcpatch-D18244) cmake -DCMAKE_INSTALL_PREFIX=/usr .
-- The following RUNTIME packages have been found:

 * GTKEngine, Pixmap/Pixbuf theme engine for GTK 2, <http://www.gtk.org/>
   Required for GTK 2 theme

-- The following REQUIRED packages have been found:

 * ECM (required version >= 0.0.9)
 * Sass, SASS compiler, <https://sass-lang.com/>
   Required for building GTK themes
 * PythonInterp (required version >= 3)
 * PythonCairo
   Required to render assets
 * Breeze
   Required to build the Breeze GTK+ styles
 * Qt5
 * Qt5Core

-- Configuring done
-- Generating done
-- Build files have been written to: /home/dev/repos/breeze-gtk

@zzag could you run with

cmake -DPYTHON_EXECUTABLE=/usr/bin/python3

and/or change python_executable to Python3_EXECUTABLE

$  (arcpatch-D18244) cmake -DCMAKE_INSTALL_PREFIX=/usr  -DPYTHON_EXECUTABLE=/usr/bin/python3 .
-- The following RUNTIME packages have been found:

 * GTKEngine, Pixmap/Pixbuf theme engine for GTK 2, <http://www.gtk.org/>
   Required for GTK 2 theme

-- The following REQUIRED packages have been found:

 * ECM (required version >= 0.0.9)
 * Sass, SASS compiler, <https://sass-lang.com/>
   Required for building GTK themes
 * PythonInterp (required version >= 3)
 * PythonCairo
   Required to render assets
 * Breeze
   Required to build the Breeze GTK+ styles
 * Qt5
 * Qt5Core

-- Configuring done
-- Generating done
-- Build files have been written to: /home/dev/repos/breeze-gtk

Trying Python 2:

dev@dev-pc:~/repos/breeze-gtk$  (arcpatch-D18244) cmake -DCMAKE_INSTALL_PREFIX=/usr  -DPYTHON_EXECUTABLE=/usr/bin/python2 .
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find PythonInterp: Found unsuitable version "2.7.15", but
  required is at least "3" (found /usr/bin/python2)
Call Stack (most recent call first):
  /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:376 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.10/Modules/FindPythonInterp.cmake:152 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  cmake/FindPythonCairo.cmake:2 (find_package)
  CMakeLists.txt:13 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/dev/repos/breeze-gtk/CMakeFiles/CMakeOutput.log".
zzag added a comment.Jan 14 2019, 3:48 PM

Well, something like this works fine, though this is a quick and dirty solution.

if (CMAKE_VERSION VERSION_LESS 3.12.0)
    find_package (PythonInterp 3 REQUIRED)
    set (_py_exe ${PYTHON_EXECUTABLE})
else ()
    find_package (Python 3.0 REQUIRED COMPONENTS Interpreter)
    set (_py_exe ${Python_EXECUTABLE})
endif ()

execute_process (COMMAND "${_py_exe}" "-c"
    "import re, cairo; print(re.compile('/__init__.py.*').sub('',cairo.__file__))"
    RESULT_VARIABLE _PY_cairo_status
    OUTPUT_VARIABLE _PY_cairo_location
    ERROR_QUIET
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (_PY_cairo_status EQUAL 0)
    set (PY_CAIRO ${_PY_cairo_location} CACHE STRING "Location of pycairo")
endif ()

find_package_handle_standard_args (PythonCairo DEFAULT_MSG PY_CAIRO)

Which change of that is relevant?

cgiboudeaux added inline comments.Jan 14 2019, 4:41 PM
cmake/FindPythonCairo.cmake
9

FindPython3.cmake doesn't define PYTHON_EXECUTABLE but Python3_EXECUTABLE, you need e.g set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}") after line 4.

zzag added inline comments.Jan 16 2019, 9:23 AM
cmake/FindPythonCairo.cmake
7

Shouldn't it be right after find_package(Python3)?

cgiboudeaux added inline comments.Jan 16 2019, 9:51 AM
cmake/FindPythonCairo.cmake
7

Correct, or this will be empty with CMake < 3.12

move set(python_exec) into relevant scope

zzag accepted this revision.Jan 16 2019, 1:46 PM
This revision was automatically updated to reflect the committed changes.
rikmills added a subscriber: rikmills.EditedJan 17 2019, 6:44 AM

This breaks NeonKubuntu builds, whereas previously the builds were working as I explicitly had added python3-cairo to the build depends. It is there still, but cmake thinks not.

EDIT: seems specific to cmake < 3.12 in Bionic. Kubuntu Cosmic/Disco build with cmake 3.12 finds python3-cairo, but fails on another issue probably related a different recent commit.

https://build.neon.kde.org/job/bionic_unstable_kde_breeze-gtk_bin_amd64/51/consoleFull

02:43:04 -- The following REQUIRED packages have not been found:
02:43:04
02:43:04 * PythonCairo
02:43:04 Required to render assets

This breaks NeonKubuntu builds, whereas previously the builds were working as I explicitly had added python3-cairo to the build depends. It is there still, but cmake thinks not.

EDIT: seems specific to cmake < 3.12 in Bionic. Kubuntu Cosmic/Disco build with cmake 3.12 finds python3-cairo, but fails on another issue probably related a different recent commit.

https://build.neon.kde.org/job/bionic_unstable_kde_breeze-gtk_bin_amd64/51/consoleFull

02:43:04 -- The following REQUIRED packages have not been found:
02:43:04
02:43:04 * PythonCairo
02:43:04 Required to render assets

From the build log:

03:42:04 The following NEW packages will be installed:

[...] libcairo-script-interpreter2{a} libcairo2-dev{a}

python3-cairo isn't installed.