diff mbox

[v2,3/3] gnu: Add python2-wxpython.

Message ID 20161025160907.30181-4-theodoros.for@openmailbox.org
State New
Headers show

Commit Message

Theodoros Foradis Oct. 25, 2016, 4:09 p.m. UTC
* gnu/packages/wxwidgets.scm (python2-wxpython): New variable.
---
 gnu/packages/wxwidgets.scm | 84 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

Comments

Leo Famulari Oct. 25, 2016, 4:35 p.m. UTC | #1
On Tue, Oct 25, 2016 at 07:09:07PM +0300, Theodoros Foradis wrote:
> * gnu/packages/wxwidgets.scm (python2-wxpython): New variable.

> +       #:tests? #f ; tests fail

We should try to fix this, or at least understand why they are failing.

> +    (native-inputs
> +     `(("gtk+" ,gtk+-2)
> +       ("expat" ,expat)
> +       ("libjpeg" ,libjpeg)
> +       ("libpng" ,libpng)
> +       ("libtiff" ,libtiff)
> +       ("libsm" ,libsm)
> +       ("libx11" ,libx11)
> +       ("mesa" ,mesa)
> +       ("pkg-config" ,pkg-config)
> +       ("python2-setuptools" ,python2-setuptools)
> +       ("zlib" ,zlib)))

To clarify, all these native-inputs are only used while building?
Native inputs typically are not intended to be available once the
package has been built and installed.
Theodoros Foradis Oct. 25, 2016, 5:13 p.m. UTC | #2
Leo Famulari writes:

> On Tue, Oct 25, 2016 at 07:09:07PM +0300, Theodoros Foradis wrote:
>> * gnu/packages/wxwidgets.scm (python2-wxpython): New variable.
>
>> +       #:tests? #f ; tests fail
>

I'll try to give this one a second look.

> We should try to fix this, or at least understand why they are failing.
>
>> +    (native-inputs
>> +     `(("gtk+" ,gtk+-2)
>> +       ("expat" ,expat)
>> +       ("libjpeg" ,libjpeg)
>> +       ("libpng" ,libpng)
>> +       ("libtiff" ,libtiff)
>> +       ("libsm" ,libsm)
>> +       ("libx11" ,libx11)
>> +       ("mesa" ,mesa)
>> +       ("pkg-config" ,pkg-config)
>> +       ("python2-setuptools" ,python2-setuptools)
>> +       ("zlib" ,zlib)))
>
> To clarify, all these native-inputs are only used while building?
> Native inputs typically are not intended to be available once the
> package has been built and installed.

To quote Danny Milosavljevic, whose original patch of python2-wxpython I
modified:
> I added gtk, opengl etc as native inputs instead of regular inputs because from the point of view of Python they are not direct inputs.

I guess this applies to gtk+,opengl,mesa and expat(?) (the others are
intented to be native-inputs for sure). I am unsure if they are intended
to be available at runtime. I assumed they were not, based on the
previous comment. If they, they should be moved to inputs.

How could I figure that out?
Theodoros Foradis Oct. 25, 2016, 6:05 p.m. UTC | #3
Leo Famulari writes:

> On Tue, Oct 25, 2016 at 07:09:07PM +0300, Theodoros Foradis wrote:
>> * gnu/packages/wxwidgets.scm (python2-wxpython): New variable.
>
>> +       #:tests? #f ; tests fail
>
> We should try to fix this, or at least understand why they are failing.

I tried building the package with #:tests #t and I get the following
output:

starting phase `check'
running "python setup.py" with command "test" and parameters ()
Found wx-config: /gnu/store/s1a3a7nn1hx10ryai3dvpbcsdbjcylb1-wxwidgets-gtk2-3.0.2/bin/wx-config
    Using flags:  --toolkit=gtk2 --unicode=yes --version=3.0
Preparing CORE...
Preparing STC...
Preparing GLCANVAS...
Preparing GIZMOS...
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'test'
phase `check' failed after 3.3 seconds


In my understanding, there seem to be no tests after all. If so, the
comment should be changed to '; no tests'.
Leo Famulari Oct. 25, 2016, 6:28 p.m. UTC | #4
On Tue, Oct 25, 2016 at 09:05:44PM +0300, Theodoros Foradis wrote:
> 
> Leo Famulari writes:
> 
> > On Tue, Oct 25, 2016 at 07:09:07PM +0300, Theodoros Foradis wrote:
> >> * gnu/packages/wxwidgets.scm (python2-wxpython): New variable.
> >
> >> +       #:tests? #f ; tests fail
> >
> > We should try to fix this, or at least understand why they are failing.
> 
> I tried building the package with #:tests #t and I get the following
> output:
> 
> starting phase `check'
> running "python setup.py" with command "test" and parameters ()
> Found wx-config: /gnu/store/s1a3a7nn1hx10ryai3dvpbcsdbjcylb1-wxwidgets-gtk2-3.0.2/bin/wx-config
>     Using flags:  --toolkit=gtk2 --unicode=yes --version=3.0
> Preparing CORE...
> Preparing STC...
> Preparing GLCANVAS...
> Preparing GIZMOS...
> usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
>    or: setup.py --help [cmd1 cmd2 ...]
>    or: setup.py --help-commands
>    or: setup.py cmd --help
> 
> error: invalid command 'test'
> phase `check' failed after 3.3 seconds
> 
> 
> In my understanding, there seem to be no tests after all. If so, the
> comment should be changed to '; no tests'.

`find . -iname "*test*"` does not show any promising results, so I guess
you are right that there are no tests.
Leo Famulari Oct. 30, 2016, 12:13 a.m. UTC | #5
On Tue, Oct 25, 2016 at 08:13:55PM +0300, Theodoros Foradis wrote:
> Leo Famulari writes:
> >> +    (native-inputs
> >> +     `(("gtk+" ,gtk+-2)
> >> +       ("expat" ,expat)
> >> +       ("libjpeg" ,libjpeg)
> >> +       ("libpng" ,libpng)
> >> +       ("libtiff" ,libtiff)
> >> +       ("libsm" ,libsm)
> >> +       ("libx11" ,libx11)
> >> +       ("mesa" ,mesa)
> >> +       ("pkg-config" ,pkg-config)
> >> +       ("python2-setuptools" ,python2-setuptools)
> >> +       ("zlib" ,zlib)))
> >
> > To clarify, all these native-inputs are only used while building?
> > Native inputs typically are not intended to be available once the
> > package has been built and installed.
> 
> To quote Danny Milosavljevic, whose original patch of python2-wxpython I
> modified:
> > I added gtk, opengl etc as native inputs instead of regular inputs
> > because from the point of view of Python they are not direct inputs.

I'm not sure what that means in this case.

> I guess this applies to gtk+,opengl,mesa and expat(?) (the others are
> intented to be native-inputs for sure). I am unsure if they are intended
> to be available at runtime. I assumed they were not, based on the
> previous comment. If they, they should be moved to inputs.

I checked the references of the built package like this:

$ guix gc --references $(./pre-inst-env guix build python2-wxpython)
/gnu/store/1xfc2pwr7qfjib9kfy3n2hjq56z7jyjx-python-2.7.11
/gnu/store/6njycb0nzbczqbzvcyn1vw5sg7xsaanr-python2-setuptools-18.3.1
/gnu/store/9nifwk709wajpyfwa0jzaa3p6mf10vxs-gcc-4.9.3-lib
/gnu/store/a5xcl27fflh6ppysf5wrsfnn3ly2gyhy-python2-wxpython-3.0.2.0
/gnu/store/fdlind5y49q37m1g1wsvx840q2scrp6x-wxwidgets-gtk2-3.0.2
/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23
/gnu/store/ykzwykkvr2c80rw4l1qh3mvfdkl7jibi-bash-4.3.42

As you can see, many of the package's inputs not referred to by the
built package. This means that those inputs will by deleted by the next
`guix gc` (unless some other installed package refers to them). That's
fine for native-inputs, which are supposed to be used only while
building.

As for whether or not the packages are required at run-time, I don't
know. wxPython's documentation should explain what the software does and
what libraries it wants to use.

Hartmut, assuming that wxPython needs these packages at run-time, do you
have any recommendations for how to keep references to them? I ask based
on your recent work on Python packaging.

Otherwise this package looks good, minus some minor cosmetic nits.
Hartmut Goebel Oct. 30, 2016, 10:13 a.m. UTC | #6
Am 30.10.2016 um 02:13 schrieb Leo Famulari:
> As for whether or not the packages are required at run-time, I don't
> know. wxPython's documentation should explain what the software does and
> what libraries it wants to use.
>
> Hartmut, assuming that wxPython needs these packages at run-time, do you
> have any recommendations for how to keep references to them? I ask based
> on your recent work on Python packaging.

You are talking about the ones listed in the "guix gc --references"
output, I assume. The only python package listed there is
python2-setuptools, which I assume to be *not* used at run-time and thus
needs to be a native input.
Danny Milosavljevic Oct. 31, 2016, 10:42 a.m. UTC | #7
Hi,

wxPython bundles wxwidgets. That's why we cd to "wxPython/wxPython" in order to avoid building it.

So wxPython as we build it requires wxwidgets as input.

But wxwidgets has multiple backends it supports, among them gtk. It should work to just leave off the gtk dependency on wxPython - since wxPython itself shouldn't require gtk.

The intention is that wxwidgets provides a backend-independent interface. I think the same should be true about wxPython. I'll check it some more.

wxPython seems to use SWIG in order to generate Python bindings to the C++ classes of wxwidgets.

> I checked the references of the built package like this:
> 
> $ guix gc --references $(./pre-inst-env guix build python2-wxpython)
> /gnu/store/1xfc2pwr7qfjib9kfy3n2hjq56z7jyjx-python-2.7.11
> /gnu/store/6njycb0nzbczqbzvcyn1vw5sg7xsaanr-python2-setuptools-18.3.1
> /gnu/store/9nifwk709wajpyfwa0jzaa3p6mf10vxs-gcc-4.9.3-lib
> /gnu/store/a5xcl27fflh6ppysf5wrsfnn3ly2gyhy-python2-wxpython-3.0.2.0
> /gnu/store/fdlind5y49q37m1g1wsvx840q2scrp6x-wxwidgets-gtk2-3.0.2
> /gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23
> /gnu/store/ykzwykkvr2c80rw4l1qh3mvfdkl7jibi-bash-4.3.42
> 
> assuming that wxPython needs these packages at run-time, 

I think it doesn't.

It's easy to test it in a container which provides wxpython and python by writing a small test program in it.
Danny Milosavljevic Oct. 31, 2016, 3:38 p.m. UTC | #8
Hi,

because of wxPython/src/helpers.cpp directly accessing a Gtk (gdk) structure (in macro GetXWindow) wxpython also requires gtk as regular input.

I've tested it in

$ guix environment --pure --ad-hoc python2-wxpython python-2 -- python

using:

import wxversion
wxversion.select("3.0")
import wx, wx.html
from wx import glcanvas
import wx.lib.fancytext
import sys
app = wx.App(redirect=True)   # Error messages go to popup window
top = wx.Frame(None)
box = wx.BoxSizer(wx.VERTICAL)
top.SetSizer(box)
#panel = wx.Panel(top)
canvas = glcanvas.GLCanvas(top)
box.Add(canvas)
canvas.Show()
top.Show()
app.MainLoop()

app = wx.App(redirect=True)
top = wx.Frame(None, title="Hello World", size=(300,200))
top.Show()
app.MainLoop()

#from wx import glcanvas
#from OpenGL.GL import *
#frame = GLFrame(None, -1, 'GL Window')
#frame.Show()
#app.MainLoop()
#app.Destroy()

The wxpython inputs I used were:

    (native-inputs
     `(("mesa" ,mesa) ; for glcanvas
       ("pkg-config" ,pkg-config)
       ("python2-setuptools" ,python2-setuptools)))
    (inputs
     `(("gtk+" ,gtk+-2) ; for wxPython/src/helpers.cpp
       ("wxwidgets" ,wxwidgets-gtk2)))

If we even built the X11 backend of wxwidgets, we would require an input "libx11" - otherwise not.

While wxpython glcanvas isn't very useful without mesa, it doesn't really require it. As you can see above it can still be imported without mesa.

Therefore, I think the above is the final version of the inputs we should use for wxpython.
diff mbox

Patch

diff --git a/gnu/packages/wxwidgets.scm b/gnu/packages/wxwidgets.scm
index 4efe7a1..0002b73 100644
--- a/gnu/packages/wxwidgets.scm
+++ b/gnu/packages/wxwidgets.scm
@@ -2,6 +2,7 @@ 
 ;;; Copyright © 2015 Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2016 Theodoros Foradis <theodoros.for@openmailbox.org>
+;;; Copyright © 2016 Danny Milosavljevic <dannym@scratchpost.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -23,6 +24,7 @@ 
   #:use-module (guix download)
   #:use-module ((guix licenses) #:prefix l:)
   #:use-module (guix build-system glib-or-gtk)
+  #:use-module (guix build-system python)
   #:use-module (guix build utils)
   #:use-module (gnu packages)
   #:use-module (gnu packages compression)
@@ -32,8 +34,10 @@ 
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages image)
   #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages python)
   #:use-module (gnu packages sdl)
   #:use-module (gnu packages webkit)
+  #:use-module (gnu packages xml)
   #:use-module (gnu packages xorg))
 
 (define-public wxwidgets
@@ -118,3 +122,83 @@  and many other languages.")
                         "gtk+"
                         (package-inputs wxwidgets))))
            (name "wxwidgets-gtk2")))
+
+(define-public python2-wxpython
+  (package
+    (name "python2-wxpython")
+    (version "3.0.2.0")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "mirror://sourceforge/wxpython/wxPython/"
+                                  version "/wxPython-src-" version ".tar.bz2"))
+              (sha256
+               (base32
+                "0qfzx3sqx4mwxv99sfybhsij4b5pc03ricl73h4vhkzazgjjjhfm"))
+              (modules '((guix build utils)))
+              (snippet
+               '(begin
+                  (delete-file-recursively "src/expat")
+                  (delete-file-recursively "src/jpeg")
+                  (delete-file-recursively "src/png")
+                  (delete-file-recursively "src/tiff")
+                  (delete-file-recursively "src/zlib")
+                  (delete-file-recursively "src/msw")
+                  (delete-file-recursively "src/osx")
+                  (delete-file-recursively "src/msdos")
+                  (substitute* '("wxPython/setup.py")
+                    ;; setup.py tries to keep its own license the same as wxwidget's
+                    ;; license (which it expects under $WXWIN/docs).
+                    (("'preamble.txt', 'licence.txt', 'licendoc.txt', 'lgpl.txt'") "")
+                    )))))
+    (build-system python-build-system)
+    (arguments
+     `(#:python ,python-2
+       #:tests? #f ; tests fail
+       #:configure-flags (list "WXPORT=gtk2"
+                               "UNICODE=1")
+       #:phases
+       (modify-phases %standard-phases
+         (add-before 'build 'chdir
+           (lambda _
+             (chdir "wxPython")))
+         (add-after 'chdir 'set-wx-out-dir
+           (lambda* (#:key outputs #:allow-other-keys)
+             ;; By default, install phase tries to copy the wxPython headers in
+             ;; gnu/store/...-wxwidgets-3.0.2 , which it can't, so they are redirected
+             ;; to the output directory by setting WXPREFIX.
+             (substitute* "config.py"
+               (("= getWxConfigValue\\('--prefix'\\)")
+                (string-append "= '" (assoc-ref outputs "out") "'")))
+             (substitute* "wx/build/config.py"
+               (("= getWxConfigValue\\('--prefix'\\)")
+                (string-append "= '" (assoc-ref outputs "out") "'")))))
+         (add-after 'set-wx-out-dir 'setenv
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (setenv "WXWIN" (assoc-ref inputs "wxwidgets"))
+             (setenv "CPPFLAGS" (string-append "-I"
+                                               (assoc-ref inputs "wxwidgets")
+                                               "/lib/wx/include/gtk2-unicode-release-2.8"
+                                               " -I"
+                                               (assoc-ref inputs "wxwidgets")
+                                               "/include/wx-3.0"
+                                               " -D_FILE_OFFSET_BITS=64"
+                                               " -DWXUSINGDLL"
+                                               " -D__WXGTK__")))))))
+    (native-inputs
+     `(("gtk+" ,gtk+-2)
+       ("expat" ,expat)
+       ("libjpeg" ,libjpeg)
+       ("libpng" ,libpng)
+       ("libtiff" ,libtiff)
+       ("libsm" ,libsm)
+       ("libx11" ,libx11)
+       ("mesa" ,mesa)
+       ("pkg-config" ,pkg-config)
+       ("python2-setuptools" ,python2-setuptools)
+       ("zlib" ,zlib)))
+    (inputs
+     `(("wxwidgets" ,wxwidgets-gtk2)))
+    (synopsis "Python2 Bindings for wxWidgets")
+    (description "@code{wxpython} are Python2 bindings for wxWidgets.")
+    (home-page "http://wxpython.org/")
+    (license (package-license wxwidgets))))