-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
gh-149671: Restore compatibility with setuptools nspkg.pth files in site module #151319
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -233,6 +233,21 @@ def test_addsitedir_hidden_file_attribute(self): | |||||
| self.assertNotIn(site.makepath(pth_file.good_dir_path)[0], sys.path) | ||||||
| self.assertIn(pth_file.base_dir, sys.path) | ||||||
|
|
||||||
| def test_sitedir_variable(self): | ||||||
| # gh-149671: Provide 'sitedir' local variable for compatibility with | ||||||
| # Python 3.14 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
And please add a link to the setuptools issue where they are going to remove these
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
or maybe not, but I still prefer the approach without the added attribute.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think there is such an issue. |
||||||
| code = '; '.join(( | ||||||
| "import sys", | ||||||
| # Code used by "-nspkg.pth" files generated by setuptools | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Probably move this comment to just above line 239, since it applies to the whole statement. Also, |
||||||
| "sitedir = sys._getframe(1).f_locals['sitedir']", | ||||||
| "print(sitedir)", | ||||||
| )) | ||||||
| pth_dir, pth_fn = self.make_pth(code) | ||||||
| with support.captured_stdout() as stdout: | ||||||
| known_paths = site.addpackage(pth_dir, pth_fn, set()) | ||||||
| sitedir = stdout.getvalue().rstrip() | ||||||
| self.assertEqual(sitedir, pth_dir) | ||||||
|
|
||||||
| # This tests _getuserbase, hence the double underline | ||||||
| # to distinguish from a test for getuserbase | ||||||
| def test__getuserbase(self): | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,3 @@ | ||||||
| Restore compatibility with setuptools ``nspkg.pth`` files in the :mod:`site` | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| module. Inject ``sitedir`` variable in the frame which executes pth code. | ||||||
| Patch by Victor Stinner. | ||||||
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.
If adding an attribute is a blocker issue, Petr suggested to recreate sitedir from the PTH filename: #149671 (comment).
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.
Using an attribute is problematic for two reasons:
StartupState.addsitedir()will overwrite the previous value so there's probably a re-entrancy problem with this approach.importline support we'll have to make changes in more than one place, and by that time, we may not remember why we addedself._sitedirin the first place (or, clients will come to depend on it even though it's non-public).@encukou approach is less yucky.