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

static assets in python package #36

Closed
jettjaniak opened this issue Feb 16, 2024 · 3 comments · Fixed by #41
Closed

static assets in python package #36

jettjaniak opened this issue Feb 16, 2024 · 3 comments · Fixed by #41
Assignees
Labels
askjai Ask Jai for more information about this feature New feature or request

Comments

@jettjaniak
Copy link
Contributor

@jaidhyani has more context

@jettjaniak jettjaniak added the feature New feature or request label Feb 16, 2024
@jaidhyani
Copy link
Collaborator

See: https://setuptools.pypa.io/en/latest/userguide/datafiles.html#package-data

Given dir structure:

project_root_directory
├── setup.py        # and/or setup.cfg, pyproject.toml
└── src
    └── mypkg
        ├── __init__.py
        ├── data1.rst
        ├── data2.rst
        ├── data1.txt
        └── data2.txt

You can add a package_data arg to setup.py:

from setuptools import setup, find_packages
setup(
    # ...,
    packages=find_packages(where="src"),
    package_dir={"": "src"},
    package_data={"mypkg": ["*.txt", "*.rst"]}
)

And then access the static assets at runtime:

from importlib.resources import files
data_text = files('mypkg').joinpath('data1.txt').read_text()

@jaidhyani
Copy link
Collaborator

We want all static assets we're generating and want to be part of the project - pickles, csvs, whatever - to go to a standard data dir. How about src/delphi/static/?

@jaidhyani jaidhyani added the askjai Ask Jai for more information about this label Feb 16, 2024
@jettjaniak
Copy link
Contributor Author

also move the files that are elsewhere now and paths in scripts that produce files

@menamerai menamerai self-assigned this Feb 17, 2024
@menamerai menamerai linked a pull request Feb 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
askjai Ask Jai for more information about this feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants