[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-05-05 Thread Victor Stinner
Ah, I see that I didn't explain something well. The issue has two sides: one side is a fix security vulnerability, the second side is more about Python *usability*. The Python usability issue is that running "math.py" overrides the Python stdlib module called "math". "math.py" is just an

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-05-04 Thread Victor Stinner
Hi, I updated my PR https://github.com/python/cpython/pull/31542 and I plan to merge it soon. It seems like most people need and like this feature. About the feature name, nobody liked the "add_path0" name which is misleading: "path0" is not easy to get, and the path is prepended, not added. I

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Barry Scott
> On 27 Apr 2022, at 20:21, Miro Hrončok wrote: > > On 27. 04. 22 20:45, Barry wrote: >>> On 27 Apr 2022, at 17:22, Victor Stinner wrote: >>> >>> Ok, you changed my mind and I added PYTHONDONTADDPATH0=1 env var. Example: >> Maybe the env var say what it is not adding rather then where it

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Miro Hrončok
On 27. 04. 22 21:34, Steve Holden wrote: So would PYTHONDONTADDSCRIPTDIR=1 be a better choice? No because for other invocations, it prevents PWD being added, not the scriptdir. Both names are bad becasue they only describe half of what's it doing (or maybe the option should not do both, if

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Miro Hrončok
On 27. 04. 22 20:45, Barry wrote: On 27 Apr 2022, at 17:22, Victor Stinner wrote: Ok, you changed my mind and I added PYTHONDONTADDPATH0=1 env var. Example: Maybe the env var say what it is not adding rather then where it adds it. PYTHONDONTADDPWD=1 But it is not "just" the PWD. In the

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Barry
> On 27 Apr 2022, at 17:22, Victor Stinner wrote: > > Ok, you changed my mind and I added PYTHONDONTADDPATH0=1 env var. Example: Maybe the env var say what it is not adding rather then where it adds it. PYTHONDONTADDPWD=1 Barry ___ Python-Dev

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Paul Moore
On Wed, 27 Apr 2022 at 16:50, Victor Stinner wrote: > > Since I didn't get any serious review on my pull request since > February, I created this thread on python-dev to get more people > looking into this issue. Pull requests don't get much visibility from the wider community - I know I can't

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Victor Stinner
On Wed, Apr 27, 2022 at 5:56 PM Antoine Pitrou wrote: > An environment variable is an easy to influence a program or system > whose inner workings you don't control (for example a system that > spawns child Python processes). And it sounds like a good idea to allow > that given that it improves

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Victor Stinner
The use case for -P still uses environment variables like PYTHONWARNINGS or PYTHONUTF8. That's why -I (isolated) cannot be used. If there is an use case for a ._pth file importing the site module, maybe a different option can be added, no? Adding -P doesn't prevent that. But it seems like use

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Victor Stinner
Since I didn't get any serious review on my pull request since February, I created this thread on python-dev to get more people looking into this issue. On Wed, Apr 27, 2022 at 5:30 PM Paul Moore wrote: > > On Wed, 27 Apr 2022 at 15:32, Victor Stinner wrote: > > > > On Tue, Apr 26, 2022 at

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Antoine Pitrou
On Wed, 27 Apr 2022 17:37:20 +0200 Victor Stinner wrote: > Oh sorry, I mean that I prefer to *not* add an environment variable, > but I'm not strongly against it. > > How would the environment varaible be used? A command line option is not > enough? An environment variable is an easy to

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Victor Stinner
Oh sorry, I mean that I prefer to *not* add an environment variable, but I'm not strongly against it. How would the environment varaible be used? A command line option is not enough? Victor On Wed, Apr 27, 2022 at 4:44 PM Antoine Pitrou wrote: > > On Tue, 26 Apr 2022 11:46:41 +0200 > Victor

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Paul Moore
On Wed, 27 Apr 2022 at 15:32, Victor Stinner wrote: > > On Tue, Apr 26, 2022 at 11:46 AM Victor Stinner wrote: > > I propose adding a -P option to Python command line interface to "not > > add sys.path[0]": > > https://github.com/python/cpython/pull/31542 > > My plan is to merge this change at

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Antoine Pitrou
On Tue, 26 Apr 2022 11:46:41 +0200 Victor Stinner wrote: > I prefer to add an environment variable, only pass the option > explicitly on the command line. I don't really understand this sentence, can you rephrase? ___ Python-Dev mailing list --

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Victor Stinner
On Tue, Apr 26, 2022 at 11:46 AM Victor Stinner wrote: > I propose adding a -P option to Python command line interface to "not > add sys.path[0]": > https://github.com/python/cpython/pull/31542 My plan is to merge this change at 2022-05-05, the day before the Python 3.11 feature freeze, unless

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-27 Thread Victor Stinner
On Tue, Apr 26, 2022 at 8:37 PM Steve Dower wrote: > The biggest issue I see is that the obvious command line options for > "import site" are already used to imply "do not import site". But then, > -P isn't obvious either. Maybe an -X option would suffice? I propose the short option "-P" rather

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-26 Thread Victor Stinner
The only purpose of proposed -P option is to "not add sys.path[0]". There are use cases which only need that. Victor On Tue, Apr 26, 2022 at 8:37 PM Steve Dower wrote: > > On 4/26/2022 10:46 AM, Victor Stinner wrote: > > I propose adding a -P option to Python command line interface to "not > >

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-26 Thread Steve Dower
On 4/26/2022 10:46 AM, Victor Stinner wrote: I propose adding a -P option to Python command line interface to "not add sys.path[0]": https://github.com/python/cpython/pull/31542 See the documentation in the PR for the exact behavior of this option. I prefer to add an environment variable, only

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-26 Thread Brett Cannon
On Tue, Apr 26, 2022 at 2:50 AM Victor Stinner wrote: > Hi, > > There are 4 main ways to run Python: > > (1) python -m module [...] > (2) python script.py [...] > (3) python -c code [...] > (4) python [...] > > (1) and (2) insert the directory of the module/script at sys.path[0]. > (3) and (4)

[Python-Dev] Re: Add -P command line option to not add sys.path[0]

2022-04-26 Thread Eryk Sun
On 4/26/22, Victor Stinner wrote: > > There are 4 main ways to run Python: > > (1) python -m module [...] > (2) python script.py [...] > (3) python -c code [...] > (4) python [...] > > (1) and (2) insert the directory of the module/script at sys.path[0]. Running a module with -m inserts the