Skip to content
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

gh-121245: Refactor site.register_readline() #121659

Merged
merged 3 commits into from
Jul 15, 2024

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Jul 13, 2024

also initialize CAN_USE_PYREPL at import from _pyrepl.main

also initialize CAN_USE_PYREPL at import from _pyrepl.main
@skirpichev
Copy link
Member Author

@smontanaro, if you can reproduce #121245, then please try this patch.

@smontanaro
Copy link
Contributor

smontanaro commented Jul 13, 2024 via email

@smontanaro
Copy link
Contributor

That said, I agree now my idea for skipping the test is wrong. Rebuilding the readline module to use the readline 8.2.10 library in /opt/homebrew, I still get the same failure.

@skirpichev
Copy link
Member Author

Rebuilding the readline module to use the readline 8.2.10 library in /opt/homebrew, I still get the same failure.

Then I would guess, as noted in #121422, that problem is related to your local customization. Try unset all PYTHON* environment variables and run tests.

@smontanaro
Copy link
Contributor

Rebuilding the readline module to use the readline 8.2.10 library in /opt/homebrew, I still get the same failure.

Then I would guess, as noted in #121422, that problem is related to your local customization. Try unset all PYTHON* environment variables and run tests.

I get that, and yes, I agree, my personal interactive settings are interfering. I have long had readline customizations in my setup. I think the correct solution is for the test suite to be run in isolation, at least that part of it which purports to test interactive features such as readline. See Victor's fix in #121414.

@skirpichev
Copy link
Member Author

skirpichev commented Jul 13, 2024

See Victor's fix in #121414.

Unfortunately, this fix already applied and it's not enough. We can do a local fix:

diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index 015b690566..88b1dc38f0 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -909,6 +909,12 @@ def test_not_wiping_history_file(self):
         hfile = tempfile.NamedTemporaryFile(delete=False)
         self.addCleanup(unlink, hfile.name)
         env = os.environ.copy()
+
+        # cleanup from PYTHON* variables
+        for k in env.copy():
+            if k.startswith("PYTHON"):
+                env.pop(k)
+
         env["PYTHON_HISTORY"] = hfile.name
         commands = "123\nspam\nexit()\n"
 

Let me know if this does work for you.

But I'm thinking on a more generic solution: probably we should instead make a default environment for all tests (say, my_env), clean PYTHON* variables in one and then in every test do my_env.copy().

Edit: typo fixed, sorry :(

@skirpichev
Copy link
Member Author

See #121672

@ZeroIntensity
Copy link
Member

site.register_readline is undocumented, it should get documented by this patch.

Lib/site.py Outdated Show resolved Hide resolved
Lib/site.py Outdated
readline.read_history_file(history)
else:
_pyrepl.readline.read_history_file(history)
my_readline.read_history_file(history)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
my_readline.read_history_file(history)
target_readline.read_history_file(history)

Lib/site.py Outdated Show resolved Hide resolved
Lib/_pyrepl/main.py Outdated Show resolved Hide resolved
@pablogsal
Copy link
Member

Thanks for the PR @skirpichev. Unfortunately you are mixing what seems to be a fix for #121245 with a general refactor, what makes more difficult to understand what is happening here and what is and what isn't necessary. What is worse, it makes it not possible to back port because 3.13 accepts bug fixes but in no way refactors. Can you please keep the changes to only the minimum set of things require to fix #121245?

@skirpichev
Copy link
Member Author

Unfortunately you are mixing what seems to be a fix for #121245 with a general refactor

@pablogsal, in fact I think that that issue is fixed (but I'm not sure, heh). It was reopened by my request, because added regression has many failures on build bots. But this seems to be fixed by #121422.

I still think, that refactoring belongs to the #121245. With new code it's obvious that we are using same readline both while reading the history and while writing...

Does this make sense for you?



def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
global CAN_USE_PYREPL
if not CAN_USE_PYREPL:
Copy link
Contributor

Choose a reason for hiding this comment

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

This old case only happened for old Windows, in which case we didn't print any warning. This is now changing but I think that's fine.

@ambv ambv merged commit 05d4137 into python:main Jul 15, 2024
41 checks passed
@ambv ambv added topic-repl Related to the interactive shell needs backport to 3.13 bugs and security fixes labels Jul 15, 2024
@miss-islington-app
Copy link

Thanks @skirpichev for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 15, 2024
(cherry picked from commit 05d4137)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Jul 15, 2024

GH-121816 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jul 15, 2024
ambv added a commit that referenced this pull request Jul 15, 2024
…21816)

(cherry picked from commit 05d4137)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
ambv added a commit to zvyn/cpython that referenced this pull request Jul 15, 2024
@skirpichev skirpichev deleted the refactor-register_readline-121245 branch July 16, 2024 00:54
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-repl Related to the interactive shell
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants