GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-41376: Correct the documentation on ``site.getusersitepackages()`` regarding respecting PYTHONNOUSERSITE by pelson · Pull Request #21602 · python/cpython

Conversation

@pelson

@pelson pelson commented Jul 23, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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 update the function to return None if user-specific site-packages are disabled (i.e. update the function to reflect the existing documentation), since there are other uses of the function which are relying on this behaviour (e.g. python -m site) and it would amount to a breaking change.

https://bugs.python.org/issue41376

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jul 23, 2020
@bedevere-bot bedevere-bot added docs Documentation in the Doc dir awaiting review labels Jul 23, 2020
@pelson

pelson commented Jul 23, 2020

Copy link
Copy Markdown
Contributor Author

I couldn't see from https://devguide.python.org/documenting/ whether I could target an older Python version (technically the docs have been wrong on this since time immemorial). For this reason I targeted Python 3.8. Very happy to rebase this against another branch as appropriate.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pelson
pelson force-pushed the getusersitepackages_and_pynoaddusersite branch from db7227e to 00c68a8 Compare July 23, 2020 15:33
@pelson
bpo-41376: Correct the documentation on `site.getusersitepackages()…
46430b8
…` 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``).
@pelson
pelson force-pushed the getusersitepackages_and_pynoaddusersite branch from 00c68a8 to 46430b8 Compare July 23, 2020 15:38
@pelson
pelson requested review from a team, 1st1, asvetlov, berkerpeksag, brettcannon, encukou, ericsnowcurrently, ericvsmith, ezio-melotti, gpshead, gvanrossum, ilevkivskyi, methane, ncoghlan, pablogsal, rhettinger, skrah, terryjreedy, tiran and warsaw as code owners July 23, 2020 15:38
@pelson
pelson changed the base branch from 3.8 to master July 23, 2020 15:38
@brettcannon
brettcannon removed request for a team, brettcannon, ezio-melotti, skrah and terryjreedy July 23, 2020 19:01
@pelson

pelson commented Oct 7, 2020

Copy link
Copy Markdown
Contributor Author

@methane sorry to ping you directly, but you were the last to add to the site documentation and have also made changes to getusersitepackages(), so figure you may be willing to review this documentation PR. I'm happy to adjust the language if there are any concerns with it, but I would really like to see this demonstrably incorrect documentation fixed for new Python releases.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@methane methane added needs backport to 3.8 skip news labels Oct 8, 2020
@methane methane closed this Oct 8, 2020
@methane methane reopened this Oct 8, 2020
methane
methane approved these changes Oct 8, 2020
View reviewed changes

@methane methane left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But merge button is disabled for some reason. I don't know why.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Oct 8, 2020
@methane
methane merged commit 35f041d into python:master Oct 8, 2020
@miss-islington

miss-islington commented Oct 8, 2020

Copy link
Copy Markdown
Contributor

Thanks @pelson for the PR, and @methane for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Oct 8, 2020
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 8, 2020
@pelson @miss-islington
bpo-41376: Fix the documentation of site.getusersitepackages() (pyt…
fec3078
…honGH-21602)

`site.getusersitepackages()` returns the location of the user-specific site-packages directory
even when the user-specific site-packages is disabled.

```
$ 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`).
(cherry picked from commit 35f041d)

Co-authored-by: Phil Elson <[email protected]>
@bedevere-bot

bedevere-bot commented Oct 8, 2020

Copy link
Copy Markdown

GH-22591 is a backport of this pull request to the 3.9 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 label Oct 8, 2020
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 8, 2020
@pelson @miss-islington
bpo-41376: Fix the documentation of site.getusersitepackages() (pyt…
a4bd1a9
…honGH-21602)

`site.getusersitepackages()` returns the location of the user-specific site-packages directory
even when the user-specific site-packages is disabled.

```
$ 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`).
(cherry picked from commit 35f041d)

Co-authored-by: Phil Elson <[email protected]>
@bedevere-bot

bedevere-bot commented Oct 8, 2020

Copy link
Copy Markdown

GH-22592 is a backport of this pull request to the 3.8 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.8 label Oct 8, 2020
miss-islington added a commit that referenced this pull request Oct 8, 2020
@miss-islington @pelson
bpo-41376: Fix the documentation of site.getusersitepackages() (GH-…
5b1fdca
…21602)

`site.getusersitepackages()` returns the location of the user-specific site-packages directory
even when the user-specific site-packages is disabled.

```
$ 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`).
(cherry picked from commit 35f041d)

Co-authored-by: Phil Elson <[email protected]>
shihai1991 added a commit to shihai1991/cpython that referenced this pull request Oct 9, 2020
@shihai1991
Merge remote-tracking branch 'origin/master' into bpo_39337_new_2
a69eef8
* origin/master: (147 commits)
  Fix the attribute names in the docstring of GenericAlias (pythonGH-22594)
  bpo-39337: Add a test case for normalizing of codec names (pythonGH-19069)
  bpo-41557: Update Windows installer to use SQLite 3.33.0 (pythonGH-21960)
  bpo-41976: Fix the fallback to gcc of ctypes.util.find_library when using gcc>9 (pythonGH-22598)
  bpo-41306: Allow scale value to not be rounded (pythonGH-21715)
  bpo-41970: Avoid test failure in test_lib2to3 if the module is already imported (pythonGH-22595)
  bpo-41376: Fix the documentation of `site.getusersitepackages()` (pythonGH-21602)
  Revert "bpo-26680: Incorporate is_integer in all built-in and standard library numeric types (pythonGH-6121)" (pythonGH-22584)
  bpo-41923: PEP 613: Add TypeAlias to typing module (python#22532)
  Fix comment about PyObject_IsTrue. (pythonGH-22343)
  bpo-38605: Make 'from __future__ import annotations' the default (pythonGH-20434)
  bpo-41905: Add abc.update_abstractmethods() (pythonGH-22485)
  bpo-41944: No longer call eval() on content received via HTTP in the UnicodeNames tests (pythonGH-22575)
  bpo-41944: No longer call eval() on content received via HTTP in the CJK codec tests (pythonGH-22566)
  Post 3.10.0a1
  Python 3.10.0a1
  bpo-41584: clarify when the reflected method of a binary arithemtic operator is called (python#22505)
  bpo-41939: Fix test_site.test_license_exists_at_url() (python#22559)
  bpo-41774: Tweak new programming FAQ entry (pythonGH-22562)
  bpo-41936. Remove macros Py_ALLOW_RECURSION/Py_END_ALLOW_RECURSION (pythonGH-22552)
  ...
pablogsal pushed a commit that referenced this pull request Oct 11, 2020
@miss-islington @pelson
bpo-41376: Fix the documentation of site.getusersitepackages() (GH-…
1006f63
…21602) (GH-22592)

`site.getusersitepackages()` returns the location of the user-specific site-packages directory
even when the user-specific site-packages is disabled.

```
$ 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`).
(cherry picked from commit 35f041d)

Co-authored-by: Phil Elson <[email protected]>

Co-authored-by: Phil Elson <[email protected]>
@pelson
pelson deleted the getusersitepackages_and_pynoaddusersite branch October 13, 2020 07:04
@pelson

pelson commented Oct 13, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the merge @methane! This was my first documentation commit 🥳.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
@pelson @xzy3-cdc
bpo-41376: Fix the documentation of site.getusersitepackages() (pyt…
115f99e
…honGH-21602)

`site.getusersitepackages()` returns the location of the user-specific site-packages directory
even when the user-specific site-packages is disabled.

```
$ 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`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@methane methane methane approved these changes
@1st1 1st1 Awaiting requested review from 1st1
@asvetlov asvetlov Awaiting requested review from asvetlov
@berkerpeksag berkerpeksag Awaiting requested review from berkerpeksag
@encukou encukou Awaiting requested review from encukou
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently
@ericvsmith ericvsmith Awaiting requested review from ericvsmith
@gpshead gpshead Awaiting requested review from gpshead
@gvanrossum gvanrossum Awaiting requested review from gvanrossum
@ilevkivskyi ilevkivskyi Awaiting requested review from ilevkivskyi
@ncoghlan ncoghlan Awaiting requested review from ncoghlan
@pablogsal pablogsal Awaiting requested review from pablogsal
@rhettinger rhettinger Awaiting requested review from rhettinger
@tiran tiran Awaiting requested review from tiran
@warsaw warsaw Awaiting requested review from warsaw

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@pelson @miss-islington @bedevere-bot @methane @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.