Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-12-07 Thread M.-A. Lemburg
On 07.12.2016 13:57, Nick Coghlan wrote: > On 7 December 2016 at 18:33, M.-A. Lemburg wrote: >> I know that you started this thread focusing on the stdlib, >> but for the purpose of distributors, the scope goes far >> beyond just the stdlib. >> >> Basically any Python module or

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-12-07 Thread Stephen J. Turnbull
Nick Coghlan writes: > While upstream changes turned out not to be necessary for the > "distributor breaking up the standard library" use case, they may > still prove worthwhile in making import errors more informative in the > case of "I just built my own Python from upstream sources and

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-12-07 Thread Nick Coghlan
On 7 December 2016 at 18:33, M.-A. Lemburg wrote: > I know that you started this thread focusing on the stdlib, > but for the purpose of distributors, the scope goes far > beyond just the stdlib. > > Basically any Python module or package which the distribution can > provide

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-12-07 Thread M.-A. Lemburg
I know that you started this thread focusing on the stdlib, but for the purpose of distributors, the scope goes far beyond just the stdlib. Basically any Python module or package which the distribution can provide should be usable as basis for a nice error message pointing to the package to

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-12-06 Thread Tomas Orsava
On 12/06/2016 03:27 AM, Nick Coghlan wrote: On 5 December 2016 at 22:53, Tomas Orsava wrote: On 12/05/2016 01:42 PM, Nick Coghlan wrote: Essentially, that would be the "name.missing.py" part of the draft proposal for optional standard library modules, just with a regular

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-12-05 Thread Nick Coghlan
On 5 December 2016 at 19:56, Tomas Orsava wrote: > On 12/03/2016 05:08 AM, Nick Coghlan wrote: >>> >>> Though I believe the default sys.excepthook function is currently written >>> in >>> C, so it wouldn't be very easy for distributors to customize it. Maybe it >>> could be

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-12-05 Thread Tomas Orsava
On 12/05/2016 01:42 PM, Nick Coghlan wrote: On 5 December 2016 at 19:56, Tomas Orsava wrote: On 12/03/2016 05:08 AM, Nick Coghlan wrote: Though I believe the default sys.excepthook function is currently written in C, so it wouldn't be very easy for distributors to

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-12-05 Thread Tomas Orsava
On 12/03/2016 05:08 AM, Nick Coghlan wrote: Though I believe the default sys.excepthook function is currently written in C, so it wouldn't be very easy for distributors to customize it. Maybe it could be made to read module=error_message pairs from some external file, which would be easier to

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Nick Coghlan
On 30 November 2016 at 04:33, Brett Cannon wrote: > On Tue, 29 Nov 2016 at 06:49 Nick Coghlan wrote: >> >> On 29 November 2016 at 20:54, Tomas Orsava wrote: >> > With a metapath hook, .missing.py files are probably overkill, and the >> >

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Eric V. Smith
On 11/29/2016 1:33 PM, Brett Cannon wrote: On Tue, 29 Nov 2016 at 06:49 Nick Coghlan > wrote: On 29 November 2016 at 20:54, Tomas Orsava > wrote: > With a metapath hook, .missing.py files

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Brett Cannon
On Tue, 29 Nov 2016 at 06:49 Nick Coghlan wrote: > On 29 November 2016 at 20:54, Tomas Orsava wrote: > > With a metapath hook, .missing.py files are probably overkill, and the > hook > > can just look at one file (or a static compiled-in list) of > >

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Todd
On Tue, Nov 29, 2016 at 4:13 AM, M.-A. Lemburg wrote: > On 29.11.2016 00:50, Brett Cannon wrote: > > Seventh, these *.missing.py files if they are directly executed are > totally > > going to be abused like *.pth files, I can just feel it in my bones. We > > need to be okay with

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Todd
On Nov 29, 2016 5:51 AM, "Wolfgang Maier" < wolfgang.ma...@biologie.uni-freiburg.de> wrote: > > On 29.11.2016 10:39, Paul Moore wrote: >> >> On 28 November 2016 at 22:33, Steve Dower wrote: >>> >>> Given that, this wouldn't necessarily need to be an executable file. The

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Nick Coghlan
On 29 November 2016 at 20:54, Tomas Orsava wrote: > With a metapath hook, .missing.py files are probably overkill, and the hook > can just look at one file (or a static compiled-in list) of > ModuleNotFound/ImportError messages for all missing modules, as M.-A. > Lemburg and

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Nick Coghlan
On 29 November 2016 at 03:28, Guido van Rossum wrote: > On Mon, Nov 28, 2016 at 9:14 AM, Nathaniel Smith wrote: >> >> Also note that in Guido's option 2, we only incur the extra fstat calls if >> the import would otherwise fail. In option 1, there are extra

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Paul Moore
On 29 November 2016 at 10:51, Wolfgang Maier wrote: > On 29.11.2016 10:39, Paul Moore wrote: >> >> On 28 November 2016 at 22:33, Steve Dower wrote: >>> >>> Given that, this wouldn't necessarily need to be an executable file. The

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Tomas Orsava
On 11/28/2016 05:38 PM, Guido van Rossum wrote: Overall I think this is a good idea. I have one hit: It seems that there are two possible strategies for searching the .missing.py file: 1. (Currently in the PEP) search it at the same time as the .py file when walking along sys.path. - Pro:

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Wolfgang Maier
On 29.11.2016 10:39, Paul Moore wrote: On 28 November 2016 at 22:33, Steve Dower wrote: Given that, this wouldn't necessarily need to be an executable file. The finder could locate a "foo.missing" file and raise ModuleNotFoundError with the contents of the file as the

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Cory Benfield
> On 29 Nov 2016, at 02:48, Chris Angelico wrote: > > On Tue, Nov 29, 2016 at 12:14 PM, Steven D'Aprano wrote: >> What if I have two files? >> >> # a.py >> try: >>import spam >> except ImportError: >>import ham as spam >> >> # b.py >> try: >>

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread Paul Moore
On 28 November 2016 at 22:33, Steve Dower wrote: > Given that, this wouldn't necessarily need to be an executable file. The > finder could locate a "foo.missing" file and raise ModuleNotFoundError with > the contents of the file as the message. No need to allow/require any

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-29 Thread M.-A. Lemburg
On 29.11.2016 00:50, Brett Cannon wrote: > Seventh, these *.missing.py files if they are directly executed are totally > going to be abused like *.pth files, I can just feel it in my bones. We > need to be okay with this if we accept this PEP as-is. Since the purpose of the PEP was to allow

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 12:14 PM, Steven D'Aprano wrote: > What if I have two files? > > # a.py > try: > import spam > except ImportError: > import ham as spam > > # b.py > try: > import spam > except ImportError: > import cornedbeef as spam > In the same

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 05:46 PM, Random832 wrote: On Mon, Nov 28, 2016, at 15:05, Ethan Furman wrote: Because it is unfriendly. Helpful error messages are a great tool to both beginner and seasoned programmers. There won't be a helpful error message unless the distributor writes one. The purpose

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Steven D'Aprano
On Tue, Nov 29, 2016 at 09:52:21AM +1100, Chris Angelico wrote: > +1, because this also provides a coherent way to reword the try/except > import idiom: > > # Current idiom > # somefile.py > try: > import foo > except ImportError: > import subst_foo as foo Nice, clean and

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Steven D'Aprano
On Mon, Nov 28, 2016 at 12:05:01PM -0800, Ethan Furman wrote: > >Honestly, though, I'm not sure of the need for the PEP in general. > >"However, there is as of yet no standardized way of dealing with > >importing a missing standard library module." is simply not true. The > >standardized way of

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Steven D'Aprano
On Mon, Nov 28, 2016 at 02:32:16PM +, Paul Moore wrote: > Also, and possibly more of an issue, use of the ".missing.py" file > will mean that a user can't provide their own implementation of the > module later on sys.path. I don'rt know if this is a significant issue > on Unix platforms. On

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Brett Cannon
On Mon, 28 Nov 2016 at 14:49 Steve Dower wrote: > On 28Nov2016 1433, Steve Dower wrote: > > On 28Nov2016 1419, Nathaniel Smith wrote: > >> I'd suggest that we additional specify that if we find a > >> foo.missing.py, then the code is executed but -- unlike a regular > >>

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Wolfgang Maier
On 28.11.2016 23:52, Chris Angelico wrote: +1, because this also provides a coherent way to reword the try/except import idiom: # Current idiom # somefile.py try: import foo except ImportError: import subst_foo as foo # New idiom: # foo.missing.py import subst_foo as foo import sys;

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 9:19 AM, Nathaniel Smith wrote: > This also suggests that the overall error-handling flow for 'import > foo' should look like: > > 1) run foo.missing.py > 2) if it raises an exception: propagate that > 3) otherwise, if sys.modules["foo"] is missing: raise

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Wolfgang Maier
On 28.11.2016 23:19, Nathaniel Smith wrote: I'd suggest that we additional specify that if we find a foo.missing.py, then the code is executed but -- unlike a regular module load -- it's not automatically inserted into sys.modules["foo"]. That seems like it could only create confusion. And it

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Nathaniel Smith
On Mon, Nov 28, 2016 at 5:28 AM, Tomas Orsava wrote: [...] > Specification > = > > When, for any reason, a standard library module is not to be included with > the > rest, a file with its name and the extension ``.missing.py`` shall be > created > and placed in the

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 01:26 PM, Paul Moore wrote: On 28 November 2016 at 21:11, Ethan Furman wrote: One "successful" use-case that would be impacted is the fallback import idiom: try: # this would do two full searches before getting the error import BlahBlah except

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Chris Barker
On Mon, Nov 28, 2016 at 1:26 PM, Paul Moore wrote: > > One "successful" use-case that would be impacted is the fallback import > > idiom: > > > > try: > > # this would do two full searches before getting the error > > import BlahBlah > > except ImportError: > >

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Wolfgang Maier
On 28.11.2016 22:26, Paul Moore wrote: On 28 November 2016 at 21:11, Ethan Furman wrote: One "successful" use-case that would be impacted is the fallback import idiom: try: # this would do two full searches before getting the error import BlahBlah except

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Paul Moore
On 28 November 2016 at 21:11, Ethan Furman wrote: > One "successful" use-case that would be impacted is the fallback import > idiom: > > try: > # this would do two full searches before getting the error > import BlahBlah > except ImportError: > import blahblah

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 01:01 PM, Guido van Rossum wrote: On Mon, Nov 28, 2016 at 12:51 PM, Ethan Furman wrote: On 11/28/2016 05:28 AM, Tomas Orsava wrote: Rendered PEP: https://fedora-python.github.io/pep-drafts/pep-A.html Overall +1, but

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 05:28 AM, Tomas Orsava wrote: Rendered PEP: https://fedora-python.github.io/pep-drafts/pep-A.html Overall +1, but using Guido's #2 option instead for handling *.missing.py files (searching all possible locations for the module before falling back to the stdlib xxx.missing.py

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Terry Reedy
On 11/28/2016 11:38 AM, Guido van Rossum wrote: Overall I think this is a good idea. I have one hit: It seems that there are two possible strategies for searching the .missing.py file: 1. (Currently in the PEP) search it at the same time as the .py file when walking along sys.path. - Pro:

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Nathaniel Smith
On Nov 28, 2016 8:38 AM, "Guido van Rossum" wrote: > > Overall I think this is a good idea. I have one hit: > > It seems that there are two possible strategies for searching the .missing.py file: > > 1. (Currently in the PEP) search it at the same time as the .py file when

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Alexandre Brault
I would also prefer (2) for exactly the example given in this thread. The Windows version of curses.missing.py could raise a ModuleNotFoundError saying that curses is not available on Windows, but a developer who wants to can install PDCurses to implement the stdlib module. I don't think the few

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Paul Moore
On 28 November 2016 at 15:51, Tomas Orsava wrote: > I believe I may have found the Windows curses implementation, it's called > PDCurses [0], and this website [1] appears to be distributing it under the > name `curses`. My apologies, I should have included a pointer. That is

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Tomas Orsava
On 11/28/2016 03:32 PM, Paul Moore wrote: On 28 November 2016 at 13:28, Tomas Orsava wrote: The ``.missing.py`` extension will be added to the end of the list, and configured to be handled by ``SourceFileLoader``. Thus, if a module is not found in its proper location, the

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Paul Moore
On 28 November 2016 at 13:28, Tomas Orsava wrote: > The ``.missing.py`` extension will be added to the end of the list, and > configured to be handled by ``SourceFileLoader``. Thus, if a module is not > found in its proper location, the ``XYZ.missing.py`` file is found and >

[Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Tomas Orsava
Hi! We have written a draft PEP entitled "Distributing a Subset of the Standard Library" that aims to standardize and improve how Python handles omissions from its standard library. This is relevant both to Python itself as well as to Linux and other distributions that are packaging it, as