Add an ExecutionLoader abc to importlib or to runpy?

I implemented get_filename() as specified in PEP 302 for importlib's source and bytecode loaders and I was starting to create the ABC for importlib.abc, but then I realized that perhaps the loader should live in runpy instead of importlib. Putting the new ABC in importlib keeps all PEP 302 ABCs in a single spot. But this addition to the PEP 302 protocols is very specific to runpy and is not directly required to make imports work (the implementation was just a reshuffling of pre-existing code from one method to another). I am tempted to leave the ABC out of importlib and stop at implementing get_filename() for importlib.abc.PyLoader and PyPycLoader. Any opinions? -Brett

Brett Cannon <brett <at> python.org> writes:
I implemented get_filename() as specified in PEP 302 for importlib's source
and bytecode loaders and I was starting to create the ABC for importlib.abc, but then I realized that perhaps the loader should live in runpy instead of importlib.
Putting the new ABC in importlib keeps all PEP 302 ABCs in a single spot. But
this addition to the PEP 302 protocols is very specific to runpy and is not directly required to make imports work (the implementation was just a reshuffling of pre-existing code from one method to another). I am tempted to leave the ABC out of importlib and stop at implementing get_filename() for importlib.abc.PyLoader and PyPycLoader. I am not sure when this discussion started. Are you replying to a 3 month-old message of yours? :) In any case, keeping all import-related ABCs in a single place sounds like a good idea. Alternatively, if the method is runpy specific, it doesn't have its place in an ABC, does it? Antoine.

Antoine Pitrou wrote:
I am not sure when this discussion started. Are you replying to a 3 month-old message of yours? :)
That depends on how you define the beginning of the discussion... However, the fact that importlib doesn't implement the comparatively recent get_filename() optional extension documented in PEP 302 came up in one of the PEP 376 threads within the last week or so.
While runpy is the only client in the standard library for the get_filename() method, the method is still a PEP 302 extension. I documented the extension in the PEP as loaders are the only things reliably in a position to provide the filename details that runpy needs to set __file__ and sys.argv[0] correctly and until importlib came along PEP 302 itself was the only real documentation of that API. Since importlib is now the "go-to" location for people that want to write their own PEP 302 importers and loaders, I would say that it is also the right place for the new ExecutionLoader ABC. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------

On Wed, Jul 15, 2009 at 06:51, Nick Coghlan <ncoghlan@gmail.com> wrote:
Especially since I was offlist three months ago. =)
I have been ignoring the PEP 372 discussions since I came into it late and I don't deal with packaging enough to want to influence the discussion, so I missed that point being made.
OK. I will add an ExecutionLoader ABC to importlib that simply subclasses InspectLoader and adds the get_filename() abstract method. Thanks to everyone for their feedback. -Brett

Brett Cannon wrote:
Since I'm pretty sure you were the one that mentioned it, it's possible I just misremembered which thread it came up in. The various discussions can blur together sometimes! Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------

Brett Cannon <brett <at> python.org> writes:
I implemented get_filename() as specified in PEP 302 for importlib's source
and bytecode loaders and I was starting to create the ABC for importlib.abc, but then I realized that perhaps the loader should live in runpy instead of importlib.
Putting the new ABC in importlib keeps all PEP 302 ABCs in a single spot. But
this addition to the PEP 302 protocols is very specific to runpy and is not directly required to make imports work (the implementation was just a reshuffling of pre-existing code from one method to another). I am tempted to leave the ABC out of importlib and stop at implementing get_filename() for importlib.abc.PyLoader and PyPycLoader. I am not sure when this discussion started. Are you replying to a 3 month-old message of yours? :) In any case, keeping all import-related ABCs in a single place sounds like a good idea. Alternatively, if the method is runpy specific, it doesn't have its place in an ABC, does it? Antoine.

Antoine Pitrou wrote:
I am not sure when this discussion started. Are you replying to a 3 month-old message of yours? :)
That depends on how you define the beginning of the discussion... However, the fact that importlib doesn't implement the comparatively recent get_filename() optional extension documented in PEP 302 came up in one of the PEP 376 threads within the last week or so.
While runpy is the only client in the standard library for the get_filename() method, the method is still a PEP 302 extension. I documented the extension in the PEP as loaders are the only things reliably in a position to provide the filename details that runpy needs to set __file__ and sys.argv[0] correctly and until importlib came along PEP 302 itself was the only real documentation of that API. Since importlib is now the "go-to" location for people that want to write their own PEP 302 importers and loaders, I would say that it is also the right place for the new ExecutionLoader ABC. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------

On Wed, Jul 15, 2009 at 06:51, Nick Coghlan <ncoghlan@gmail.com> wrote:
Especially since I was offlist three months ago. =)
I have been ignoring the PEP 372 discussions since I came into it late and I don't deal with packaging enough to want to influence the discussion, so I missed that point being made.
OK. I will add an ExecutionLoader ABC to importlib that simply subclasses InspectLoader and adds the get_filename() abstract method. Thanks to everyone for their feedback. -Brett

Brett Cannon wrote:
Since I'm pretty sure you were the one that mentioned it, it's possible I just misremembered which thread it came up in. The various discussions can blur together sometimes! Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
participants (4)
-
Antoine Pitrou
-
Brett Cannon
-
Nick Coghlan
-
Paul Moore