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

Textual console showing wrong path #3237

Closed
willmcgugan opened this issue Sep 5, 2023 · 8 comments · Fixed by Textualize/textual-dev#19 or #3294
Closed

Textual console showing wrong path #3237

willmcgugan opened this issue Sep 5, 2023 · 8 comments · Fixed by Textualize/textual-dev#19 or #3294
Assignees
Labels
bug Something isn't working Task

Comments

@willmcgugan
Copy link
Collaborator

The textual console command is showing the wrong path.

IIRC there is an offset in the stack which it uses to find the caller. We may have introduced another level in the stack.

Image

@davep davep self-assigned this Sep 7, 2023
@davep davep added bug Something isn't working Task labels Sep 7, 2023
@davep
Copy link
Contributor

davep commented Sep 13, 2023

On initial look at this, I don't think the issue is as broad as is suggested here. Given this code:

from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Button

class LogLocationApp(App[None]):

    def compose(self) -> ComposeResult:
        yield Button("Print", id="print")
        yield Button("Log", id="log")

    @on(Button.Pressed, "#print")
    def print_to_console(self) -> None:
        print("This was from a print")

    @on(Button.Pressed, "#log")
    def log_to_console(self) -> None:
        self.log.debug("This was from a log")

if __name__ == "__main__":
    LogLocationApp().run()

I see a variety of locations that mostly look okay:

Screenshot 2023-09-13 at 10 59 02

Presumably the thing that's the issue here is when something is logged to the console via print?

@davep
Copy link
Contributor

davep commented Sep 13, 2023

Looks like the change was brought in with the capture print facility: 4406b9d

davep added a commit to Textualize/textual-dev that referenced this issue Sep 13, 2023
Fixes Textualize/textual#3237

I'm undecided about this. It doesn't feel quite right to special-case this,
but on the other hand `print` is a form of logging that seems to work
differently in Textual vs the normal logging facility (which seems to do its
own dance to handle the call location, before it makes it to devtools).

This does correct the issue, this does ensure that `print` reports the
location the same as any `self.log` call. So this is a commit made to
solicit more detail on the design decisions in the core of Textual.
davep added a commit to Textualize/textual-dev that referenced this issue Sep 13, 2023
This time, don't special-case the print down in the StdoutRedirector, but
instead allow the caller to pass in the frame we're supposed to work from.

Note that with this change it *won't* fix the problem that this seeks to
fix, but it will allow for a change in Textual that will fix the problem. As
such this code should be merged and released *before* such code is merged
into Textual.

Meanwhile, this code should be safe to release first as it's designed to be
backward-compatible.

See Textualize/textual#3237
@willmcgugan
Copy link
Collaborator Author

@davep What's the resolution here? It's in For Review, but no linked PR.

@davep
Copy link
Contributor

davep commented Sep 25, 2023

The description of the PR linked just above (#3294) has the explanation. I believe @darrenburns reviewed the textual-dev side of things late last week, and moving this on was predicated on that being reviewed, accepted and deployed.

@willmcgugan
Copy link
Collaborator Author

Can you please make that happen, and ping me when you need something deployed.

@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@davep
Copy link
Contributor

davep commented Sep 25, 2023

Reopening for a moment (GitHub helpfully closed it when I merged the PR on textual-dev).

@willmcgugan textual-dev should now be ready to deploy (with an appropriate version bump, of course), so things can then move forward.

@davep davep reopened this Sep 25, 2023
@davep davep closed this as completed in 057cb7f Oct 5, 2023
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
2 participants