Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tanzim
Copy link

@tanzim tanzim commented Jun 5, 2024

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
Copy link

ghost commented Jun 5, 2024

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

Click the button to sign:
CLA not signed

@bedevere-app
Copy link

bedevere-app bot commented Jun 5, 2024

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
Copy link
Contributor

eryksun commented Jun 5, 2024

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.
Copy link
Member

@zooba zooba Jun 6, 2024

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
Copy link

python-cla-bot bot commented Apr 6, 2025

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

CLA signed

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