| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,11 @@ import can be suppressed using the interpreter's :option:`-S` option. | |||
| 13 | 13 | ||
| 14 | 14 | .. index:: triple: module; search; path | |
| 15 | 15 | ||
| 16 | - Importing this module will append site-specific paths to the module search path. | ||
| 16 | + Importing this module will append site-specific paths to the module search | ||
| 17 | + path, unless :option:`-S` was used. In that case, this module can be safely | ||
| 18 | + imported with no automatic modifications to the module search path. To | ||
| 19 | + explicitly trigger the usual site-specific additions, call the | ||
| 20 | + :func:`site.main` function. | ||
| 17 | 21 | ||
| 18 | 22 | .. index:: | |
| 19 | 23 | pair: site-python; directory | |
@@ -114,6 +118,13 @@ empty, and the path manipulations are skipped; however the import of | |||
| 114 | 118 | .. envvar:: PYTHONUSERBASE | |
| 115 | 119 | ||
| 116 | 120 | ||
| 121 | + .. function:: main() | ||
| 122 | + | ||
| 123 | + Adds all the standard site-specific directories to the module search | ||
| 124 | + path. This function is called automatically when this module is imported, | ||
| 125 | + unless the :program:`python` interpreter was started with the :option:`-S` | ||
| 126 | + flag. | ||
| 127 | + | ||
| 117 | 128 | .. function:: addsitedir(sitedir, known_paths=None) | |
| 118 | 129 | ||
| 119 | 130 | Adds a directory to sys.path and processes its pth files. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -239,7 +239,9 @@ Miscellaneous options | |||
| 239 | 239 | .. cmdoption:: -S | |
| 240 | 240 | ||
| 241 | 241 | Disable the import of the module :mod:`site` and the site-dependent | |
| 242 | - manipulations of :data:`sys.path` that it entails. | ||
| 242 | + manipulations of :data:`sys.path` that it entails. Also disable these | ||
| 243 | + manipulations if :mod:`site` is explicitly imported later (call | ||
| 244 | + :func:`site.main` if you want them to be triggered). | ||
| 243 | 245 | ||
| 244 | 246 | ||
| 245 | 247 | .. cmdoption:: -u | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,3 +128,8 @@ that may require changes to your code: | |||
| 128 | 128 | ||
| 129 | 129 | * Stub | |
| 130 | 130 | ||
| 131 | + | ||
| 132 | + .. Issue #11591: When :program:`python` was started with :option:`-S`, | ||
| 133 | + ``import site`` will not add site-specific paths to the module search | ||
| 134 | + paths. In previous versions, it did. See changeset for doc changes in | ||
| 135 | + various files. Contributed by Carl Meyer with editions by Éric Araujo. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -508,6 +508,11 @@ def execusercustomize(): | |||
| 508 | 508 | ||
| 509 | 509 | ||
| 510 | 510 | def main(): | |
| 511 | + """Add standard site-specific directories to the module search path. | ||
| 512 | + | ||
| 513 | + This function is called automatically when this module is imported, | ||
| 514 | + unless the python interpreter was started with the -S flag. | ||
| 515 | + """ | ||
| 511 | 516 | global ENABLE_USER_SITE | |
| 512 | 517 | ||
| 513 | 518 | abs_paths() | |
@@ -526,7 +531,10 @@ def main(): | |||
| 526 | 531 | if ENABLE_USER_SITE: | |
| 527 | 532 | execusercustomize() | |
| 528 | 533 | ||
| 529 | - main() | ||
| 534 | + # Prevent edition of sys.path when python was started with -S and | ||
| 535 | + # site is imported later. | ||
| 536 | + if not sys.flags.no_site: | ||
| 537 | + main() | ||
| 530 | 538 | ||
| 531 | 539 | def _script(): | |
| 532 | 540 | help = """\ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,12 +81,15 @@ Core and Builtins | |||
| 81 | 81 | Library | |
| 82 | 82 | ------- | |
| 83 | 83 | ||
| 84 | + - Issue #11591: Prevent "import site" from modifying sys.path when python | ||
| 85 | + was started with -S. | ||
| 86 | + | ||
| 84 | 87 | - Issue #11371: Mark getopt error messages as localizable. Patch by Filip | |
| 85 | 88 | Gruszczyński. | |
| 86 | 89 | ||
| 87 | 90 | - Issue #11333: Add __slots__ to collections ABCs. | |
| 88 | 91 | ||
| 89 | - - Issue #11628: cmp_to_key generated class should use __slots__ | ||
| 92 | + - Issue #11628: cmp_to_key generated class should use __slots__. | ||
| 90 | 93 | ||
| 91 | 94 | - Issue #5537: Fix time2isoz() and time2netscape() functions of | |
| 92 | 95 | httplib.cookiejar for expiration year greater than 2038 on 32-bit systems. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,7 +169,9 @@ Disable the import of the module | |||
| 169 | 169 | .I site | |
| 170 | 170 | and the site-dependent manipulations of | |
| 171 | 171 | .I sys.path | |
| 172 | - that it entails. | ||
| 172 | + that it entails. Also disable these manipulations if | ||
| 173 | + .I site | ||
| 174 | + is explicitly imported later. | ||
| 173 | 175 | .TP | |
| 174 | 176 | .B \-u | |
| 175 | 177 | Force the binary I/O layers of stdin, stdout and stderr to be unbuffered. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments