Issue 16804: python3 -S -m site fails (original) (raw)
Created on 2012-12-28 20:22 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (8)
Author: Antoine Pitrou (pitrou) * 
Date: 2012-12-28 20:22
$ python3.4 -S -m site sys.path = [ '', '/home/antoine/opt/lib/python34.zip', '/home/antoine/opt/lib/python3.4/', '/home/antoine/opt/lib/python3.4/plat-linux', '/home/antoine/opt/lib/python3.4/lib-dynload', ] Traceback (most recent call last): File "/home/antoine/opt/lib/python3.4/runpy.py", line 160, in _run_module_as_main "main", fname, loader, pkg_name) File "/home/antoine/opt/lib/python3.4/runpy.py", line 73, in _run_code exec(code, run_globals) File "/home/antoine/opt/lib/python3.4/site.py", line 640, in _script() File "/home/antoine/opt/lib/python3.4/site.py", line 612, in _script "exists" if os.path.isdir(USER_BASE) else "doesn't exist")) File "/home/antoine/opt/lib/python3.4/genericpath.py", line 42, in isdir st = os.stat(s) TypeError: stat: can't specify None for path argument
Author: Alyssa Coghlan (ncoghlan) * 
Date: 2012-12-29 06:51
Hmm, it works in 3.2, so I suspect that's a symptom of the code change that skipped the side effects on explicit import when "-S" was specified.
Author: Meador Inge (meador.inge) * 
Date: 2012-12-30 16:24
Yeah, it is a result of the fix for (changeset a364719e400a). Incidentally, the decision was made to forgo writing a testcase in favor of proof by inspection :-)
There are also other consequences of that change:
./python.exe -S Python 3.4.0a0 (default:08c215115842, Dec 30 2012, 09:54:54) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.65))] on darwin
import site quit() Traceback (most recent call last): File "", line 1, in NameError: name 'quit' is not defined ^D
'quit' not being defined in this case is a regression.
ISTM the original change was meant to only prevent sys.path from being altered, but it is preventing a bunch of other things (USER_BASE, USER_SITE, quit, ...) from being initialized as well.
Author: Meador Inge (meador.inge) * 
Date: 2012-12-30 18:02
Whoops, the 'quit' case is actually intended and is documented (http://docs.python.org/3.4/library/site.html):
""" or additions to the builtins. To explicitly trigger the usual site-specific additions, call the site.main() function. """
I think the right way to fix this is to use the accessor functions for the USER_* variables. Does the attached look OK?
Author: Antoine Pitrou (pitrou) * 
Date: 2013-04-05 23:27
Patch works ok here, but should there be a test too?
Author: Éric Araujo (eric.araujo) * 
Date: 2013-04-06 15:32
It seems to me that -m site is not a guaranteed API but just a way to inspect/debug your installation/environment, so I wouldn’t add tests that make it looks like behavior is more defined than “print stuff about site dirs”. I’d commit this simple fix as is (but then again, I’m responsible for the breakage :)
Author: Meador Inge (meador.inge) * 
Date: 2013-04-09 23:15
I will go ahead and commit the patch as is. Thanks for the review y'all.
Author: Roundup Robot (python-dev) 
Date: 2013-04-14 02:00
New changeset faa5d705c27d by Meador Inge in branch '3.3': Issue #16804: Fix 'python -S -m site' failure. http://hg.python.org/cpython/rev/faa5d705c27d
New changeset 8cbd8d8ac828 by Meador Inge in branch 'default': Issue #16804: Fix 'python -S -m site' failure. http://hg.python.org/cpython/rev/8cbd8d8ac828
History
Date
User
Action
Args
2022-04-11 14:57:39
admin
set
github: 61008
2013-04-14 02:01:50
meador.inge
set
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2013-04-14 02:00:32
python-dev
set
nosy: + python-dev
messages: +
2013-04-09 23:15:45
meador.inge
set
messages: +
2013-04-06 15:32:49
eric.araujo
set
messages: +
2013-04-05 23:27:23
pitrou
set
messages: +
2012-12-30 18:02:24
meador.inge
set
files: + issue16804-0.patch
messages: +
assignee: meador.inge
keywords: + patch
stage: patch review
2012-12-30 16:24:37
meador.inge
set
nosy: + eric.araujo
messages: +
2012-12-29 13:24:26
christian.heimes
set
nosy: + christian.heimes
2012-12-29 06:51:48
ncoghlan
set
messages: +
2012-12-29 06:00:42
Arfrever
set
nosy: + Arfrever
2012-12-29 02:36:29
meador.inge
set
nosy: + meador.inge
2012-12-28 20:22:43
pitrou
create