This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: python3 -S -m site fails
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3, Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: meador.inge Nosy List: Arfrever, christian.heimes, eric.araujo, meador.inge, ncoghlan, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2012-12-28 20:22 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
issue16804-0.patch meador.inge, 2012-12-30 18:02 review
Messages (8)
msg178424 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-12-28 20:22
$ python3.4 -S -m site
sys.path = [
Traceback (most recent call last):
  File "/home/antoine/opt/lib/python3.4/", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/home/antoine/opt/lib/python3.4/", line 73, in _run_code
    exec(code, run_globals)
  File "/home/antoine/opt/lib/python3.4/", line 640, in <module>
  File "/home/antoine/opt/lib/python3.4/", line 612, in _script
    "exists" if os.path.isdir(USER_BASE) else "doesn't exist"))
  File "/home/antoine/opt/lib/python3.4/", line 42, in isdir
    st = os.stat(s)
TypeError: stat: can't specify None for path argument
msg178476 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) 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.
msg178585 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-12-30 16:24
Yeah, it is a result of the fix for issue11591 (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 "<stdin>", line 1, in <module>
   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.
msg178594 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-12-30 18:02
Whoops, the 'quit' case is actually intended and is documented (

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?
msg186114 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-05 23:27
Patch works ok here, but should there be a test too?
msg186134 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) 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 :)
msg186470 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2013-04-09 23:15
I will go ahead and commit the patch as is.  Thanks for the review y'all.
msg186879 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-14 02:00
New changeset faa5d705c27d by Meador Inge in branch '3.3':
Issue #16804: Fix 'python -S -m site' failure.

New changeset 8cbd8d8ac828 by Meador Inge in branch 'default':
Issue #16804: Fix 'python -S -m site' failure.
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 61008
2013-04-14 02:01:50meador.ingesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2013-04-14 02:00:32python-devsetnosy: + python-dev
messages: + msg186879
2013-04-09 23:15:45meador.ingesetmessages: + msg186470
2013-04-06 15:32:49eric.araujosetmessages: + msg186134
2013-04-05 23:27:23pitrousetmessages: + msg186114
2012-12-30 18:02:24meador.ingesetfiles: + issue16804-0.patch
messages: + msg178594

assignee: meador.inge
keywords: + patch
stage: patch review
2012-12-30 16:24:37meador.ingesetnosy: + eric.araujo
messages: + msg178585
2012-12-29 13:24:26christian.heimessetnosy: + christian.heimes
2012-12-29 06:51:48ncoghlansetmessages: + msg178476
2012-12-29 06:00:42Arfreversetnosy: + Arfrever
2012-12-29 02:36:29meador.ingesetnosy: + meador.inge
2012-12-28 20:22:43pitroucreate