[Import-SIG] Loading Resources From a Python Module/Package
donald at stufft.io
Sun Feb 1 02:08:54 CET 2015
> On Jan 31, 2015, at 7:59 PM, Donald Stufft <donald at stufft.io> wrote:
>> How this is implemented in the Loader() API can be whatever folks want. The important thing is that these all solve actual use cases and solve them better and easier than the naive approach of using os.path functions directly.
>> Important Things:
>> * resource_filename and ResourceFilename() must return the real file system path if available and a temporary file else wise.
>> * resource_filename *must* be available for the lifetime of the process once the function has been called.
>> * ResourceFilename *must* clean itself up at the end of the context manager.
>> * These functions/context managers *must* work in terms of package names and relative file paths.
>> All seem reasonable to me.
Oh, one additional thing that I think is important:
They should work with modules (foo -> foo.py), packages (foo -> foo/__init__.py), old style “namespace” packages via extending __path__ (foo -> multiple foo/__init__.py ), new style namespace packages (foo -> multiple foo/). What file path to use is obvious in the first two cases because there is only one candidate file. For the other two I think it should just use the order of the __path__ and return the first one it finds (or None/Exception if it doesn’t find one).
PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Import-SIG