cpython: a364719e400a (original) (raw)

Mercurial > cpython

changeset 68859:a364719e400a

Do not touch sys.path when site is imported and python was started with -S. Original patch by Carl Meyer, review by Brett Cannon, small doc editions by yours truly. Fixes #11591. [#11591]

Éric Araujo merwok@netwok.org
date Wed, 23 Mar 2011 02:06:24 +0100
parents 997271aebd69
children 85ffaa4e60e9
files Doc/library/site.rst Doc/using/cmdline.rst Doc/whatsnew/3.3.rst Lib/site.py Misc/NEWS Misc/python.man
diffstat 6 files changed, 36 insertions(+), 5 deletions(-)[+] [-] Doc/library/site.rst 13 Doc/using/cmdline.rst 4 Doc/whatsnew/3.3.rst 5 Lib/site.py 10 Misc/NEWS 5 Misc/python.man 4

line wrap: on

line diff

--- a/Doc/library/site.rst +++ b/Doc/library/site.rst @@ -13,7 +13,11 @@ import can be suppressed using the inter .. 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 the +:func:site.main function. .. index:: pair: site-python; directory @@ -114,6 +118,13 @@ empty, and the path manipulations are sk .. envvar:: PYTHONUSERBASE +.. function:: main() +

.. function:: addsitedir(sitedir, known_paths=None) Adds a directory to sys.path and processes its pth files.

--- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -239,7 +239,9 @@ Miscellaneous options .. cmdoption:: -S Disable the import of the module :mod:site and the site-dependent

.. cmdoption:: -u

--- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -128,3 +128,8 @@ that may require changes to your code:

--- a/Lib/site.py +++ b/Lib/site.py @@ -508,6 +508,11 @@ def execusercustomize(): def main():

+

-main() +# Prevent edition of sys.path when python was started with -S and +# site is imported later. +if not sys.flags.no_site:

def _script(): help = """[](#l4.26)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -81,12 +81,15 @@ Core and Builtins Library ------- +- Issue #11591: Prevent "import site" from modifying sys.path when python

--- a/Misc/python.man +++ b/Misc/python.man @@ -169,7 +169,9 @@ Disable the import of the module .I site and the site-dependent manipulations of .I sys.path -that it entails. +that it entails. Also disable these manipulations if +.I site +is explicitly imported later. .TP .B -u Force the binary I/O layers of stdin, stdout and stderr to be unbuffered.