WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
75931
webkitpy: add os_name, os_version to platforminfo
https://bugs.webkit.org/show_bug.cgi?id=75931
Summary
webkitpy: add os_name, os_version to platforminfo
Dirk Pranke
Reported
2012-01-09 19:48:35 PST
webkitpy: add os_name, os_version to platforminfo
Attachments
Patch
(17.62 KB, patch)
2012-01-09 19:51 PST
,
Dirk Pranke
no flags
Details
Formatted Diff
Diff
revamp to make it more mockable, add is_mac(), etc.
(22.37 KB, patch)
2012-01-10 14:27 PST
,
Dirk Pranke
eric
: review+
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Dirk Pranke
Comment 1
2012-01-09 19:51:52 PST
Created
attachment 121786
[details]
Patch
Eric Seidel (no email)
Comment 2
2012-01-09 23:02:37 PST
Comment on
attachment 121786
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=121786&action=review
> Tools/Scripts/webkitpy/common/system/platforminfo.py:92 > + if self.os_name == 'mac':
It's a little strange to my eyes that os_name is a member instead of a function. But it does make sense. It's not like the platform changes during execution. :) I also have concern with string comparisions like this as they're very error prone. I've found lots of errors in webkitpy where we check things like sys.platform == "mac" (when it's really supposed to be "darwin"), or sys.platform == "Darwin", etc. I think we should consider using platform_info.is_mac() (or just .is_mac) to get around this possible gotcha. In any case, this is a great improvement. centralizing our platform calls behind a mock is a good thing.
Eric Seidel (no email)
Comment 3
2012-01-09 23:03:10 PST
I'd like you and Adam to have a chance to see/respond to my musings. Then I'll happily r+ this tomorrow. I'm a bit too drained to give a full review atm.
Adam Barth
Comment 4
2012-01-09 23:09:22 PST
Comment on
attachment 121786
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=121786&action=review
This is great.
> Tools/Scripts/webkitpy/common/system/platforminfo.py:54 > + raise AssertionError('unrecognized platform string "%s"' % sys_platform)
Why not just assert (the language construct)?
> Tools/Scripts/webkitpy/common/system/platforminfo.py:63 > + # FIXME: Should this routine enforce minimum versions and handle 'future', or let callers do that?
I would support future here.
>> Tools/Scripts/webkitpy/common/system/platforminfo.py:92 >> + if self.os_name == 'mac': > > It's a little strange to my eyes that os_name is a member instead of a function. But it does make sense. It's not like the platform changes during execution. :) > > I also have concern with string comparisions like this as they're very error prone. I've found lots of errors in webkitpy where we check things like sys.platform == "mac" (when it's really supposed to be "darwin"), or sys.platform == "Darwin", etc. > > I think we should consider using platform_info.is_mac() (or just .is_mac) to get around this possible gotcha. > > In any case, this is a great improvement. centralizing our platform calls behind a mock is a good thing.
Yeah, having an is_mac predicate is a good idea.
> Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py:48 > + def setUp(self): > + self.sys_platform = sys.platform > + self.getwindowsversion = None > + if hasattr(sys, 'getwindowsversion'): > + self.getwindowsversion = getattr(sys, 'getwindowsversion') > + del sys.getwindowsversion
Hum... mutating globals is sad times. Maybe we should pass in a mock sys object to the platforminfo constructor?
Dirk Pranke
Comment 5
2012-01-10 11:43:44 PST
(In reply to
comment #2
)
> (From update of
attachment 121786
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=121786&action=review
> > > Tools/Scripts/webkitpy/common/system/platforminfo.py:92 > > + if self.os_name == 'mac': > > It's a little strange to my eyes that os_name is a member instead of a function. But it does make sense. It's not like the platform changes during execution. :) >
I don't feel strongly one way or another here.
> I also have concern with string comparisions like this as they're very error prone. I've found lots of errors in webkitpy where we check things like sys.platform == "mac" (when it's really supposed to be "darwin"), or sys.platform == "Darwin", etc. > > I think we should consider using platform_info.is_mac() (or just .is_mac) to get around this possible gotcha.
> Sure, I can add some convenience functions. I'll add is_mac, is_win, is_linux, and wrappers for mac versions, since I've seen those elsewhere, but I won't add win or linux version wrappers until someone needs them ... (In reply to
comment #4
)
> (From update of
attachment 121786
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=121786&action=review
> > This is great. > > > Tools/Scripts/webkitpy/common/system/platforminfo.py:54 > > + raise AssertionError('unrecognized platform string "%s"' % sys_platform) > > Why not just assert (the language construct)? >
I'm not sure I follow you ... what language construct would that be in this case?
> > Tools/Scripts/webkitpy/common/system/platforminfo.py:63 > > + # FIXME: Should this routine enforce minimum versions and handle 'future', or let callers do that? > > I would support future here. >
Okay.
> > Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py:48 > > + def setUp(self): > > + self.sys_platform = sys.platform > > + self.getwindowsversion = None > > + if hasattr(sys, 'getwindowsversion'): > > + self.getwindowsversion = getattr(sys, 'getwindowsversion') > > + del sys.getwindowsversion > > Hum... mutating globals is sad times. Maybe we should pass in a mock sys object to the platforminfo constructor?
I will try to rework it to make it more better :).
Adam Barth
Comment 6
2012-01-10 11:56:55 PST
> I'm not sure I follow you ... what language construct would that be in this case?
Reading <
http://docs.python.org/reference/simple_stmts.html
>, it seems like the construct doesn't exist. I must have dreamed it up.
Adam Roben (:aroben)
Comment 7
2012-01-10 12:10:14 PST
Comment on
attachment 121786
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=121786&action=review
>>> Tools/Scripts/webkitpy/common/system/platforminfo.py:54 >>> + raise AssertionError('unrecognized platform string "%s"' % sys_platform) >> >> Why not just assert (the language construct)? > > I'm not sure I follow you ... what language construct would that be in this case?
Presumably you could do something like: assert False, 'unrecognized platform string "%s"' % sys_platform
Dirk Pranke
Comment 8
2012-01-10 14:27:48 PST
Created
attachment 121912
[details]
revamp to make it more mockable, add is_mac(), etc.
Eric Seidel (no email)
Comment 9
2012-01-10 14:35:21 PST
Comment on
attachment 121912
[details]
revamp to make it more mockable, add is_mac(), etc. View in context:
https://bugs.webkit.org/attachment.cgi?id=121912&action=review
Thanks for your work on this.
> Tools/Scripts/webkitpy/common/system/platforminfo.py:39 > + Public (static) properties: > + -- os_name > + -- os_version
I'm slightly wary about making the public, now that you have the is_mac() stuff. We wish to discourage folks from writing error-prone string comparisons.
> Tools/Scripts/webkitpy/common/system/platforminfo.py:67 > + if self.os_name == 'mac':
I think you want is_mac() here.
Dirk Pranke
Comment 10
2012-01-10 15:06:33 PST
(In reply to
comment #9
)
> (From update of
attachment 121912
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=121912&action=review
> > Thanks for your work on this. > > > Tools/Scripts/webkitpy/common/system/platforminfo.py:39 > > + Public (static) properties: > > + -- os_name > > + -- os_version > > I'm slightly wary about making the public, now that you have the is_mac() stuff. We wish to discourage folks from writing error-prone string comparisons. >
True. However, at least for now there are places where I need a string, e.g., in expanding parsing "chromium-mac" and figuring out what the os mapping is. Hopefully once I get further along in the refactoring I'll be able to get rid of most of these references.
> > Tools/Scripts/webkitpy/common/system/platforminfo.py:67 > > + if self.os_name == 'mac': > > I think you want is_mac() here.
Good catch, will fix.
Dirk Pranke
Comment 11
2012-01-10 15:34:11 PST
Committed
r104637
: <
http://trac.webkit.org/changeset/104637
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug