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

Use blessings when possible for WPT UI #8551

Merged
merged 1 commit into from Nov 17, 2015
Merged

Conversation

@mrobinson
Copy link
Member

mrobinson commented Nov 16, 2015

Use blessings when it is possible for the WPT UI and fall back to using
raw control characters. This also fixes a bug where the UI didn't work
correctly in iTerm.app. Remove the one line version of the UI, since it
is no longer used as the iTerm fallback.

Review on Reviewable

@mrobinson
Copy link
Member Author

mrobinson commented Nov 16, 2015

@jdm or @jgraham r?

self.terminal = blessings.Terminal()
self.clear_eol = self.terminal.clear_eol
self.move_up = self.terminal.move_up
except:

This comment has been minimized.

@frewsxcv

frewsxcv Nov 16, 2015

Member

Can we make this except ImportError just so we silence+catch all exceptions in case one occurs from something else?

This comment has been minimized.

@mrobinson

mrobinson Nov 16, 2015

Author Member

The idea here was that if the import failed, if creating the Terminal failed, or if the __getattr__ call in blessings fails (which just calls into curses), we should always fall back. If you like I can split the work into two try/except blocks and print an error in the second one.

This comment has been minimized.

@jgraham

jgraham Nov 16, 2015

Contributor

try and except with no condition is never a good idea; even except Exception: is better because it won't catch KeyboardInterrupt. In this case I agree that splitting into two blocks is a better idea.

@jgraham
Copy link
Contributor

jgraham commented Nov 17, 2015

Reviewed 1 of 1 files at r1.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from the review on Reviewable.io

@mrobinson mrobinson force-pushed the mrobinson:blessings branch from c54b7b7 to 2e04bd2 Nov 17, 2015
@mrobinson
Copy link
Member Author

mrobinson commented Nov 17, 2015

Review status: all files reviewed at latest revision, 1 unresolved discussion.


tests/wpt/grouping_formatter.py, line 33 [r1] (raw file):
Done.


Comments from the review on Reviewable.io

@jgraham
Copy link
Contributor

jgraham commented Nov 17, 2015

Reviewed 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 3 unresolved discussions.


tests/wpt/grouping_formatter.py, line 53 [r2] (raw file):
Factor out the default values here and below


tests/wpt/grouping_formatter.py, line 58 [r2] (raw file):
use Exception as exception (or I prefer Exception as e)


Comments from the review on Reviewable.io

return self.terminal.clear_eol, self.terminal.move_up
except Exception, exception:
sys.stderr.write("GroupingFormatter: Could not get terminal "
"control characters: %s" % exception)

This comment has been minimized.

@frewsxcv

frewsxcv Nov 17, 2015

Member

This probably needs a \n since write doesn't add one

@jgraham
Copy link
Contributor

jgraham commented Nov 17, 2015

Review status: all files reviewed at latest revision, 4 unresolved discussions.


tests/wpt/grouping_formatter.py, line 60 [r2] (raw file):
Actually I'm not sure this line doesn't do more harm than good since it causes a warning message that can't go through the mozlog infrastructure. I'd be inclined just to delete it.


Comments from the review on Reviewable.io

@mrobinson
Copy link
Member Author

mrobinson commented Nov 17, 2015

Review status: all files reviewed at latest revision, 4 unresolved discussions.


tests/wpt/grouping_formatter.py, line 60 [r2] (raw file):
I think it's still useful since it allows us to improve the script if there are problems finding the appropriate control codes. If it's deleted, I believe that the two try/except blocks should be merged. There isn't any point in isolated ImportError when we respond to all exceptions in the same way.


Comments from the review on Reviewable.io

Use blessings when it is possible for the WPT UI and fall back to using
raw control characters. This also fixes a bug where the UI didn't work
correctly in iTerm.app. Remove the one line version of the UI, since it
is no longer used as the iTerm fallback.
@mrobinson mrobinson force-pushed the mrobinson:blessings branch from 2e04bd2 to 7225e36 Nov 17, 2015
@mrobinson
Copy link
Member Author

mrobinson commented Nov 17, 2015

Review status: all files reviewed at latest revision, 4 unresolved discussions.


tests/wpt/grouping_formatter.py, line 53 [r2] (raw file):
Done.


tests/wpt/grouping_formatter.py, line 58 [r2] (raw file):
Done.


Comments from the review on Reviewable.io

@jgraham
Copy link
Contributor

jgraham commented Nov 17, 2015

Reviewed 1 of 1 files at r3.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


tests/wpt/grouping_formatter.py, line 60 [r2] (raw file):
I guess it's probably OK like this, but it's not ideal.


Comments from the review on Reviewable.io

@mrobinson
Copy link
Member Author

mrobinson commented Nov 17, 2015

Review status: all files reviewed at latest revision, 2 unresolved discussions.


tests/wpt/grouping_formatter.py, line 60 [r2] (raw file):
If you have a better approach for sending the error through machformatter, I'll be happy to implement it. I considered recording it and logging it after the logger was initialized, but that seemed a bit convoluted.


Comments from the review on Reviewable.io

@jgraham
Copy link
Contributor

jgraham commented Nov 17, 2015

@bors-servo
Copy link
Contributor

bors-servo commented Nov 17, 2015

📌 Commit 7225e36 has been approved by jgraham

@bors-servo
Copy link
Contributor

bors-servo commented Nov 17, 2015

Testing commit 7225e36 with merge d7c98f8...

bors-servo added a commit that referenced this pull request Nov 17, 2015
Use blessings when possible for WPT UI

Use blessings when it is possible for the WPT UI and fall back to using
raw control characters. This also fixes a bug where the UI didn't work
correctly in iTerm.app. Remove the one line version of the UI, since it
is no longer used as the iTerm fallback.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8551)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 17, 2015

@bors-servo bors-servo merged commit 7225e36 into servo:master Nov 17, 2015
2 of 3 checks passed
2 of 3 checks passed
code-review/reviewable Review in progress: all files reviewed, 2 unresolved discussions
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@mrobinson mrobinson deleted the mrobinson:blessings branch Nov 17, 2015

try:
self.terminal = blessings.Terminal()
return self.terminal.clear_eol, self.terminal.move_up

This comment has been minimized.

@salty-horse

salty-horse Dec 5, 2015

Contributor

clear_eol and move_up are in the wrong order :)

This comment has been minimized.

@frewsxcv

frewsxcv Dec 5, 2015

Member

Excellent detective work @salty-horse 👍

This comment has been minimized.

@mrobinson

mrobinson Dec 5, 2015

Author Member

Nice catch!

This comment has been minimized.

@frewsxcv

frewsxcv Dec 6, 2015

Member

@salty-horse You going to open a PR to fix it?

This comment has been minimized.

@salty-horse

salty-horse Dec 6, 2015

Contributor

Will do. Can I put my other suggestion in a separate commit in the same PR?

else:
return ("\033[F" + "\033[K") * len(self.current_display.splitlines())
return ((self.move_up + self.clear_eol) *
len(self.current_display.splitlines()))

This comment has been minimized.

@salty-horse

salty-horse Dec 5, 2015

Contributor

instead of len(s.splitlines()), s.count('\n') should be equivalent (unless Windows does weird things, which I doubt)

This comment has been minimized.

@frewsxcv

frewsxcv Dec 6, 2015

Member

What advantages does your new solution have?

This comment has been minimized.

@salty-horse

salty-horse Dec 6, 2015

Contributor

It's slightly faster (did not measure). No need to create a list with new strings just to count its length. However:

  1. It only works if you assume the last line ends with a newline (Simple fix if you want to support other cases, but I don't think it's an issue)
  2. Only tested on Linux.

This comment has been minimized.

@frewsxcv

frewsxcv Dec 6, 2015

Member

It might be better use s.count(os.linesep) for better Windows support, though I'm not too sure TBH

https://docs.python.org/2/library/os.html#os.linesep

This comment has been minimized.

@mrobinson

mrobinson Dec 6, 2015

Author Member

This is counting the number of lines in self.current_display, which is always assigned internally. I believe that means that Windows line endings shouldn't pose any complications. As far as I can tell the .count("\n") approach should be fine.

This comment has been minimized.

@salty-horse

salty-horse Dec 6, 2015

Contributor

The rest of the strings are composed with \n, so I'm not sure what that will do :)
If no-one can confirm it's working on Windows/Mac, I'll just patch the other bit.

This comment has been minimized.

@salty-horse

salty-horse Dec 6, 2015

Contributor

I tested this on mac and windows, and it does what you expect. So seems fine to me:

'a\nb\nc\n'.count('\n')

This comment has been minimized.

@jdm

jdm Dec 6, 2015

Member

I would expect splitting a constant string on a constant separator to work the same on all platforms :) The real question is given multiline string content from an external source, does it contain \r values that would cause difficulties when splitting on \n?

This comment has been minimized.

@salty-horse

salty-horse Dec 6, 2015

Contributor

You're right. Not sure why I tested that :P. In any case, there is no external source other than file names in that output.

bors-servo added a commit that referenced this pull request Dec 7, 2015
Fix redraw of WPT UI output, and slightly improve line counting

See discussion in PR #8551.

Redraw of the first test name was broken due to a mix-up between two ANSI escape codes.
I also took the opportunity to change the way line count is calculated. It's a bit cleaner that way (the new operation is ~%20 faster, but that's unnoticeable).

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8861)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.