-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-41541: Make pty.spawn set window size #21861
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
Conversation
184e866
to
0b94299
Compare
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.
I don't see any new tests. There should be at least one that fails before the new code is applied which then passes after it is applied.
The current tests are in Lib/test/test_pty.py.
Sir, thank you for taking the time to review this. I understand. While this was originally meant to be applied, now it is merely a sample. I have made several other improvements, and the final result is here: https://github.com/8vasu/pypty2 The final result has conflicts with this patch. While there is nothing wrong with this patch, it should not be applied. However, I still suggest that this tiny change be used as a starting point to get a sense of what can happen if window resizing is not present. I will add a test now. I will also reupload the png images to bpo. |
I have added the before and after screenshots and the short example that I had used to test this to the BPO issue. This example is from the docs ( see https://docs.python.org/3/library/pty.html ). I took the screenshots to make it easy for the reviewer: this is a visual change. Please follow these steps in indicated order to reproduce the issue:
The output is expected to be wrapped around the edges of the xterm window, making it hard to visually parse. Note that this patch does NOT handle SIGWINCH. It merely sets initial window size for slave. Therefore, if the xterm window is resized AFTER script.py is started, this patch will not resize slave accordingly. I have added that functionality to pypty2. More rigorous stty-based tests will be added to pypty2 if you find this smaller change useful. These changes are very useful if one uses a tiling window manager. |
May I please have a short chat session with you on freenode #python-dev sometime? |
Unfortunately I have never learned IRC. If I understand what you would like to do, which is to simply replace the current You should also add tests for the known problems that the current I know it's a big task, but doing it would prove a couple things:
Okay, apparently I am now registered on freenode. Feel free to look me up! |
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.
From my understanding, writing a test for this PR seems to mostly be a matter of creating a terminal from STDIN with a specified window size, and then reading the FD's (slave_fd
) window size to ensure it's the same after it's spawned. Since pty.spawn()
doesn't appear to expose the FD for the terminal window, you would write the tests against login_tty()
. Alternatively, you could create a mock version of pty.spawn()
that exposes the FD or allows you to pass a pair created from os.opentty()
rather than within pty.spawn()
(purely for testing purposes, within test_pty
-- this could be potentially written as a nested function within something like test_spawn_winsize()
).
TL;DR the test(s) should somehow address the change that pty.spawn()
now sets window size based on STDIN.
(I'm very far from an expert with pty, but hopefully the above gives you a general idea of what the appropriate tests might involve. If/when Thomas (@Yhg1s) gets around to reviewing the PR, he could have more detailed feedback.)
Edit: For additional context, I left this review comment based on what the OP wrote in core-mentorship, they seemed to be seeking some guidance on how the unit test(s) should be written for this change.
@ethanfurman @aeros This was very helpful. I (we :D ?) can work on this during weekends. Note: This pull request adds |
Here you go: https://bugs.python.org/issue41818 I have started doing my homework on unittest. I am tempted to go the mock function route for all pty.spawn() tests. Is there any particular time during next weekend when you will be available on IRC #python-dev? Thank you for your patience. |
@ethanfurman Would the mock function route (as I suggested earlier) be reasonable in the unit test(s) for this specific change? Just wanted to double check before the author invests too much time into it, since I have not worked with the internals of tty previously. |
The purpose of For example, if you have a function that returns data from a database using a complex query then your test should be verifying that the created query is correct, so you would use In this case the target of the test is the window itself, and its size -- so a test needs to be able to create the window, and then retrieve information about it, and |
@ethanfurman I get it. Upon request of @aeros, I will use modified terminology for the pty ends. I will use |
Cool. Instead of If it looks like I'll time on Saturday I'll post a comment here. |
Haha. Got it! The reason why I used |
Why not call it something like That being said, I think either
Not to go too deep into the terminology rabbit hole, but I think it's perfectly reasonable to base the connotation of a term in a project from the primary language it uses (English in this case) rather than pursuing every culture's. Otherwise, the number of useful analogy terms starts to become very limited to an extent that I would consider to be impractical for ease of communication. So, I'm not personally opposed to |
Thank you for the feedback @aeros. As you said, not to go too deep into the terminology rabbit hole, but here is a final suggestion toward which I am inclined:
If @ethanfurman @aeros like these terms, then I will start to use them in |
Updates: now Edit: the terminology has not been changed yet. |
Updates: thank you for being patient. I have added the main tests to pypty2: slave termios, slave winsize, and FreeBSD hang. Do you prefer a pull request on GitHub or do you want me to upload pypty2 to bpo first? Edit: I can make a pull request/upload the files on next Saturday. |
Sir, I have created the first pull request [ #22962 ]. Thank you very much for making me do this :) I now have some experience with python's unittest library! To make it easier for you, this pull request only includes the tests from pypty2; I will make subsequent pull requests based on your suggestions. The new tests are
As you suggested, I have added @expectedfailure for no. 2 and no. 3 and a custom @expectedFailureOnBSD for no. 4. Edit: @expectedfailure has been changed to @expectedFailureIfStdinIsTTY since the automated tests on GitHub were failing otherwise: their stdin is not a tty. Please run the tests on a tty to achieve desired results :) |
I need this fix in a project that I'm working on. What is missing to merge the branch? |
This is being done in a series of PRs. I do not want to make a hasty fix
for this. To expedite the process can you please help review some of my
PRs? Please see bpo-41818. bpo-41541 is abandoned. Thank you.
…On Wed, Apr 27, 2022, 3:10 AM Paul Laffitte ***@***.***> wrote:
I need this fix in a project that I'm working on. What is missing to merge
the branch?
—
Reply to this email directly, view it on GitHub
<#21861 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQDGGD5JILUV6SJKUD25DPLVHDY7RANCNFSM4P6V42AQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Ok, I understand. Thanks for the quick answer. I took a look at your PRs, but I don't really know what could I do to help. I never contributed to python before and it looks like some people are already reviewing them, so I feel I will not be very useful in this context 😅 |
Thank you for understanding :) I am trying my best to get this done. The
python core devs (I am not one of them) have limited time; they are also
doing their best to help us.
…On Thu, Apr 28, 2022, 12:28 PM Paul Laffitte ***@***.***> wrote:
Ok, I understand. Thanks for the quick answer. I took a look at your PRs,
but I don't really know what could I do to help. I never contributed to
python before and it looks like some people are already reviewing them, so
I feel I will not be very useful in this context 😅
—
Reply to this email directly, view it on GitHub
<#21861 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQDGGD6JCZS76DGP2WOECEDVHLDCHANCNFSM4P6V42AQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
- window size cf. python/cpython#21861 - ctrl+R
I will close the PR and issue. If the situation changed, please reopen (or comment, if you don't have permission). In case it is reopened: This will need docs and tests. Let's keep inclusive terminology for another PR -- it's important, but also complicated, orthogonal to the functionality, and best discussed with another group of people (see PEP-732). For now, be consistent with terminology that's already in the docs, and in the man pages of the POSIX API we're wrapping: |
@encukou Thank you for closing this. |
https://bugs.python.org/issue41541