Subject: [bug#29850] [PATCH v3] gnu: Add python-hidapi.

From: Marius Bakke <[email-masked]>
Date: Wed, 27 Dec 2017 22:58:03 +0100

Hello!

Danny Milosavljevic <[email-masked]> writes:

> * gnu/packages/libusb.scm (python-hidapi, python2-hidapi): New variables.

[...]

> +(define-public python-hidapi
> +  (package
> +    (name "python-hidapi")
> +    (version "0.7.99.post21")
> +    (source
> +      (origin
> +        (method url-fetch)
> +        (uri (pypi-uri "hidapi" version))
> +        (sha256
> +          (base32
> +            "15ws59zdrxahf3k7z5rcrwc4jgv1307anif8ixm2cyb9ask1mgp0"))

Please re-indent the entire expression with emacs or ./etc/indent-code.el.

> +        (modules '((guix build utils)))
> +        (snippet
> +         ;; Remove bundled libraries.
> +         '(begin
> +            (delete-file-recursively "hidapi")))))

In absense of a consensus on unspecified return values, return #t here.

> +    (build-system python-build-system)
> +    (arguments
> +     `(#:phases
> +       (modify-phases %standard-phases
> +         (add-after 'unpack 'patch-configuration
> +           (lambda* (#:key inputs #:allow-other-keys)
> +             (substitute* "setup.py"
> +               (("'/usr/include/libusb-1.0'")
> +                (string-append "'" (assoc-ref inputs "libusb")
> +                               "/include/libusb-1.0'"))
> +               (("'/usr/include/hidapi'")
> +                (string-append "'" (assoc-ref inputs "hidapi")
> +                               "/include/hidapi'")))
> +             #t))
> +         (replace 'build
> +           (lambda _
> +             ;; Necessary because python-build-system drops the arguments.
> +             (invoke "python" "setup.py" "build" "--with-system-hidapi")))
> +         (replace 'check
> +           (lambda _
> +             ;; Necessary because python-build-system drops the arguments.
> +             (invoke "python" "setup.py" "test" "--with-system-hidapi")))
> +         (replace 'install
> +           (lambda* (#:key outputs #:allow-other-keys)
> +             ;; Necessary because python-build-system drops the arguments.
> +             (invoke "python" "setup.py" "install" "--with-system-hidapi"
> +                     (string-append "--prefix=" (assoc-ref outputs "out"))
> +                     "--single-version-externally-managed" "--root=/"))))))

I don't think repeating the same comment thrice is necessary.  Maybe
just add an XXX note at the top mentioning why we do this dance rather
than use python-build-system directly.

It would be good to extend python-build-system to support this however.
#:setuppy-flags? :)

> +    (inputs
> +     `(("hidapi" ,hidapi)
> +       ("libusb" ,libusb)
> +       ("eudev" ,eudev)))
> +    (native-inputs
> +     `(("python-cython" ,python-cython)))
> +    (home-page "https://github.com/trezor/cython-hidapi")
> +    (synopsis "Cython interface to hidapi")
> +    (description "This package provides a Cython interface to @code{hidapi}.")
> +    ;; The library can be used under either of these licenses.
> +    ;; TODO Add cython-hidapi DIY license?

I think this TODO can be removed, we have lots of "one-off" licenses
scattered throughout.

> +    (license (list gpl3 bsd-3
> +                   (non-copyleft
> +                    "https://github.com/trezor/cython-hidapi/blob/master/LICENSE-orig.txt")))))

The (non-copyleft ...) procedure takes an optional comment.  This
license is short enough to fit, maybe we can just add the "whole" text?

No strong opinion.  The rest LGTM!

> +
> +(define-public python2-hidapi
> +  (package-with-python2 python-hidapi))