diff mbox series

[bug#48785,v4,3/3] gnu: Add python-lightgbm.

Message ID 20211031014028.82583-3-monego@posteo.net
State New
Headers show
Series [bug#48785,v4,1/3] gnu: Add fast-double-parser. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Vinicius Monego Oct. 31, 2021, 1:40 a.m. UTC
* gnu/packages/machine-learning.scm (python-lightgbm): New variable.
---
 gnu/packages/machine-learning.scm | 59 +++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
diff mbox series

Patch

diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index c7613ebe4e..59e9fdc75b 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -1268,6 +1268,65 @@  the following advantages:
 @end itemize\n")
     (license license:expat)))
 
+(define-public python-lightgbm
+  (package
+    (inherit lightgbm)
+    (name "python-lightgbm")
+    (source (package-source lightgbm))
+    (build-system python-build-system)
+    (arguments
+     `(#:configure-flags (list "--precompile") ; use precompiled library
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'preparations
+           (lambda _
+             (setenv "HOME" "/tmp")     ;to write a log file
+             ;; Move Python files to source root to silence some warnings.
+             (rename-file "python-package/setup.py" "setup.py")
+             (rename-file "python-package/README.rst" "README.rst")
+             (rename-file "python-package/lightgbm" "lightgbm")
+             ;; Install version file to read the library's version.
+             (with-output-to-file "lightgbm/VERSION.txt"
+               (lambda ()
+                 (display ,(package-version lightgbm))))
+             ;; Skip building the shared library.
+             (substitute* "setup.py"
+               (("'install_lib': CustomInstallLib,") ""))))
+         (add-after 'install 'install-liblightgbm
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (pylib (string-append out "/lib/python"
+                                          ,(version-major+minor
+                                            (package-version python))
+                                          "/site-packages"))
+                    (lgbdir (string-append pylib "/lightgbm"))
+                    (lib-lightgbm (string-append (assoc-ref inputs "lightgbm")
+                                                 "/lib/lib_lightgbm.so")))
+               ;; This symlink is necessary for tests.
+               (symlink lib-lightgbm "lightgbm/lib_lightgbm.so")
+               ;; And this one for runtime.
+               (mkdir-p (string-append lgbdir "/lib"))
+               (symlink lib-lightgbm (string-append lgbdir
+                                                    "/lib_lightgbm.so")))))
+         (replace 'check
+           (lambda* (#:key inputs outputs tests? #:allow-other-keys)
+             (when tests?
+               (add-installed-pythonpath inputs outputs)
+               (invoke "python" "-m" "pytest"
+                       "tests/python_package_test")))))))
+    (native-inputs
+     `(("python-psutil" ,python-psutil)
+       ("python-pytest" ,python-pytest)
+       ("python-wheel" ,python-wheel)))
+    (inputs
+     `(("lightgbm" ,lightgbm)))
+    (propagated-inputs
+     `(("python-numpy" ,python-numpy)
+       ("python-pandas" ,python-pandas)
+       ("python-scikit-learn" ,python-scikit-learn)
+       ("python-scipy" ,python-scipy)))
+    (synopsis "Python frontend for LightGBM")))
+
 (define-public vowpal-wabbit
   ;; Language bindings not included.
   (package