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

Python Exception MountError: Can't mount widget(s) before Vertical() is mounted upon startup #7

Closed
xavierog opened this issue May 29, 2024 · 4 comments

Comments

@xavierog
Copy link

Hi,

I installed cliexercices through pipx in a Debian Sid/unstable container and got the following stacktrace when launching it:

[0][12:03:06][user]{fe066b4f7864}~ $ cliexercises
╭──────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────────────────────────────────────────────╮
│ /home/user/.local/share/pipx/venvs/cliexercises/lib/python3.11/site-packages/cliexercises/cli_exercises.py:87 in on_mount                                                                                         │
│                                                                                                                                                                                                                   │
│    84 │                                                                                        ╭───────────────────────────────── locals ─────────────────────────────────╮                                       │
│    85 │   def on_mount(self):                                                                  │ self = CLIExercisesApp(title='CLIExercisesApp', classes={'-light-mode'}) │                                       │
│    86 │   │   self.dark = self.user_progress.get(-1, False)                                    ╰──────────────────────────────────────────────────────────────────────────╯                                       │
│ ❱  87 │   │   self.set_quest_ip_op()                                                                                                                                                                              │
│    88 │                                                                                                                                                                                                           │
│    89 │   def on_input_submitted(self, event):                                                                                                                                                                    │
│    90 │   │   self.process_user_cmd()                                                                                                                                                                             │
│                                                                                                                                                                                                                   │
│ /home/user/.local/share/pipx/venvs/cliexercises/lib/python3.11/site-packages/cliexercises/cli_exercises.py:153 in set_quest_ip_op                                                                                 │
│                                                                                                                                                                                                                   │
│   150 │   │   │   │   ip_txt = self.trim(f.read())                                             ╭───────────────────────────────────────────── locals ──────────────────────────────────────────────╮              │
│   151 │   │   │   l_ip = Label(ip_txt, classes='ip_op', markup=False)                          │        f = <_io.TextIOWrapper name='ip.txt' mode='r' encoding='ascii'>                            │              │
│   152 │   │   │   l_ip.border_title = ip_file                                                  │  ip_file = 'ip.txt'                                                                               │              │
│ ❱ 153 │   │   │   v_ip.mount(l_ip)                                                             │ ip_files = ['ip.txt']                                                                             │              │
│   154 │   │                                                                                    │   ip_txt = 'hi there\nhow are you\n\n2 apples\n12 bananas\n\n\nblue sky\nyellow sun\nbrown earth' │              │
│   155 │   │   self.op_txt = self.trim(self.questions[self.q_idx]['op_file'])                   │     l_ip = Label()                                                                                │              │
│   156 │   │   l_op = Label(self.op_txt, classes='ip_op', markup=False)                         │     self = CLIExercisesApp(title='CLIExercisesApp', classes={'-light-mode'})                      │              │
│                                                                                                │     v_ip = Vertical()                                                                             │              │
│                                                                                                │     v_op = Vertical()                                                                             │              │
│                                                                                                ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯              │
│                                                                                                                                                                                                                   │
│ /home/user/.local/share/pipx/venvs/cliexercises/lib/python3.11/site-packages/textual/widget.py:938 in mount                                                                                                       │
│                                                                                                                                                                                                                   │
│    935 │   │   │   provided a ``MountError`` will be raised.                                    ╭─────── locals ───────╮                                                                                          │
│    936 │   │   """                                                                              │   after = None       │                                                                                          │
│    937 │   │   if not self.is_attached:                                                         │  before = None       │                                                                                          │
│ ❱  938 │   │   │   raise MountError(f"Can't mount widget(s) before {self!r} is mounted")        │    self = Vertical() │                                                                                          │
│    939 │   │   # Check for duplicate IDs in the incoming widgets                                │ widgets = (Label(),) │                                                                                          │
│    940 │   │   ids_to_mount = [widget.id for widget in widgets if widget.id is not None]        ╰──────────────────────╯                                                                                          │
│    941 │   │   unique_ids = set(ids_to_mount)                                                                                                                                                                     │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
MountError: Can't mount widget(s) before Vertical() is mounted
[0][12:03:09][user]{fe066b4f7864}~ $
@learnbyexample
Copy link
Owner

learnbyexample commented May 29, 2024

Seems like something has changed in new versions of Textual. I haven't pinned the framework to a particular version (did that because it was convenient for me using pip and a single venv environment to test all of my TUI apps).

I'm not familiar with pipx, but if you are able to install Textual version 0.57.1 (what I last checked) and then install this app in the same environment, it should work.

@learnbyexample
Copy link
Owner

Relevant discussion: Textualize/textual#4570

@learnbyexample
Copy link
Owner

I've uploaded a new version of the cliexercises app that takes of the mount issue. Let me know if it works on your end.

The same problem is present in some of the other apps as well, so I'll keep this issue open until they are fixed.

@xavierog
Copy link
Author

I've uploaded a new version of the cliexercises app that takes of the mount issue. Let me know if it works on your end.

Yes, I confirm cliexercises 2.2.0 works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants