-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
"python -S" should be robust against e.g. "from site import addsitedir" #55800
Comments
If python is run with the -S flag, that declares the intent of the user to not have site-specific additions to sys.path. However, some code in that process may have a legitimate need for a function defined in site.py - for instance, addsitedir. But the act of importing site.py, as a side effect, adds the standard site-specific directories to sys.path. python -S would be more useful and reliable if it prevented importing site from automatically making the sys.path additions. There is no loss of flexibility here, as user code could still explicitly call site.main() to achieve all of the current side-effects of "import site". The fix is a one-liner, and is in the linked hg repository. |
Thanks. Would you mind adding tests in test_site? |
Adding a test is easier said than done. The behavior change here depends on python being run with -S. Currently test_site skips itself if the test suite is run with -S, and if I remove that skip it crashes under -S. Options as I see it:
Which option do you prefer? |
Fair argument. Brett is the author of recent changes in site, let him decide. Brett: Would you agree to 1)? |
This is what I get for trying to clean up site.py years ago. =) I'm fine with the change as long as there is a very clear Misc/NEWS message that the semantics on import have changed (and obviously this is not backported). |
I think this requires a note in NEWS but also in Doc/library/site.rst. Carl, would you like to make a new changeset with that edition in your repo? (It will also provide a test for the Create Patch button after.) |
Added documentation to Doc/library/site.rst and Misc/NEWS. |
Looks great, thank you. I think I’ll also add a docstring to main before committing, now that the function is publicly documented. Did you have to manually click “Create Patch” to make roundup generate it? Did you try first to click on the button of the existing repo before adding a new repo entry? (Still learning how to use it, thanks for experimenting along :) Brett: Thanks for the review. If you don’t comment negatively on the doc change, I will commit this. (Side concern: the module does not define __all__, even though only 4 functions and 4 constants are officially documented. I’d like to define __all__, but the recentish huge thread on public/private APIs scared me.) |
Yes - the first time too.
That would probably have worked fine. The "Remote hg repo" field was just empty when I made my latest comment, so I filled it in again. Wasn't sure if it would duplicate, or be smart enough to tell they were the same repo, or what. I guess it duplicated :/ |
Looks like this field is always empty: its goal is to add a repo, just like the File field is always empty unless you add a file. The existing files and repositories are however listed underneath the form, so your screen just probably did not go low enough for you to see that the repo was still listed. |
Doc changes seem fine to me. |
New changeset a364719e400a by Éric Araujo in branch 'default': |
Committed with small wording changes and more docs. Thank you, and good luck for cpythonv! |
New changeset 9a1ca0062950 by Éric Araujo in branch 'default': |
New changeset 6ee5443773cb by Éric Araujo in branch 'default': |
Now that site can be imported without side effects under -S, I think the tests could be updated: they don’t have to be all skipped under -S. See attached patch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: