Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork48
Description
In GitLab by @rob.speer on May 16, 2018, 01:23
Suppose I have a Web application,myapp, that needs to serve a static file, which by convention needs to be in the pathmyapp/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 namedmyapp/static/__init__.py andmyapp/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 ofpkg_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 ispath(myapp, "static/ld/context.ld.json").