unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Vinicius Monego <monego@posteo.net>
To: 48388@debbugs.gnu.org
Cc: Vinicius Monego <monego@posteo.net>
Subject: [bug#48388] [PATCH v3 3/3] gnu: Add python-xgboost.
Date: Sun, 27 Jun 2021 17:30:47 +0000	[thread overview]
Message-ID: <20210627173047.2576-3-monego@posteo.net> (raw)
In-Reply-To: <20210627173047.2576-1-monego@posteo.net>

* gnu/packages/machine-learning.scm (python-xgboost): New variable.
* gnu/packages/patches/python-xgboost-use-system-libxgboost.patch: New patch.
* gnu/local.mk (dist_patch_DATA): Add it.
---
Changed source to inherit from xgboost.
Added phase after 'install to add a VERSION file and symlink libxgboost, so it can be found at runtime. This change allowed to greatly simplify the patch.
Also removed #t from phases.
If this patchset is good enough now, I will do the same changes to LightGBM: http://issues.guix.gnu.org/48785

 gnu/local.mk                                  |  1 +
 gnu/packages/machine-learning.scm             | 66 +++++++++++++++++++
 ...python-xgboost-use-system-libxgboost.patch | 18 +++++
 3 files changed, 85 insertions(+)
 create mode 100644 gnu/packages/patches/python-xgboost-use-system-libxgboost.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 19db9787dc..821fd390a4 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1632,6 +1632,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/python-unittest2-python3-compat.patch	\
   %D%/packages/patches/python-unittest2-remove-argparse.patch	\
   %D%/packages/patches/python-waitress-fix-tests.patch		\
+  %D%/packages/patches/python-xgboost-use-system-libxgboost.patch \
   %D%/packages/patches/pypy3-7.3.1-fix-tests.patch		\
   %D%/packages/patches/qemu-build-info-manual.patch		\
   %D%/packages/patches/qemu-CVE-2021-20203.patch		\
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index bbdfba960e..69b96ffd61 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -1991,6 +1991,72 @@ tree boosting (also known as GBDT, GBM) that solve many data science problems
 in a fast and accurate way.")
     (license license:asl2.0)))
 
+(define-public python-xgboost
+  (package
+    (inherit xgboost)
+    (name "python-xgboost")
+    (source
+     (origin
+       (inherit (package-source xgboost))
+       (patches (search-patches "python-xgboost-use-system-libxgboost.patch"))))
+    (build-system python-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'preparations
+           (lambda* (#:key inputs #:allow-other-keys)
+             ;; Move python-package content to parent directory to silence
+             ;; some warnings about files not being found if we chdir.
+             (rename-file "python-package/xgboost" "xgboost")
+             (rename-file "python-package/README.rst" "README.rst")
+             (rename-file "python-package/setup.cfg" "setup.cfg")
+             (rename-file "python-package/setup.py" "setup.py")))
+         (add-after 'install 'install-version-and-libxgboost
+           (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"))
+                    (xgbdir (string-append pylib "/xgboost"))
+                    (version-file (string-append xgbdir "/VERSION"))
+                    (libxgboost (string-append (assoc-ref inputs "xgboost")
+                                               "/lib/libxgboost.so")))
+               (with-output-to-file version-file
+                 (lambda ()
+                   (display ,(package-version xgboost))))
+               (mkdir-p (string-append xgbdir "/lib"))
+               (symlink libxgboost (string-append xgbdir "/lib"
+                                                  "/libxgboost.so")))))
+         (replace 'check
+           ;; Python-specific tests are located in tests/python.
+           (lambda* (#:key inputs outputs tests? #:allow-other-keys)
+             (when tests?
+               (add-installed-pythonpath inputs outputs)
+               (invoke "pytest" "tests/python"
+                       ;; FIXME: CLI tests fail with PermissionError.
+                       "--ignore" "tests/python/test_cli.py" "-k"
+                       (string-append
+                        "not test_cli_regression_demo"
+                        ;; The tests below open a network connection.
+                        " and not test_model_compatibility"
+                        " and not test_get_group"
+                        " and not test_cv_no_shuffle"
+                        " and not test_cv"
+                        " and not test_training"
+                        ;; "'['./runexp.sh']' returned non-zero exit status 1"
+                        " and not test_cli_binary_classification"))))))))
+    (native-inputs
+     `(("python-pandas" ,python-pandas)
+       ("python-pytest" ,python-pytest)
+       ("python-scikit-learn" ,python-scikit-learn)))
+    (inputs
+     `(("xgboost" ,xgboost)))
+    (propagated-inputs
+     `(("python-numpy" ,python-numpy)
+       ("python-scipy" ,python-scipy)))
+    (synopsis "Python interface for the XGBoost library")))
+
 (define-public python-iml
   (package
     (name "python-iml")
diff --git a/gnu/packages/patches/python-xgboost-use-system-libxgboost.patch b/gnu/packages/patches/python-xgboost-use-system-libxgboost.patch
new file mode 100644
index 0000000000..ce82309afd
--- /dev/null
+++ b/gnu/packages/patches/python-xgboost-use-system-libxgboost.patch
@@ -0,0 +1,18 @@
+This patch was imported from Debian: https://sources.debian.org/src/xgboost/1.2.1-1/debian/patches/setup.py.patch/
+
+Description: the libxgboost.so has been installed by another package already
+Forwarded: no need
+--- a/python-package/setup.py
++++ b/python-package/setup.py
+@@ -286,10 +286,8 @@
+               'numpy',
+               'scipy',
+           ],
+-          ext_modules=[CMakeExtension('libxgboost')],
+           cmdclass={
+               'build_ext': BuildExt,
+               'sdist': Sdist,
+-              'install_lib': InstallLib,
+               'install': Install
+           },
+           extras_require={
\ No newline at end of file
-- 
2.32.0





  parent reply	other threads:[~2021-06-27 18:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 23:56 [bug#48388] [PATCH 0/3] Add xgboost Vinicius Monego
2021-05-12 23:58 ` [bug#48388] [PATCH 1/3] gnu: Add dmlc-core Vinicius Monego
2021-05-12 23:58   ` [bug#48388] [PATCH 2/3] gnu: Add xgboost Vinicius Monego
2021-05-12 23:58   ` [bug#48388] [PATCH 3/3] gnu: Add python-xgboost Vinicius Monego
2021-05-13 15:29 ` [bug#48388] [PATCH v2 2/3] gnu: Add xgboost Vinicius Monego
2021-05-13 15:29   ` [bug#48388] [PATCH v2 3/3] gnu: Add python-xgboost Vinicius Monego
2021-06-27 17:30 ` [bug#48388] [PATCH v3 1/3] gnu: Add dmlc-core Vinicius Monego
2021-06-27 17:30   ` [bug#48388] [PATCH v3 2/3] gnu: Add xgboost Vinicius Monego
2021-06-27 17:30   ` Vinicius Monego [this message]
2021-06-27 23:11 ` [bug#48388] [PATCH v4 3/3] gnu: Add python-xgboost Vinicius Monego
2021-09-25 19:36 ` [bug#48388] [PATCH v5 1/3] gnu: Add dmlc-core Vinicius Monego
2021-09-25 19:36   ` [bug#48388] [PATCH v5 2/3] gnu: Add xgboost Vinicius Monego
2021-09-25 19:36   ` [bug#48388] [PATCH v5 3/3] gnu: Add python-xgboost Vinicius Monego
2021-09-25 20:14   ` bug#48388: [PATCH v5 1/3] gnu: Add dmlc-core Leo Famulari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210627173047.2576-3-monego@posteo.net \
    --to=monego@posteo.net \
    --cc=48388@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).