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

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

Conversation

skirpichev
Copy link
Contributor

@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
Contributor 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
Contributor 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
Contributor 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
Contributor Author

See #121672

@ZeroIntensity
Copy link
Contributor

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

@@ -0,0 +1,3 @@
Simplify handling of the history file in ``site.register_readline()``
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that I'm pretty sure this suggestion will break buildbots while site.register_readline is undocumented. Document that before adding this.

Suggested change
Simplify handling of the history file in ``site.register_readline()``
Simplify handling of the history file in :func:`site.register_readline`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this out of the scope for this pr.

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
Contributor

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
Contributor 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?

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.

None yet

5 participants