Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package uses non-standard site-package paths for resources #25

Closed
pbenner opened this issue May 1, 2023 · 4 comments
Closed

Package uses non-standard site-package paths for resources #25

pbenner opened this issue May 1, 2023 · 4 comments
Labels
discussion Needs discussion pkg PyPI package related

Comments

@pbenner
Copy link
Collaborator

pbenner commented May 1, 2023

The package seems to use the following non-standard paths:

[...]/site-packages/tmp
[...]/site-packages/data

Please use pkg_resources for determining package resource paths.

@janosh
Copy link
Owner

janosh commented May 1, 2023

pkg_resources is deprecated. Maybe we should use importlib.resources. I'll have to read up on that.

@janosh janosh added pkg PyPI package related discussion Needs discussion labels May 1, 2023
@janosh
Copy link
Owner

janosh commented Nov 28, 2023

@pbenner are the /tmp and /data directories empty or actually used for anything. maybe the solution is just to get rid of this or check if the package is using an editable install before running this.

for directory in [SITE_FIGS, SITE_MODELS, FIGSHARE, PDF_FIGS]:
os.makedirs(directory, exist_ok=True)

@pbenner
Copy link
Collaborator Author

pbenner commented Nov 29, 2023

The [...]/site-packages/data directory is created when installing the package and it contains the figshare files, because of:

matbench_discovery = ["../data/figshare/*"]

One solution would be to move the data/figshare folder into the matbench_discovery folder. But I guess it would take a few more modifications to turn it into a real python package. For instance, this is not compatible:

ROOT = os.path.dirname(os.path.dirname(__file__)) # repo root directory
DATA_DIR = f"{ROOT}/data" # directory to store raw data
SITE_FIGS = f"{ROOT}/site/src/figs" # directory for interactive figures
SITE_MODELS = f"{ROOT}/site/src/routes/models" # directory to write model analysis
FIGSHARE = f"{ROOT}/data/figshare"
SCRIPTS = f"{ROOT}/scripts"
PDF_FIGS = f"{ROOT}/paper/figs" # directory for light-themed PDF figures

The ROOT variable points to the [...]/site-package directory.

@janosh
Copy link
Owner

janosh commented Jan 15, 2024

@pbenner Sorry this took ages to address. I think I fixed the supporting data directories being created in root-level /site-packages in 55ab66b. This dynamic way of deciding where data files go feels like a bad solution:

# check if package is installed in editable mode
# hopefully better method coming in https://github.com/pypa/setuptools/issues/4186
pkg_is_editable = os.path.isdir(f"{PKG_DIR}/../matbench_discovery.egg-info")
# repo root directory if editable install, else the pkg directory
ROOT = os.path.dirname(PKG_DIR) if pkg_is_editable else PKG_DIR

I opened pypa/setuptools#4186 to either design a less hacky way of implementing this or maybe learn how to better address the underlying issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Needs discussion pkg PyPI package related
Projects
None yet
Development

No branches or pull requests

2 participants