From patchwork Fri Apr 4 19:16:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 41294 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8EE9F27BBE2; Fri, 4 Apr 2025 20:19:49 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED,URIBL_SBL_A autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BB72727BBE9 for ; Fri, 4 Apr 2025 20:19:45 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u0mZL-0007G5-Px; Fri, 04 Apr 2025 15:19:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u0mZI-0007CL-79 for guix-patches@gnu.org; Fri, 04 Apr 2025 15:19:08 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u0mZG-0007xJ-Ay for guix-patches@gnu.org; Fri, 04 Apr 2025 15:19:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=Wr5mop/Npb6Aqxtnm/2tqbUqsZ19LUU5F21s83YH39s=; b=LeuPmX6aU3XLpqdDj4HAv+mrk1BMidyoU4bmISy54ECJnEoItO/HHt8XXanQ0vKmboAmPXXtChNJ0ce6FvShfKXzdkdIEpZTxsstwtwSzmO85oImvIiPWsx1Z/xljU+X3TflrBlXMrd31BkgiSizV5zOoQtQ+rSGf9ab2agbb0fQh95GRg8c5kB/srUnPZJdIlaGn6aSpCEW2nbmb2LwT9HxVvi7zhtanUE1MQGYar26upNVjLUsqfXnMTYI6c9Jozz+nk2xW0aDs/QExelCKe5QIR6hEeNnoGQwjMCh9At9/y2v4pm10wfSiW0YBJIPtmZaCnxx5kr7Atggrdlj8g==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1u0mZG-0007RZ-40 for guix-patches@gnu.org; Fri, 04 Apr 2025 15:19:06 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77541] [PATCH 23/38] gnu: python-bed-reader: Fix build and enable tests. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 04 Apr 2025 19:19:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77541 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77541@debbugs.gnu.org Cc: Nicolas Graves Received: via spool by 77541-submit@debbugs.gnu.org id=B77541.174379429728395 (code B ref 77541); Fri, 04 Apr 2025 19:19:06 +0000 Received: (at 77541) by debbugs.gnu.org; 4 Apr 2025 19:18:17 +0000 Received: from localhost ([127.0.0.1]:40124 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u0mYS-0007Np-Mu for submit@debbugs.gnu.org; Fri, 04 Apr 2025 15:18:17 -0400 Received: from 10.mo562.mail-out.ovh.net ([46.105.72.220]:56581) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u0mXz-0007Gr-2a for 77541@debbugs.gnu.org; Fri, 04 Apr 2025 15:17:49 -0400 Received: from director4.derp.mail-out.ovh.net (director4.derp.mail-out.ovh.net [79.137.60.37]) by mo562.mail-out.ovh.net (Postfix) with ESMTPS id 4ZTpK10rxvz1ddd; Fri, 4 Apr 2025 19:17:41 +0000 (UTC) Received: from director4.derp.mail-out.ovh.net (director4.derp.mail-out.ovh.net. [127.0.0.1]) by director4.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for <77541@debbugs.gnu.org>; Fri, 4 Apr 2025 19:17:41 +0000 (UTC) Received: from mta6.priv.ovhmail-u1.ea.mail.ovh.net (unknown [10.110.178.229]) by director4.derp.mail-out.ovh.net (Postfix) with ESMTPS id 4ZTpK10Vj7zyD4; Fri, 4 Apr 2025 19:17:41 +0000 (UTC) Received: from ngraves.fr (unknown [10.1.6.5]) by mta6.priv.ovhmail-u1.ea.mail.ovh.net (Postfix) with ESMTPSA id 9E113D43D38; Fri, 4 Apr 2025 19:17:40 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-107S001d5f5dbf0-0e84-40d2-ad66-d93e944faba0, 5C763BAE2B049B0552D0CEA89988AE409CD35AAA) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.92.117.144 Date: Fri, 4 Apr 2025 21:16:55 +0200 Message-ID: <20250404191717.32747-23-ngraves@ngraves.fr> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250404191717.32747-1-ngraves@ngraves.fr> References: <20250404191717.32747-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 3482689889811358434 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 49 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduledvvdeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucgoufhushhpvggtthffohhmrghinhculdegledmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeeltdfhiefgtdffkeeitdeggeffieevteffieeigfelffegkeelhfegudfhudevueenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhgihhthhhusghushgvrhgtohhnthgvnhhtrdgtohhmpdhgihhthhhusgdrihhonecukfhppeduvdejrddtrddtrddupdeltddrledvrdduudejrddugeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpehnghhrrghvvghssehnghhrrghvvghsrdhfrhdpnhgspghrtghpthhtohepvddprhgtphhtthhopeejjeehgeduseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdfovfetjfhoshhtpehmohehiedvmgdpmhhouggvpehsmhhtphhouhht DKIM-Signature: a=rsa-sha256; bh=Wr5mop/Npb6Aqxtnm/2tqbUqsZ19LUU5F21s83YH39s=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1743794261; v=1; b=NA7vMr9iBmM6Tq9wvZahqmhNINP8XZ2ytNOc4j8eO9CHL3FuRrRJt8WgV1Ie5Cb9dtXKw7q+ +avy3HKPnVI+FS8qy0s9QCRK2gIdohb0jAHDA7jkVGTP1H1W2g7hMF5vy8DN6HyUSJx5Mi/RVIw 3HK7bx29DQzDzK96AUbSYwAQXNkclUPDR9Xn60QgbMVBl1rhpK6prg8Ci9AgAnC1QsEb8NiNlKr 3qYHyVm39n1Uwk1oIb+1B9fLT9MIOLdHIT182jhcYeXws+T1jG3yV7HkhCwnhqForVbGZQ7Kepw cNpjjLxXkiNCwJiDnXy2N3Zx4elSnFqB6wJR33Rr/W61g== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/packages/bioinformatics.scm (python-bed-reader): Fix build and enable tests. [source]{snippet}: Delete bundled website-related javascript. {patches}: Use the store-cached instead of pooch-cached samples. [arguments]{tests?}: Enable them. {cargo-test-flags}: Skip doc tests. Skip failing tests. {cargo-inputs}: Improve style. {cargo-development-inputs}: Improve style. {phases}: Add phases 'set-data-path, 'patch-data-path to use store-cached samples for library and tests. Rewrite phase 'prepare-python-module to rely more on the existing info in pyproject.toml. Rewrite phase 'check-python entirely, and marginaly rewrite phase 'install-python-library to match 'check-python phase style. {modules}: Adapt accordingly. {propagated-inputs}: Remove python-pooch. Add python-scipy. (bed-sample-files): Add origin, used in python-bed-reader. * gnu/packages/patches/python-bed-reader-use-store-samples.patch: Add patch. * gnu/local.mk: Record patch. --- gnu/local.mk | 1 + gnu/packages/bioinformatics.scm | 195 ++++++++++++------ .../python-bed-reader-use-store-samples.patch | 147 +++++++++++++ 3 files changed, 284 insertions(+), 59 deletions(-) create mode 100644 gnu/packages/patches/python-bed-reader-use-store-samples.patch diff --git a/gnu/local.mk b/gnu/local.mk index 1bf8f8deba..6c2466114d 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -2008,6 +2008,7 @@ dist_patch_DATA = \ %D%/packages/patches/python-3.12-fix-tests.patch \ %D%/packages/patches/python-accupy-use-matplotx.patch \ %D%/packages/patches/python-accupy-fix-use-of-perfplot.patch \ + %D%/packages/patches/python-bed-reader-use-store-samples.patch \ %D%/packages/patches/python-chai-drop-python2.patch \ %D%/packages/patches/python-clarabel-blas.patch \ %D%/packages/patches/python-docrepr-fix-tests.patch \ diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm index 4dbedc09f9..c5fe295f6c 100644 --- a/gnu/packages/bioinformatics.scm +++ b/gnu/packages/bioinformatics.scm @@ -2167,6 +2167,20 @@ (define-public python-bcbio-gff/biopython-1.73 (modify-inputs (package-propagated-inputs python-bcbio-gff) (replace "python-biopython" python-biopython-1.73)))))) +(define bed-sample-files + (let* ((name "bed-sample-files") + (commit "a06dc0450e484090f15656ffd5d317813a5e1e01") + (revision "0") + (version (git-version "0.0.0" revision commit))) + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/fastlmm/bed-sample-files") + (commit commit))) + (file-name (git-file-name name version)) + (sha256 + (base32 "1ldr2lvgbcykxa9i2s2298mhfh0sz96aaxs5dx217aipa9vsrjwk"))))) + (define-public python-bed-reader (package (name "python-bed-reader") @@ -2176,80 +2190,124 @@ (define-public python-bed-reader (method url-fetch) (uri (pypi-uri "bed_reader" version)) (sha256 - (base32 "1c8ibwvz3b069w7ffh9aasz16lfkmx4z0249c2v909a21mrkkd6n")))) + (base32 "1c8ibwvz3b069w7ffh9aasz16lfkmx4z0249c2v909a21mrkkd6n")) + (modules '((guix build utils))) + ;; Bundled unused javascript & co. + (snippet #~(delete-file-recursively "_static")) + (patches + (search-patches "python-bed-reader-use-store-samples.patch")))) (build-system cargo-build-system) (arguments (list - ;; Many of the tests (both the Rust tests and the Python tests) require - ;; Internet access to fetch samples. - #:tests? #false #:install-source? #false #:features '(list "extension-module") - #:cargo-test-flags '(list "--features=extension-module") + #:cargo-test-flags + '(list "--features=extension-module" + ;; Skip doc tests. + "--lib" "--bins" "--tests" "--" + ;; This test is the only one not matched by our regexp. + "--skip=http_one" + ;; These test require a 84 GB file. + "--skip=http_two" + "--skip=http_cloud_urls_md_3") #:cargo-inputs - `(("rust-anyinput" ,rust-anyinput-0.1) - ("rust-bytecount" ,rust-bytecount-0.6) - ("rust-byteorder" ,rust-byteorder-1) - ("rust-bytes" ,rust-bytes-1) - ("rust-cloud-file" ,rust-cloud-file-0.2) - ("rust-derive-builder" ,rust-derive-builder-0.20) - ("rust-dpc-pariter" ,rust-dpc-pariter-0.4) - ("rust-fetch-data" ,rust-fetch-data-0.2) - ("rust-futures-util" ,rust-futures-util-0.3) - ("rust-itertools" ,rust-itertools-0.13) - ("rust-ndarray" ,rust-ndarray-0.16) - ("rust-ndarray-npy" ,rust-ndarray-npy-0.9) - ("rust-num-traits" ,rust-num-traits-0.2) - ("rust-numpy" ,rust-numpy-0.22) - ("rust-pyo3" ,rust-pyo3-0.22) - ("rust-pyo3-build-config" ,rust-pyo3-build-config-0.22) - ("rust-rayon" ,rust-rayon-1) - ("rust-statrs" ,rust-statrs-0.17) - ("rust-thiserror" ,rust-thiserror-1) - ("rust-tokio" ,rust-tokio-1)) + (list rust-anyinput-0.1 + rust-bytecount-0.6 + rust-byteorder-1 + rust-bytes-1 + rust-cloud-file-0.2 + rust-derive-builder-0.20 + rust-dpc-pariter-0.4 + rust-fetch-data-0.2 + rust-futures-util-0.3 + rust-itertools-0.13 + rust-ndarray-0.16 + rust-ndarray-npy-0.9 + rust-num-traits-0.2 + rust-numpy-0.22 + rust-pyo3-0.22 + rust-pyo3-build-config-0.22 + rust-rayon-1 + rust-statrs-0.17 + rust-thiserror-1 + rust-tokio-1) #:cargo-development-inputs - `(("rust-anyhow" ,rust-anyhow-1) - ("rust-ndarray-rand" ,rust-ndarray-rand-0.15) - ("rust-rusoto-credential" ,rust-rusoto-credential-0.48) - ("rust-temp-testdir" ,rust-temp-testdir-0.2) - ("rust-thousands" ,rust-thousands-0.2)) + (list rust-anyhow-1 + rust-ndarray-rand-0.15 + rust-rusoto-credential-0.48 + rust-temp-testdir-0.2 + rust-thousands-0.2) #:imported-modules (append %cargo-build-system-modules %pyproject-build-system-modules) #:modules '((guix build cargo-build-system) ((guix build pyproject-build-system) #:prefix py:) - (guix build utils)) + (guix build utils) + (ice-9 match) + (ice-9 rdelim)) #:phases #~(modify-phases %standard-phases + (add-after 'configure 'set-data-path + (lambda _ + ;; This var is still necessary despite the patch-data-path phase. + ;; Otherwise more tests fail with a read-only filesystem error. + (setenv "BED_READER_DATA_DIR" #+bed-sample-files))) + (add-after 'unpack 'patch-data-path + (lambda _ + ;; If BED_READER_DATA_DIR is unset, default to bed-sample-files. + (substitute* "bed_reader/_sample_data.py" + (("os\\.environ\\.get\\(\"BED_READER_DATA_DIR\"" all) + (format #f "~a, ~s" all #+bed-sample-files))) + ;; XXX: More work is necessary to use another + ;; version of sample files with BED_READER_DATA_DIR + ;; Currently, only the hardcoded Guix version is working. + (substitute* '("bed_reader/tests/test_open_bed_cloud.py" + "src/bed_cloud.rs" + "src/lib.rs" + "src/supplemental_documents/cloud_urls_etc.md" + "tests/tests_api_cloud.rs") + (("\ +https://raw\\.githubusercontent\\.com/fastlmm/bed-sample-files/main") + (string-append "file://" #+bed-sample-files))) + (substitute* "src/tests.rs" + (("bed_reader/tests/data") + #+bed-sample-files)))) (add-after 'install 'prepare-python-module (lambda _ - ;; We don't use maturin. - (delete-file "pyproject.toml") - (call-with-output-file "pyproject.toml" - (lambda (port) - (format port "\ + ;; We don't use maturin. Conveniently, what we want to drop + ;; from pyproject.toml is at the end of the file. + (rename-file "pyproject.toml" "pyproject.toml.bak") + (call-with-input-file "pyproject.toml.bak" + (lambda (in) + (call-with-output-file "pyproject.toml" + (lambda (out) + (let loop () + (match (read-line in) + ((? eof-object? eof) + eof) + ("[build-system]" + (and (format out "\ [build-system] build-backend = 'setuptools.build_meta' requires = ['setuptools'] + +[tool.setuptools.packages.find] +where = [\".\"] +exclude = [\"src\", \"docs\", \"tests\", \"Cargo.toml\"] "))) - (call-with-output-file "setup.cfg" - (lambda (port) - (format port "\ -[metadata] -name = bed-reader -version = ~a - -[options] -packages = find: - -[options.packages.find] -exclude = - src - docs - tests - Cargo.toml -" #$version))))) + ("samples = [\"pooch>=1.5.0\"]" + (and (format out "samples = []~%") + (loop))) + ("[project]" + (and (format out "\ +[project] +version = ~s +" #$version) + (loop))) + (line + (and (format out "~a~%" line) + (loop))))))))))) (add-after 'prepare-python-module 'enable-bytecode-determinism (assoc-ref py:%standard-phases 'enable-bytecode-determinism)) (add-after 'enable-bytecode-determinism 'build-python-module @@ -2261,16 +2319,35 @@ (define-public python-bed-reader (let ((site (string-append #$output "/lib/python" #$(version-major+minor (package-version python)) - "/site-packages"))) - (mkdir-p site) + "/site-packages/"))) + (mkdir-p (string-append site "bed_reader")) (copy-file "target/release/libbed_reader.so" - (string-append site "/bed_reader/bed_reader.so"))))) + (string-append site "bed_reader/bed_reader.so"))))) (add-after 'install-python-library 'add-install-to-pythonpath (assoc-ref py:%standard-phases 'add-install-to-pythonpath)) (add-after 'add-install-to-pythonpath 'check-python - (lambda* (#:key tests? test-flags #:allow-other-keys) + (lambda* (#:key tests? #:allow-other-keys) (when tests? - (apply invoke "pytest" "-v" #$output test-flags))))))) + (let ((site (string-append #$output "/lib/python" + #$(version-major+minor + (package-version python)) + "/site-packages/")) + (data-dir "bed_reader/tests/data")) + (symlink (canonicalize-path data-dir) + (string-append site data-dir)) + (invoke "pytest" "-v" #$output + ;; These test require a 84 GB file. + "-k" (string-join + (list "not test_http_two" + "test_http_cloud_urls_rst_3" + "test_http_cloud_urls_rst_4" + ;; XXX: python-pooch dependency removed + "test_optional_dependencies") + " and not ")) + (delete-file-recursively + (string-append site "bed_reader/tests")) + (delete-file-recursively + (string-append #$output "/.pytest_cache"))))))))) (native-inputs (list python-pytest python-pytest-cov python-pytest-datadir @@ -2278,7 +2355,7 @@ (define-public python-bed-reader python-recommonmark python-sphinx)) (inputs (list python-wrapper)) - (propagated-inputs (list python-numpy python-pandas python-pooch)) + (propagated-inputs (list python-numpy python-pandas python-scipy)) (home-page "https://fastlmm.github.io/") (synopsis "Read and write the PLINK BED format, simply and efficiently") (description diff --git a/gnu/packages/patches/python-bed-reader-use-store-samples.patch b/gnu/packages/patches/python-bed-reader-use-store-samples.patch new file mode 100644 index 0000000000..813f155225 --- /dev/null +++ b/gnu/packages/patches/python-bed-reader-use-store-samples.patch @@ -0,0 +1,147 @@ +From 7e6bcdfeed54500ca533d2f0eb12078248c43c77 Mon Sep 17 00:00:00 2001 +Message-ID: <7e6bcdfeed54500ca533d2f0eb12078248c43c77.1743682382.git.ngraves@ngraves.fr> +From: Nicolas Graves +Date: Thu, 3 Apr 2025 11:33:58 +0200 +Subject: [PATCH] samples: Use deterministic samples in Guix. + +--- + bed_reader/_sample_data.py | 86 +++++++++----------------------------- + 1 file changed, 19 insertions(+), 67 deletions(-) + +diff --git a/bed_reader/_sample_data.py b/bed_reader/_sample_data.py +index 6ca4cc0..6a1146e 100644 +--- a/bed_reader/_sample_data.py ++++ b/bed_reader/_sample_data.py +@@ -1,33 +1,8 @@ ++import os + import tempfile + from pathlib import Path, PurePath + from typing import Union + +-try: +- import pooch +- +- """ +- Load sample data. +- """ +- +- POOCH = pooch.create( +- # Use the default cache folder for the OS +- path=pooch.os_cache("bed_reader"), +- # The remote data is on Github +- base_url="https://raw.githubusercontent.com/" +- + "fastlmm/bed-sample-files/main/", +- # If this is a development version, get the data from the master branch +- version_dev="main", +- # The registry specifies the files that can be fetched +- env="BED_READER_DATA_DIR", +- ) +- +- # Get registry file from package_data +- registry_file = Path(__file__).parent / "tests/registry.txt" +- # Load this registry file +- POOCH.load_registry(registry_file) +-except ImportError: +- pooch = None +- + + def sample_file(filepath: Union[str, Path]) -> str: + """Retrieve a sample .bed file. (Also retrieves associated .fam and .bim files). +@@ -40,50 +15,41 @@ def sample_file(filepath: Union[str, Path]) -> str: + Returns + ------- + str +- Local name of sample .bed file. +- +- +- .. note:: +- This function requires the :mod:`pooch` package. Install `pooch` with: +- +- .. code-block:: bash +- +- pip install --upgrade bed-reader[samples] +- +- +- By default this function puts files under the user's cache directory. +- Override this by setting +- the `BED_READER_DATA_DIR` environment variable. ++ Local path of sample .bed file. + + Example + -------- + + .. doctest:: + +- >>> # pip install bed-reader[samples] # if needed + >>> from bed_reader import sample_file + >>> + >>> file_name = sample_file("small.bed") + >>> print(f"The local file name is '{file_name}'") + The local file name is '...small.bed' +- + """ +- if pooch is None: +- raise ImportError( +- "The function sample_file() requires pooch. " +- + "Install it with 'pip install --upgrade bed-reader[samples]'.", ++ filepath = Path(filepath) ++ sample_dir = os.environ.get("BED_READER_DATA_DIR") ++ if sample_dir is None: ++ raise EnvironmentError( ++ "BED_READER_DATA_DIR environment variable is not set. " ++ "This should point to the directory containing the sample files." + ) + +- filepath = Path(filepath) +- file_string = str(filepath) +- if file_string.lower().endswith(".bed"): +- POOCH.fetch(file_string[:-4] + ".fam") +- POOCH.fetch(file_string[:-4] + ".bim") +- return POOCH.fetch(file_string) ++ file_path = Path(sample_dir) / filepath ++ ++ # Check if file exists ++ if not file_path.exists(): ++ raise FileNotFoundError( ++ f"Sample file '{filepath}' not found in {sample_dir}. " ++ f"Make sure you're using the latest samples in BED_READER_DATA_DIR." ++ ) ++ ++ return str(file_path) + + + def sample_url(filepath: Union[str, Path]) -> str: +- """Retrieve a URL to a sample .bed file. (Also makes ready associated .fam and .bim files). ++ """Retrieve a URL to a sample .bed file. + + Parameters + ---------- +@@ -95,25 +61,11 @@ def sample_url(filepath: Union[str, Path]) -> str: + str + URL to sample .bed file. + +- +- .. note:: +- This function requires the :mod:`pooch` package. Install `pooch` with: +- +- .. code-block:: bash +- +- pip install --upgrade bed-reader[samples] +- +- +- By default this function puts files under the user's cache directory. +- Override this by setting +- the `BED_READER_DATA_DIR` environment variable. +- + Example + -------- + + .. doctest:: + +- >>> # pip install bed-reader[samples] # if needed + >>> from bed_reader import sample_url + >>> + >>> url = sample_url("small.bed") +-- +2.49.0 +