8000 bpo-41376: Correct the documentation on ``site.getusersitepackages()`… · python/cpython@46430b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46430b8

Browse files
committed
bpo-41376: Correct the documentation on site.getusersitepackages() regarding respecting PYTHONNOUSERSITE
``site.getusersitepackages()`` returns the location of the user-specific site-packages directory whether or not it exists, or is added to the ``sys.path``. We can see this easily with: ``` $ python -c "import site; print(site.getusersitepackages())" /home/user/.local/lib/python3.7/site-packages $ python -s -c "import site; print(site.getusersitepackages())" /home/user/.local/lib/python3.7/site-packages ``` This is even true when the user-specific site-packages doesn't exist, as is demonstrated by: ``` $ python -m site sys.path = [ '/home/user/conda/lib/python37.zip', '/home/user/conda/lib/python3.7', '/home/user/conda/lib/python3.7/lib-dynload', '/home/user/conda/lib/python3.7/site-packages', ] USER_BASE: '/home/user/.local' (exists) USER_SITE: '/home/user/.local/lib/python3.7/site-packages' (doesn't exist) ENABLE_USER_SITE: True $ python -s -m site sys.path = [ '/home/user/conda/lib/python37.zip', '/home/user/conda/lib/python3.7', '/home/user/conda/lib/python3.7/lib-dynload', '/home/user/conda/lib/python3.7/site-packages', ] USER_BASE: '/home/user/.local' (exists) USER_SITE: '/home/user/.local/lib/python3.7/site-packages' (doesn't exist) ENABLE_USER_SITE: False ``` It was not practical to prevent the function from returning None if user-specific site-packages are disabled, since there are other uses of the function which are relying on this behaviour (e.g. ``python -m site``).
1 parent 680254a commit 46430b8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Doc/library/site.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231 7AA2 ,9 @@ Module contents
231231

232232
Return the path of the user-specific site-packages directory,
233233
:data:`USER_SITE`. If it is not initialized yet, this function will also set
234-
it, respecting :envvar:`PYTHONNOUSERSITE` and :data:`USER_BASE`.
234+
it, respecting :data:`USER_BASE`. To determine if the user-specific
235+
site-packages was added to ``sys.path`` :data:`ENABLE_USER_SITE` should be
236+
used.
235237

236238
.. versionadded:: 3.2
237239

0 commit comments

Comments
 (0)
0