Using static files in a library

I have a library that uses some static (.csv) files in certain functions, i.e., you call the function, and it reads one of these files and produces an output. These functions are mostly used in mix tasks for development/testing purposes. There is however some possibility that someone would want to use them in production, so I am considering including them when I publish the library to hex.

Given this, I have two questions:

  1. Is there a convention as to what directory this type of file goes in? (There was a similar question asked this morning but I think the circumstances might be a little different)

  2. In dev/test, the path for the directory where I tentatively keep the files is top_level/datasets, but if this package is included in some other project the path will be top_level/deps/library_name/datasets. I think I could just modify the functions to use the right path at compile time using Mix.env but using Mix.env for almost anything seems to be frowned upon, so I am not confident that is the best approach.

This is not related to CSV, but it may be a good source of inspiration:

Following ElixirSchool you should use Application.app_dir/2:

Application.app_dir(:app_name, "priv/datasets")
# or
Path.join(:code.priv_dir(:app_name), "datasets")

Libraries which may be helpful for you:

1 Like