One idea may be, when executing "python -m", check to see if the module is loaded from CWD, if so then have CWD added, but if the module is not loaded from CWD then not have it added.
-----Original Message-----
From: Nick Timkovich <prometheus235@gmail.com>
To: Brianvanderburg2 <brianvanderburg2@aim.com>
Cc: python-ideas@python.org <python-ideas@python.org>
Sent: Mon, Feb 24, 2020 2:52 pm
Subject: Re: [Python-ideas] Control adding script path/CWD to sys.path
When running a python script directly, the directory of that script gets added to sys.path. When running as a module "python -m", it looks like an empty string gets added to sys.path, which appears to result in CWD being used.
Are you familiar with the -I option for "isolated mode"?
https://docs.python.org/3/using/cmdline.html#id2
-I
Run Python in isolated mode. This also implies -E and -s. In isolated mode sys.path contains neither the script’s directory nor the user’s site-packages directory. All PYTHON* environment variables are ignored, too. Further restrictions may be imposed to prevent the user from injecting malicious code. New in version 3.4.