From 050c0a4c6d733c23f4a2cdd7b9d100512783bf94 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Tue, 3 Mar 2026 16:08:11 -0500 Subject: [PATCH 1/3] load interpolation data with importlib --- src/diffpy/labpdfproc/functions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/diffpy/labpdfproc/functions.py b/src/diffpy/labpdfproc/functions.py index 7ecd126..8d7a76a 100644 --- a/src/diffpy/labpdfproc/functions.py +++ b/src/diffpy/labpdfproc/functions.py @@ -1,6 +1,6 @@ import math import warnings -from pathlib import Path +from importlib.resources import files import numpy as np import pandas as pd @@ -17,11 +17,11 @@ CVE_METHODS = ["brute_force", "polynomial_interpolation"] # Pre-computed datasets for polynomial interpolation (fast calculation) +data_dir = files("diffpy.labpdfproc") / "data" MUD_LIST = np.array([0.5, 1, 2, 3, 4, 5, 6, 7]) -CWD = Path(__file__).parent.resolve() -MULS = np.loadtxt(CWD / "data" / "inverse_cve.xy") +MULS = np.loadtxt(data_dir / "inverse_cve.xy") COEFFICIENT_LIST = np.array( - pd.read_csv(CWD / "data" / "coefficient_list.csv", header=None) + pd.read_csv(data_dir / "coefficient_list.csv", header=None) ) INTERPOLATION_FUNCTIONS = [ interp1d(MUD_LIST, coeffs, kind="quadratic") for coeffs in COEFFICIENT_LIST From 9e35c846e6bb064273d66810c0c278d9c10b7c4a Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Tue, 3 Mar 2026 16:14:05 -0500 Subject: [PATCH 2/3] news --- news/load-data.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/load-data.rst diff --git a/news/load-data.rst b/news/load-data.rst new file mode 100644 index 0000000..4b614de --- /dev/null +++ b/news/load-data.rst @@ -0,0 +1,23 @@ +**Added:** + +* No news added: change how data path is referenced. Remove ``__file__`` reference. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* From 19dfb6231984507852294c7765e27be9ba9d1941 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Tue, 3 Mar 2026 16:22:49 -0500 Subject: [PATCH 3/3] add package-data so the data dir will be included at runtime --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index a55f107..b7ac149 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,9 @@ include = ["*"] # package names should match these glob patterns (["*"] by defa exclude = ["diffpy.labpdfproc.tests*"] # exclude packages matching these glob patterns (empty by default) namespaces = false # to disable scanning PEP 420 namespaces (true by default) +[tool.setuptools.package-data] +"diffpy.labpdfproc" = ["data/*"] + [tool.setuptools.dynamic] dependencies = {file = ["requirements/pip.txt"]}