diff mbox series

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

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

Commit Message

Vinicius Monego June 26, 2023, 1:06 a.m. UTC
* gnu/packages/machine-learning.scm (python-lightgbm): New variable.
---
Removed symlinks in favor of substituting lib_path.

 gnu/packages/machine-learning.scm | 39 +++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff mbox series

Patch

diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index 17de467f46..bba89d789d 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -1839,6 +1839,45 @@  (define-public lightgbm
 @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
+     (list #:configure-flags #~(list "--precompile") ; use our library
+           #:phases
+           #~(modify-phases %standard-phases
+               (add-after 'unpack 'preparations
+                 (lambda _
+                   (setenv "HOME" "/tmp") ; to write a log file
+                   (rename-file "python-package/setup.py" "setup.py")
+                   (rename-file "python-package/README.rst" "README.rst")
+                   (rename-file "python-package/lightgbm" "lightgbm")
+                   ;; Write the version so the module identifies it.
+                   (with-output-to-file "lightgbm/VERSION.txt"
+                     (lambda () (display #$(package-version lightgbm))))
+                   ;; Manually install the lib.
+                   (substitute* "setup.py"
+                     (("'install_lib': CustomInstallLib,") ""))
+                   ;; Change lib_path to look for our package's lib.
+                   (substitute* "lightgbm/libpath.py"
+                     (("lib_path = \\[str\\(p\\) for p in dll_path if p\\.is_file\\(\\)]")
+                      ;; lib_path is a list of paths.
+                      (format #f "lib_path = ['~a/lib/lib_lightgbm.so']"
+                              #$(this-package-input "lightgbm"))))))
+               (replace 'check
+                 (lambda* (#:key tests? #:allow-other-keys)
+                   (when tests?
+                     (invoke "python" "-m" "pytest"
+                             "tests/python_package_test")))))))
+    (native-inputs (list python-psutil python-pytest python-wheel))
+    (inputs (list lightgbm))
+    (propagated-inputs (list python-numpy python-pandas python-scikit-learn
+                             python-scipy))
+    (synopsis "Python interface for LightGBM")))
+
 (define-public vowpal-wabbit
   ;; Language bindings not included.
   (package