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

Pre-loading example data #4

Open
juanfung opened this issue Apr 6, 2018 · 1 comment
Open

Pre-loading example data #4

juanfung opened this issue Apr 6, 2018 · 1 comment
Assignees

Comments

@juanfung
Copy link
Owner

juanfung commented Apr 6, 2018

Data used in the examples currently stored under pycge/pycge/data/, and included in MANIFEST.in

Example model definitions and scripts, currently stored under pycge/pycge/examples/, can be loaded as modules; e.g., from pycge.examples.splcge_model_def import SplModelDef.

A user cannot easily access the data. The best option afaik is:

import os, sys
os.path.dirname(sys.modules['pycge'].__file__)+'/data/path_to_data' 

It might be better to automatically load the data when loading the module. For example, by adding the above commands to splcge_model_def.py.

@juanfung juanfung self-assigned this Apr 6, 2018
@juanfung
Copy link
Owner Author

juanfung commented Oct 16, 2019

A better solution is to use pkg_resources, included in setuptools: see ResourceManager API, eg:

import pkg_resources
spl_path = pkg_resources.resource_filename('pycge', 'data/splcge_data_dir')

This can be included in splcge.py or another file (or wrapped in a function loaded with pycge).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant