Skip to content

mtest: consider AttributeError#15445

Merged
dcbaker merged 1 commit intomesonbuild:masterfrom
komh:mtest
Jan 22, 2026
Merged

mtest: consider AttributeError#15445
dcbaker merged 1 commit intomesonbuild:masterfrom
komh:mtest

Conversation

@komh
Copy link
Copy Markdown
Contributor

@komh komh commented Jan 6, 2026

os.get_terminal_size is not defined on OS/2.

@bonzini bonzini added this to the 1.11 milestone Jan 6, 2026
Comment thread mesonbuild/mtest.py Outdated
except OSError:
except (OSError, AttributeError):
self.cols = 80
self.is_tty = False
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it indeed accurate to say that OS/2 doesn't (cannot ever) have a tty?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Error says that os does not have get_terminal_size attr. I know, os.get_terminal_size() has not been implemented on OS/2.

Copy link
Copy Markdown
Contributor

@bonzini bonzini Jan 13, 2026

Choose a reason for hiding this comment

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

Would this work instead?

        self.is_tty = os.isatty(1)
        self.cols = 80
        if self.is_tty:
            try:
                self.cols, _ = os.get_terminal_size(1)
            except (OSError, AttributeError):
                pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but parentheses are necessary.

Traceback (most recent call last):
  File "f:/lang/work/meson/meson-os2.git/meson.py", line 27, in <module>
    sys.exit(mesonmain.main())
  File "f:\lang\work\meson\meson-os2.git/mesonbuild/mesonmain.py", line 313, in main
    return run(sys.argv[1:], launcher)
  File "f:\lang\work\meson\meson-os2.git/mesonbuild/mesonmain.py", line 304, in run
    return CommandLineParser().run(args)
  File "f:\lang\work\meson\meson-os2.git/mesonbuild/mesonmain.py", line 67, in __init__
    from . import mconf, mdist, minit, minstall, mintro, msetup, mtest, rewriter, msubprojects, munstable_coredata, mcompile, mdevenv, mformat
  File "f:\lang\work\meson\meson-os2.git/mesonbuild/mtest.py", line 562
    except OSError, AttributeError:
                  ^
SyntaxError: invalid syntax

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And the following error ocurrs:

[0/1] Running all tests
Traceback (most recent call last):
  File "f:\lang\work\meson\meson-os2.git/mesonbuild/mesonmain.py", line 193, in run
    return options.run_func(options)
  File "f:\lang\work\meson\meson-os2.git/mesonbuild/mtest.py", line 2308, in run
    with TestHarness(options) as th:
  File "f:\lang\work\meson\meson-os2.git/mesonbuild/mtest.py", line 1674, in __init__
    self.console_logger = ConsoleLogger(options.max_lines)
  File "f:\lang\work\meson\meson-os2.git/mesonbuild/mtest.py", line 565, in __init__
    self.output_start = dashes(self.SCISSORS, self.HLINE, self.cols - 2)
AttributeError: 'ConsoleLogger' object has no attribute 'cols'

ERROR: Unhandled python exception

    This is a Meson bug and should be reported!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See edited comment above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it works!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would this work instead?

Then there is no need to check for OSError either... OSError is how os.get_terminal_size(1) signals that fd 1 isn't a tty.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed OSError.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Without OSError check, PowerShell tests failed. So I added it again.

os.get_terminal_size is not defined on OS/2.
@dcbaker dcbaker merged commit cab9b60 into mesonbuild:master Jan 22, 2026
31 checks passed
@komh komh deleted the mtest branch January 23, 2026 13:58
@bonzini bonzini modified the milestones: 1.11, 1.10.3 Mar 17, 2026
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

Successfully merging this pull request may close these issues.

4 participants