Allow resources to be in subdirectories
Suppose I have a Web application, myapp
, that needs to serve a static file, which by convention needs to be in the path myapp/static/ld/context.ld.json
. Suppose I also want to be able to access that file from Python code, because its contents are used in a test.
As importlib_resources is currently defined, I would need to rewrite the path as if it were a Python submodule, even though it does not contain actual Python code: path(myapp.static.ld, "context.ld.json")
. I would also need to create empty files named myapp/static/__init__.py
and myapp/static/ld/__init__.py
, and hopefully exclude them from being served as static files.
That would be enough for me to give up and use paths relative to __file__
instead. In general, I would heartily recommend importlib if I could reasonably promise that it was an improvement over using __file__
or over existing uses of pkg_resources
, which it wouldn't be if it doesn't support subdirectories.
The call I would like to be able to make in this situation is path(myapp, "static/ld/context.ld.json")
.