Merge "Fix unconditional license print if H103 is not selected"
This commit is contained in:
commit
8e26e603ec
@ -86,11 +86,12 @@ def hacking_has_correct_license(physical_line, filename, lines, line_number):
|
|||||||
if line_number == 1 and len(lines) > 10 and _project_is_apache():
|
if line_number == 1 and len(lines) > 10 and _project_is_apache():
|
||||||
for idx, line in enumerate(lines):
|
for idx, line in enumerate(lines):
|
||||||
column = line.find('Licensed under the Apache License')
|
column = line.find('Licensed under the Apache License')
|
||||||
if (0 < column < 10 and not
|
if 0 < column < 10:
|
||||||
_check_for_exact_apache(idx, lines)):
|
exact, cmp_str = _check_for_exact_apache(idx, lines)
|
||||||
if (line.find('SPDX-License-Identifier: Apache-2.0') <= 0):
|
if (not exact and
|
||||||
|
line.find('SPDX-License-Identifier: Apache-2.0') <= 0):
|
||||||
return (column, "H103: Header does not match Apache 2.0 "
|
return (column, "H103: Header does not match Apache 2.0 "
|
||||||
"License notice")
|
"License notice" + cmp_str)
|
||||||
|
|
||||||
|
|
||||||
EMPTY_LINE_RE = re.compile(r"^\s*(#.*|$)")
|
EMPTY_LINE_RE = re.compile(r"^\s*(#.*|$)")
|
||||||
@ -163,11 +164,10 @@ under the License."""
|
|||||||
stripped_apache2 = re.sub(r'\s+', ' ', APACHE2).strip()
|
stripped_apache2 = re.sub(r'\s+', ' ', APACHE2).strip()
|
||||||
|
|
||||||
if stripped_apache2 in content:
|
if stripped_apache2 in content:
|
||||||
return True
|
return (True, None)
|
||||||
else:
|
else:
|
||||||
print("<license>!=<apache2>:\n'%s' !=\n'%s'" %
|
return (False, "\n<license>!=<apache2>:\n'%s' !=\n'%s'" %
|
||||||
(content, stripped_apache2))
|
(content, stripped_apache2))
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
@core.flake8ext
|
@core.flake8ext
|
||||||
|
@ -90,7 +90,20 @@ class CoreTestCase(tests.TestCase):
|
|||||||
def test_H103_full_fail(self):
|
def test_H103_full_fail(self):
|
||||||
"""Verify that the H103 check finds an SPDX header"""
|
"""Verify that the H103 check finds an SPDX header"""
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
(2, 'H103: Header does not match Apache 2.0 License notice'),
|
(2, 'H103: Header does not match Apache 2.0 License notice\n'
|
||||||
|
'<license>!=<apache2>:\n'
|
||||||
|
'\'Licensed under the Apache License, Version 2.0 foo bar foo '
|
||||||
|
'bar foo bar foo bar foo bar\' !=\n'
|
||||||
|
'\'Licensed under the Apache License, Version 2.0 (the '
|
||||||
|
'"License"); you may not use this file except in compliance '
|
||||||
|
'with the License. You may obtain a copy of the License at '
|
||||||
|
'http://www.apache.org/licenses/LICENSE-2.0 Unless required '
|
||||||
|
'by applicable law or agreed to in writing, software '
|
||||||
|
'distributed under the License is distributed on an "AS IS" '
|
||||||
|
'BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either '
|
||||||
|
'express or implied. See the License for the specific '
|
||||||
|
'language governing permissions and limitations under the '
|
||||||
|
'License.\''),
|
||||||
comments.hacking_has_correct_license(
|
comments.hacking_has_correct_license(
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
Loading…
Reference in New Issue
Block a user