-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add remaining copyright statements, add licenses sanity test #5098
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f8e769d
Add sanity test (currently fails).
felixfontein 51c7313
doc_fragments can also be non-GPLv3+.
felixfontein eb36302
Replace 'Author:' by 'Copyright:' in some specific cases.
felixfontein 9ccf564
Avoid matching string for license checkers.
felixfontein e1acc5f
Reformulate not to throw license detection off.
felixfontein 21b1398
Add PSF copyright notice for plugins/module_utils/_mount.py.
felixfontein 7ca7fb0
Add generic copyright notices.
felixfontein ee9ee66
Update changelog fragment.
felixfontein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| minor_changes: | ||
| - "All software licenses are now in the ``LICENSES/`` directory of the collection root (https://github.com/ansible-collections/community.general/pull/5065, https://github.com/ansible-collections/community.general/pull/5079, https://github.com/ansible-collections/community.general/pull/5080, https://github.com/ansible-collections/community.general/pull/5083, https://github.com/ansible-collections/community.general/pull/5087, https://github.com/ansible-collections/community.general/pull/5095)." | ||
| - "All software licenses are now in the ``LICENSES/`` directory of the collection root (https://github.com/ansible-collections/community.general/pull/5065, https://github.com/ansible-collections/community.general/pull/5079, https://github.com/ansible-collections/community.general/pull/5080, https://github.com/ansible-collections/community.general/pull/5083, https://github.com/ansible-collections/community.general/pull/5087, https://github.com/ansible-collections/community.general/pull/5095, https://github.com/ansible-collections/community.general/pull/5098)." | ||
| - "Added MIT license as ``LICENSES/MIT.txt`` for tests/unit/plugins/modules/packaging/language/test_gem.py (https://github.com/ansible-collections/community.general/pull/5065)." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "include_symlinks": false, | ||
| "output": "path-message" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/usr/bin/env python | ||
| # Copyright (c) 2022, Felix Fontein <felix@fontein.de> | ||
| # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
| """Prevent files without a correct license identifier from being added to the source tree.""" | ||
| from __future__ import (absolute_import, division, print_function) | ||
| __metaclass__ = type | ||
|
|
||
| import os | ||
| import glob | ||
| import sys | ||
|
|
||
|
|
||
| def format_license_list(licenses): | ||
| if not licenses: | ||
| return '(empty)' | ||
| return ', '.join(['"%s"' % license for license in licenses]) | ||
|
|
||
|
|
||
| def find_licenses(filename, relax=False): | ||
| spdx_license_identifiers = [] | ||
| other_license_identifiers = [] | ||
| has_copyright = False | ||
| try: | ||
| with open(filename, 'r', encoding='utf-8') as f: | ||
| for line in f: | ||
| line = line.rstrip() | ||
| if 'Copyright ' in line: | ||
| has_copyright = True | ||
| if 'Copyright: ' in line: | ||
| print('%s: found copyright line with "Copyright:". Please remove the colon.' % (filename, )) | ||
| if 'SPDX-FileCopyrightText: ' in line: | ||
| has_copyright = True | ||
| idx = line.find('SPDX-License-Identifier: ') | ||
| if idx >= 0: | ||
| spdx_license_identifiers.append(line[idx + len('SPDX-License-Identifier: '):]) | ||
| if 'GNU General Public License' in line: | ||
| if 'v3.0+' in line: | ||
| other_license_identifiers.append('GPL-3.0-or-later') | ||
| if 'version 3 or later' in line: | ||
| other_license_identifiers.append('GPL-3.0-or-later') | ||
| if 'Simplified BSD License' in line: | ||
| other_license_identifiers.append('BSD-2-Clause') | ||
| if 'Apache License 2.0' in line: | ||
| other_license_identifiers.append('Apache-2.0') | ||
| if 'PSF License' in line or 'Python-2.0' in line: | ||
| other_license_identifiers.append('PSF-2.0') | ||
| if 'MIT License' in line: | ||
| other_license_identifiers.append('MIT') | ||
| except Exception as exc: | ||
| print('%s: error while processing file: %s' % (filename, exc)) | ||
| if len(set(spdx_license_identifiers)) < len(spdx_license_identifiers): | ||
| print('%s: found identical SPDX-License-Identifier values' % (filename, )) | ||
| if other_license_identifiers and set(other_license_identifiers) != set(spdx_license_identifiers): | ||
| print('%s: SPDX-License-Identifier yielded the license list %s, while manual guessing yielded the license list %s' % ( | ||
| filename, format_license_list(spdx_license_identifiers), format_license_list(other_license_identifiers))) | ||
| if not has_copyright and not relax: | ||
| print('%s: found no copyright notice' % (filename, )) | ||
| return sorted(spdx_license_identifiers) | ||
|
|
||
|
|
||
| def main(): | ||
| """Main entry point.""" | ||
| paths = sys.argv[1:] or sys.stdin.read().splitlines() | ||
|
|
||
| # The following paths are allowed to have no license identifier | ||
| no_comments_allowed = [ | ||
| 'changelogs/fragments/*.yml', | ||
| 'changelogs/fragments/*.yaml', | ||
| 'tests/sanity/extra/*.json', | ||
| 'tests/sanity/ignore-2.*.txt', | ||
| 'COPYING', | ||
| ] | ||
|
|
||
| # These files are completely ignored | ||
| ignore_paths = [ | ||
| 'CHANGELOG.rst', | ||
| 'changelogs/changelog.yaml', | ||
| 'tests/sanity/extra/licenses.py', # The strings in find_licenses() confuse this code :-) | ||
| '.ansible-test-timeout.json', | ||
| 'LICENSES/*.txt', | ||
| ] | ||
|
|
||
| no_comments_allowed = [fn for pattern in no_comments_allowed for fn in glob.glob(pattern)] | ||
| ignore_paths = [fn for pattern in ignore_paths for fn in glob.glob(pattern)] | ||
|
|
||
| valid_licenses = [license_file[len('LICENSES/'):-len('.txt')] for license_file in glob.glob('LICENSES/*.txt')] | ||
|
|
||
| for path in paths: | ||
| if path.startswith('./'): | ||
| path = path[2:] | ||
| if path in ignore_paths or path.startswith('tests/output/'): | ||
| continue | ||
| if os.stat(path).st_size == 0: | ||
| continue | ||
| if not path.endswith('.license') and os.path.exists(path + '.license'): | ||
| path = path + '.license' | ||
| valid_licenses_for_path = valid_licenses | ||
| if path.startswith('plugins/') and not path.startswith(('plugins/modules/', 'plugins/module_utils/', 'plugins/doc_fragments/')): | ||
| valid_licenses_for_path = [license for license in valid_licenses if license == 'GPL-3.0-or-later'] | ||
| licenses = find_licenses(path, relax=path in no_comments_allowed) | ||
| if not licenses: | ||
| if path not in no_comments_allowed: | ||
| print('%s: must have at least one license' % (path, )) | ||
| else: | ||
| for license in licenses: | ||
| if license not in valid_licenses_for_path: | ||
| print('%s: found not allowed license "%s", must be one of %s' % ( | ||
| path, license, format_license_list(valid_licenses_for_path))) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.