Nick Coghlan <ncogh...@gmail.com> added the comment:

It turns out pydoc's CLI is looking specifically for '' in sys.path, but *not* 
looking for "os.getcwd()".

The resulting sys.path manipulation then goes completely wrong for "python -m 
pydoc", since it ends up removing "scriptdir" from sys.path, and that's the 
directory containing "pydoc" and the rest of the standard library.

It surprised me that you were getting the misbehaviour for the direct pydoc 
command though, as for me, that's a separate script living in `*/bin`, so the 
misbehaviour doesn't happen (only the bin directory gets removed from sys.path, 
which is the desired behaviour).

It turns out that behaviour is due to a difference between venv and virtualenv, 
where the latter defines a shell alias to hide the filesystem level pydoc 
scripts installed system wide:

```
$ which pydoc                                                                   
                                                                    
pydoc ()                                                                        
                                                                                
                                        
{                                                                               
                                                                                
                                        
    python -m pydoc "$@"                                                        
                                                                                
                                        
}
```

and hence will encounter the problem.

So I think there are two changes needed here:

1. Update pydoc.cli() to search sys.path for "os.getcwd()" in addition to 
searching for the empty string.
2. Rewording the note in the porting guide to explicitly call out checks for 
"'' in sys.path" in start-up code as potentially requiring updates

----------
assignee:  -> ncoghlan

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33185>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to