diff -r 525320df8afb -r ebe5760afa08 Doc/library/site.rst --- a/Doc/library/site.rst Thu Mar 17 20:20:30 2011 +0200 +++ b/Doc/library/site.rst Mon Mar 21 13:40:17 2011 -0400 @@ -13,7 +13,11 @@ .. index:: triple: module; search; path -Importing this module will append site-specific paths to the module search path. +Importing this module will append site-specific paths to the module search +path, unless :option:`-S` was used. In that case, this module can be safely +imported with no automatic modifications to the module search path. To +explicitly trigger the usual site-specific additions, call this module's +:func:`main` function. .. index:: pair: site-python; directory @@ -114,6 +118,12 @@ .. envvar:: PYTHONUSERBASE +.. function:: main() + + Adds all the standard site-specific directories to the module search + path. This function is called automatically when this module is imported, + unless the python interpreter was run with the :option:`-S` flag. + .. function:: addsitedir(sitedir, known_paths=None) Adds a directory to sys.path and processes its pth files. diff -r 525320df8afb -r ebe5760afa08 Lib/site.py --- a/Lib/site.py Thu Mar 17 20:20:30 2011 +0200 +++ b/Lib/site.py Mon Mar 21 13:40:17 2011 -0400 @@ -526,7 +526,8 @@ if ENABLE_USER_SITE: execusercustomize() -main() +if not sys.flags.no_site: + main() def _script(): help = """\ diff -r 525320df8afb -r ebe5760afa08 Misc/NEWS --- a/Misc/NEWS Thu Mar 17 20:20:30 2011 +0200 +++ b/Misc/NEWS Mon Mar 21 13:40:17 2011 -0400 @@ -72,6 +72,9 @@ Library ------- +- Issue #11591: Prevent imports from "site" from automatically adding site + directories to sys.path under "python -S". + - Issue #10812: Add some extra posix functions to the os module. - Issue #10979: unittest stdout buffering now works with class and module