[issue31874] [feature] runpy.run_module should mimic script launch behavior for sys.path

2019-09-03 Thread Nick Coghlan


Nick Coghlan  added the comment:

Good point regarding the heuristic: it would need to take the requested module 
name into account to be correct.

* check if the requested module was found relative to the current directory 
(can be worked out from __main__.__spec__ and the current working directory)
* if it was, make sys.path[0] the absolute path of the current directory
* otherwise, remove sys.path[0] entirely

--
nosy: +ncoghlan

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31874] [feature] runpy.run_module should mimic script launch behavior for sys.path

2018-08-11 Thread Jason R. Coombs


Jason R. Coombs  added the comment:

In [setuptools 1453](https://github.com/pypa/setuptools/issues/1453), this 
issue hit the project hard. Tox 3.2 changed the default invocation of pip from 
the script-based invocation to the runpy based implementation (python -m pip), 
which causes pip to be unable to uninstall the setuptools in the environment.

This use case also reveals that the heuristic of "retain '' in sys.path if the 
module being executed is in a subdirectory of a current directory" wouldn't 
address the issue, as `.tox/python/lib/python3.7/site-packages/pip/__main__.py` 
is in a subdirectory of the current directory, but one would still expect '' 
not to be in sys.path in this case.

But basing on __main__.__spec__, that would probably do what is expected.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31874] [feature] runpy.run_module should mimic script launch behavior for sys.path

2017-10-26 Thread Jason R. Coombs

Change by Jason R. Coombs :


--
components: +Library (Lib)

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31874] [feature] runpy.run_module should mimic script launch behavior for sys.path

2017-10-26 Thread Jason R. Coombs

Change by Jason R. Coombs :


--
type:  -> enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31874] [feature] runpy.run_module should mimic script launch behavior for sys.path

2017-10-26 Thread Jason R. Coombs

Jason R. Coombs  added the comment:

At first, I didn't understand why one wouldn't simply omit sys.path[0], similar 
to what scripts do, but then I realized that Nick was aware of a common 
use-case that I was overlooking - that `python -m` may be used to launch 
behavior in a local package - in which case it's relevant and important that 
sys.path[0] == ''.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31874] [feature] runpy.run_module should mimic script launch behavior for sys.path

2017-10-26 Thread Jason R. Coombs

New submission from Jason R. Coombs :

In [this comment](https://bugs.python.org/issue16737#msg282872) I describe an 
issue whereby launching an application via runpy.run_module (aka python -m) 
produces different and unexpected behavior than running the same app via an 
entry script.

In [this followup comment](https://bugs.python.org/issue16737#msg304662), I 
provide more detail on why a user might expect for run_module to mimic the 
behavior of launching a script.

[Nick suggests](https://bugs.python.org/issue16737#msg304707):

> Update sys.path[0] based on __main__.__spec__.origin after [resolving] 
> __main__.__spec__. That way it will only stay as the current directory if the 
> module being executed is in a subdirectory of the current directory, and will 
> otherwise be updated appropriately for wherever we actually found the main 
> module.

--
messages: 305054
nosy: jason.coombs
priority: normal
severity: normal
status: open
title: [feature] runpy.run_module should mimic script launch behavior for 
sys.path
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com