Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/site.rst

    r2 r391  
    1 
    21:mod:`site` --- Site-specific configuration hook
    32================================================
    43
    54.. module:: site
    6    :synopsis: A standard way to reference site-specific modules.
    7 
     5   :synopsis: Module responsible for site-specific configuration.
     6
     7**Source code:** :source:`Lib/site.py`
     8
     9--------------
     10
     11.. highlightlang:: none
    812
    913**This module is automatically imported during initialization.** The automatic
     
    1216.. index:: triple: module; search; path
    1317
    14 Importing this module will append site-specific paths to the module search path.
     18Importing this module will append site-specific paths to the module search path
     19and add a few builtins.
    1520
    1621.. index::
     
    2227are skipped.  For the tail part, it uses the empty string and then
    2328:file:`lib/site-packages` (on Windows) or
    24 :file:`lib/python|version|/site-packages` and then :file:`lib/site-python` (on
     29:file:`lib/python{X.Y}/site-packages` and then :file:`lib/site-python` (on
    2530Unix and Macintosh).  For each of the distinct head-tail combinations, it sees
    2631if it refers to an existing directory, and if so, adds it to ``sys.path`` and
    2732also inspects the newly added path for configuration files.
    2833
    29 A path configuration file is a file whose name has the form :file:`package.pth`
     34A path configuration file is a file whose name has the form :file:`{name}.pth`
    3035and exists in one of the four directories mentioned above; its contents are
    3136additional items (one per line) to be added to ``sys.path``.  Non-existing items
    32 are never added to ``sys.path``, but no check is made that the item refers to a
    33 directory (rather than a file).  No item is added to ``sys.path`` more than
     37are never added to ``sys.path``, and no check is made that the item refers to a
     38directory rather than a file.  No item is added to ``sys.path`` more than
    3439once.  Blank lines and lines beginning with ``#`` are skipped.  Lines starting
    3540with ``import`` (followed by space or tab) are executed.
     
    4449For example, suppose ``sys.prefix`` and ``sys.exec_prefix`` are set to
    4550:file:`/usr/local`.  The Python X.Y library is then installed in
    46 :file:`/usr/local/lib/python{X.Y}` (where only the first three characters of
    47 ``sys.version`` are used to form the installation path name).  Suppose this has
     51:file:`/usr/local/lib/python{X.Y}`.  Suppose this has
    4852a subdirectory :file:`/usr/local/lib/python{X.Y}/site-packages` with three
    4953subsubdirectories, :file:`foo`, :file:`bar` and :file:`spam`, and two path
     
    7882After these path manipulations, an attempt is made to import a module named
    7983:mod:`sitecustomize`, which can perform arbitrary site-specific customizations.
    80 If this import fails with an :exc:`ImportError` exception, it is silently
    81 ignored.
    82 
    83 .. index:: module: sitecustomize
     84It is typically created by a system administrator in the site-packages
     85directory.  If this import fails with an :exc:`ImportError` exception, it is
     86silently ignored.
     87
     88.. index:: module: usercustomize
     89
     90After this, an attempt is made to import a module named :mod:`usercustomize`,
     91which can perform arbitrary user-specific customizations, if
     92:data:`ENABLE_USER_SITE` is true.  This file is intended to be created in the
     93user site-packages directory (see below), which is part of ``sys.path`` unless
     94disabled by :option:`-s`.  An :exc:`ImportError` will be silently ignored.
    8495
    8596Note that for some non-Unix systems, ``sys.prefix`` and ``sys.exec_prefix`` are
    8697empty, and the path manipulations are skipped; however the import of
    87 :mod:`sitecustomize` is still attempted.
     98:mod:`sitecustomize` and :mod:`usercustomize` is still attempted.
    8899
    89100
    90101.. data:: PREFIXES
    91102
    92    A list of prefixes for site package directories
     103   A list of prefixes for site-packages directories.
    93104
    94105   .. versionadded:: 2.6
     
    97108.. data:: ENABLE_USER_SITE
    98109
    99    Flag showing the status of the user site directory. True means the
    100    user site directory is enabled and added to sys.path. When the flag
    101    is None the user site directory is disabled for security reasons.
     110   Flag showing the status of the user site-packages directory.  ``True`` means
     111   that it is enabled and was added to ``sys.path``.  ``False`` means that it
     112   was disabled by user request (with :option:`-s` or
     113   :envvar:`PYTHONNOUSERSITE`).  ``None`` means it was disabled for security
     114   reasons (mismatch between user or group id and effective id) or by an
     115   administrator.
    102116
    103117   .. versionadded:: 2.6
     
    106120.. data:: USER_SITE
    107121
    108    Path to the user site directory for the current Python version or None
     122   Path to the user site-packages for the running Python.  Can be ``None`` if
     123   :func:`getusersitepackages` hasn't been called yet.  Default value is
     124   :file:`~/.local/lib/python{X.Y}/site-packages` for UNIX and non-framework Mac
     125   OS X builds, :file:`~/Library/Python/{X.Y}/lib/python/site-packages` for Mac
     126   framework builds, and :file:`{%APPDATA%}\\Python\\Python{XY}\\site-packages`
     127   on Windows.  This directory is a site directory, which means that
     128   :file:`.pth` files in it will be processed.
    109129
    110130   .. versionadded:: 2.6
     
    113133.. data:: USER_BASE
    114134
    115    Path to the base directory for user site directories
    116 
    117    .. versionadded:: 2.6
    118 
    119 
    120 .. envvar:: PYTHONNOUSERSITE
    121 
    122    .. versionadded:: 2.6
    123 
    124 
    125 .. envvar:: PYTHONUSERBASE
     135   Path to the base directory for the user site-packages.  Can be ``None`` if
     136   :func:`getuserbase` hasn't been called yet.  Default value is
     137   :file:`~/.local` for UNIX and Mac OS X non-framework builds,
     138   :file:`~/Library/Python/{X.Y}` for Mac framework builds, and
     139   :file:`{%APPDATA%}\\Python` for Windows.  This value is used by Distutils to
     140   compute the installation directories for scripts, data files, Python modules,
     141   etc. for the :ref:`user installation scheme <inst-alt-install-user>`.  See
     142   also :envvar:`PYTHONUSERBASE`.
    126143
    127144   .. versionadded:: 2.6
     
    130147.. function:: addsitedir(sitedir, known_paths=None)
    131148
    132    Adds a directory to sys.path and processes its pth files.
    133 
    134 
    135 .. XXX Update documentation
    136 .. XXX document python -m site --user-base --user-site
     149   Add a directory to sys.path and process its :file:`.pth` files.  Typically
     150   used in :mod:`sitecustomize` or :mod:`usercustomize` (see above).
     151
     152
     153.. function:: getsitepackages()
     154
     155   Return a list containing all global site-packages directories (and possibly
     156   site-python).
     157
     158   .. versionadded:: 2.7
     159
     160
     161.. function:: getuserbase()
     162
     163   Return the path of the user base directory, :data:`USER_BASE`.  If it is not
     164   initialized yet, this function will also set it, respecting
     165   :envvar:`PYTHONUSERBASE`.
     166
     167   .. versionadded:: 2.7
     168
     169
     170.. function:: getusersitepackages()
     171
     172   Return the path of the user-specific site-packages directory,
     173   :data:`USER_SITE`.  If it is not initialized yet, this function will also set
     174   it, respecting :envvar:`PYTHONNOUSERSITE` and :data:`USER_BASE`.
     175
     176   .. versionadded:: 2.7
     177
     178
     179The :mod:`site` module also provides a way to get the user directories from the
     180command line:
     181
     182.. code-block:: sh
     183
     184   $ python3 -m site --user-site
     185   /home/user/.local/lib/python3.3/site-packages
     186
     187.. program:: site
     188
     189If it is called without arguments, it will print the contents of
     190:data:`sys.path` on the standard output, followed by the value of
     191:data:`USER_BASE` and whether the directory exists, then the same thing for
     192:data:`USER_SITE`, and finally the value of :data:`ENABLE_USER_SITE`.
     193
     194.. cmdoption:: --user-base
     195
     196   Print the path to the user base directory.
     197
     198.. cmdoption:: --user-site
     199
     200   Print the path to the user site-packages directory.
     201
     202If both options are given, user base and user site will be printed (always in
     203this order), separated by :data:`os.pathsep`.
     204
     205If any option is given, the script will exit with one of these values: ``O`` if
     206the user site-packages directory is enabled, ``1`` if it was disabled by the
     207user, ``2`` if it is disabled for security reasons or by an administrator, and a
     208value greater than 2 if there is an error.
     209
     210.. seealso::
     211
     212   :pep:`370` -- Per user site-packages directory
Note: See TracChangeset for help on using the changeset viewer.