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

Improve tidy's license validation logic #12781

Merged
merged 3 commits into from Aug 14, 2016
Merged

Conversation

@UK992
Copy link
Contributor

UK992 commented Aug 9, 2016

Rebased and fixed #10721, which is inactive for months.
Fixes #10716

r? @larsbergstrom or @edunham


This change is Reviewable

@highfive
Copy link

highfive commented Aug 9, 2016

Heads up! This PR modifies the following files:

  • @wafflespeanut: python/tidy/servo_tidy_tests/test_tidy.py, python/tidy/HISTORY.rst, python/tidy/servo_tidy/tidy.py, python/tidy/servo_tidy/licenseck.py, python/tidy/setup.py, python/tidy/servo_tidy_tests/apache2_license.rs
@UK992 UK992 force-pushed the UK992:tidycheck-rebased branch from 4521d53 to bd2bf06 Aug 9, 2016
@@ -150,3 +154,7 @@ def test_file_list(self):
def do_tests():
suite = unittest.TestLoader().loadTestsFromTestCase(CheckTidiness)
return 0 if unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() else 1
unittest.TextTestRunner(verbosity=2).run(suite)

This comment has been minimized.

@jdm

jdm Aug 9, 2016

Member

This is unreachable code.

This comment has been minimized.

@UK992

UK992 Aug 9, 2016

Author Contributor

done!

@UK992 UK992 force-pushed the UK992:tidycheck-rebased branch from bd2bf06 to d4d7948 Aug 9, 2016
@UK992
Copy link
Contributor Author

UK992 commented Aug 9, 2016

With last commit i added grabbing actual comment block, and also added checking for blank line after shebang, so that doesn't messed up license check.

@jdm jdm added S-fails-travis and removed S-fails-travis labels Aug 9, 2016
@jdm
Copy link
Member

jdm commented Aug 9, 2016

The travis failure is unrelated to these changes.

@@ -7,97 +7,14 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

mpl = "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/"

This comment has been minimized.

@aneeshusa

aneeshusa Aug 10, 2016

Member

Why put these onto a single line? AFAIK the indentation never changes, just the comment character at the start of each line. IMO this form is nicer:

mpl = """\
This Source Code...
""",

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 10, 2016

Member

Style Nit: Also, the name could be in uppercase, since it's a constant (even though it doesn't make any difference in python).

This comment has been minimized.

@UK992

UK992 Aug 10, 2016

Author Contributor

@aneeshusa i changed it to this type of form, and before matching with header remove all newlines.



def licensed_mpl(header):
if licenseck.mpl in header:

This comment has been minimized.

@aneeshusa

aneeshusa Aug 10, 2016

Member

We can do return licenseck.mpl in header directly.


# These licenses are valid for use in Servo
licenses = [
apache = "Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. This file may not be copied, modified, or distributed except according to those terms."

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 10, 2016

Member

ditto on the name

copyright = [
"See the COPYRIGHT file at the top-level directory of this distribution",
"See http://rust-lang.org/COPYRIGHT",
]

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 10, 2016

Member

copyright is a built-in function. ditto on uppercase?

yield (1, "missing blank line after shebang")

blank_lines = 0
MAX_BLANK_LINES = 2 if lines[0].startswith("#!") else 1

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 10, 2016

Member

Style nit: This shouldn't be uppercase, since it's a variable.

@@ -150,3 +159,6 @@ def test_file_list(self):
def do_tests():
suite = unittest.TestLoader().loadTestsFromTestCase(CheckTidiness)
return 0 if unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() else 1

if __name__ == "__main__":
do_tests()

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 10, 2016

Member

Why was this change introduced?

This comment has been minimized.

@UK992

UK992 Aug 10, 2016

Author Contributor

don't know, i removed it.

@@ -1,6 +1,17 @@
Release History
---------------

0.1.0 (2016-04-19)

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 10, 2016

Member

psst... date?


def licensed_apache(header):
if licenseck.apache in header:
for copyright in licenseck.copyright:

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 10, 2016

Member

ditto on copyright

@@ -305,7 +339,7 @@ def check_toml(file_name, lines):
for idx, line in enumerate(lines):
if line.find("*") != -1:
yield (idx + 1, "found asterisk instead of minimum version number")
for license in licenses_toml:
for license in licenseck.licenses_toml:

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 10, 2016

Member

license is also a built-in function

@UK992
Copy link
Contributor Author

UK992 commented Aug 10, 2016

Addressed all reviews.

@@ -139,3 +66,4 @@
'name = "webrender"',
'name = "webrender_traits"',
]
# noqa: Indicate to flake8 that we do not want to check indentation here

This comment has been minimized.

@aneeshusa

aneeshusa Aug 10, 2016

Member

We shouldn't need this anymore since we don't have unindented strings inside a list (the old licenses variable).

This comment has been minimized.

@UK992

UK992 Aug 10, 2016

Author Contributor

removed.

@@ -17,12 +17,9 @@
import StringIO
import subprocess
import sys
from licenseck import licenses, licenses_toml, licenses_dep_toml
import licenseck as licenses

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 11, 2016

Member

Nit: This should be from licenseck import MPL, ... (we don't wanna prefer * even though we import all the names)

EMACS_HEADER = "/* -*- Mode:"
VIM_HEADER = "/* vim:"
MAX_LICENSE_LINESPAN = max(len(license.splitlines()) for license in licenses)
COMMENTS = ["// ", "# ", " *", "/* ", "*/ "]

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 11, 2016

Member

We won't be needing */ here, would we?



def licensed_mpl(header):
return licenses.MPL.replace('\n', ' ') in header

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 11, 2016

Member

Instead of doing a string replacement for every function call, we could just have a global variable like mpl = MPL.replace('\n', ' ') or something at the top.

This comment has been minimized.

@UK992

UK992 Aug 11, 2016

Author Contributor

I added backslash to every line in licenseck.



def licensed_apache(header):
if licenses.APACHE.replace('\n', ' ') in header:

This comment has been minimized.

@wafflespeanut

wafflespeanut Aug 11, 2016

Member

ditto on "globalizing"

@highfive
Copy link

highfive commented Aug 12, 2016

  ▶ Unexpected subtest result in /html/browsers/browsing-the-web/history-traversal/browsing_context_name.html:
  └ PASS [expected FAIL] Retaining window.name on history traversal
@UK992
Copy link
Contributor Author

UK992 commented Aug 13, 2016

Last commit add support for colored text in Windows Console.
Before:
screenshot 2016-08-13 03 10 42

After:
screenshot 2016-08-13 03 11 06

@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 14, 2016

Thanks again! :)

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Aug 14, 2016

📌 Commit fed0e94 has been approved by Wafflespeanut

@bors-servo
Copy link
Contributor

bors-servo commented Aug 14, 2016

Testing commit fed0e94 with merge 4b5f859...

bors-servo added a commit that referenced this pull request Aug 14, 2016
Improve tidy's license validation logic

Rebased and fixed #10721, which is inactive for months.
Fixes #10716

r? @larsbergstrom or @edunham

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12781)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 14, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Aug 14, 2016

  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/transform-table-007.htm
  └   → /css-transforms-1_dev/html/transform-table-007.htm a5c014b20ef1363bea6f24eda28c7efb7c45698a
/css-transforms-1_dev/html/reference/transform-blank-ref.htm fa6407b1acbbfea27e27061e7d1bdeca98e4a728
Testing a5c014b20ef1363bea6f24eda28c7efb7c45698a == fa6407b1acbbfea27e27061e7d1bdeca98e4a728
@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 14, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 14, 2016

Testing commit fed0e94 with merge 8419f96...

bors-servo added a commit that referenced this pull request Aug 14, 2016
Improve tidy's license validation logic

Rebased and fixed #10721, which is inactive for months.
Fixes #10716

r? @larsbergstrom or @edunham

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12781)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 14, 2016

💔 Test failed - mac-rel-wpt

@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 14, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 14, 2016

Previous build results for arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, windows-dev are reusable. Rebuilding only mac-rel-wpt...

@bors-servo
Copy link
Contributor

bors-servo commented Aug 14, 2016

@bors-servo bors-servo merged commit fed0e94 into servo:master Aug 14, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@UK992 UK992 deleted the UK992:tidycheck-rebased branch Sep 2, 2016
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.

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