Skip to content

gh-120037: User site packages are being added when site module is enabled in _pth file#120100

Closed
tanzim wants to merge 4 commits into
python:mainfrom
tanzim:main
Closed

gh-120037: User site packages are being added when site module is enabled in _pth file#120100
tanzim wants to merge 4 commits into
python:mainfrom
tanzim:main

Conversation

@tanzim

@tanzim tanzim commented Jun 5, 2024

Copy link
Copy Markdown

Don't add user site package directory to sys.path when a distribution specific _.pth exists with site import enabled.

I'd prefer that we add some tests for this, however none of the embedding tests looks like they test with _pth files enabled?

Thanks to @eryksun for the fix suggestion.

@ghost

ghost commented Jun 5, 2024

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

@bedevere-app

bedevere-app Bot commented Jun 5, 2024

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@eryksun

eryksun commented Jun 5, 2024

Copy link
Copy Markdown
Contributor

Let's update _pthFileTests in "Lib/test/test_site.py" to verify that sys.flags.no_user_site is nonzero.

Basic test:

    @support.requires_subprocess()
    def test_underpth_no_user_site(self):
        pth_lines = [test.support.STDLIB_DIR, 'import site']
        exe_file = self._create_underpth_exe(pth_lines)
        p = subprocess.run([exe_file, '-X', 'utf8', '-c',
                            'import sys; '
                            'sys.exit(not sys.flags.no_user_site)'])
        self.assertEqual(p.returncode, 0, "sys.flags.no_user_site was 0")

@@ -0,0 +1 @@
Fix user site packages directory being added to `sys.path` when site module is enabled in `._pth` file. Patch by Tanzim Husain.

@zooba zooba Jun 6, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Fix user site packages directory being added to `sys.path` when site module is enabled in `._pth` file. Patch by Tanzim Husain.
Fix user site packages directory being enabled when a ``._pth`` file has been used. Patch by Tanzim Husain.

This is a ReST file, not Markdown, so the syntax is slightly different. This should work to allow the docs builds to pass.

Edit And simplified the text a little.

@python-cla-bot

python-cla-bot Bot commented Apr 6, 2025

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA signed

@zooba

zooba commented Aug 5, 2025

Copy link
Copy Markdown
Member

Seems like we're not getting a CLA, so I created #137428 to get this change in.

@zooba zooba closed this Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants