In a Python package I have a data file which is nested 'above' a file which requires it. e.g.
package
data
data.csv
utils
util.py
In util.py I obtain the file as a stream using pkg_resources; this allows the code to be run from source and when installed as a package.
data_stream = pkg_resources.resource_stream(
__name__, os.path.join("..", "data", "data.csv")
)
This works fine, and allows the data file to be retrieved as expected.
However, when I run tests which use the code in util.py, a Deprecationwarning is revealed, stating "DeprecationWarning: Use of .. or absolute path in a resource path is not allowed and will raise exceptions in a future release."
But I'm not sure what the correct way to approach this is?