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
Rework license scripts #185
Merged
ordovicia
merged 11 commits into
pfnet-research:master
from
ordovicia:rework-license-scripts
Apr 8, 2019
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
77b156c
git ignore python-related files
ordovicia 39db766
Remove redundant "(C)" in modification license terms
ordovicia aed1622
Rework license scripts
ordovicia 91753d8
Fix .travis.yaml to call check_license.py (commented out)
ordovicia b128a80
Add license header to e2e.go
ordovicia 63cce0d
Minor fix on add_license.py
ordovicia e58e84d
Move license scripts to scripts/license directory
ordovicia 700e9a0
Fix license scripts
ordovicia 222397c
Add verbose option to license scripts
ordovicia 5c112da
Enable license checking in CI
ordovicia 3a7d8c7
Fix license_header.py
ordovicia File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,60 @@ | ||
# Copyright 2019 Preferred Networks, Inc. | ||
# | ||
# 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. | ||
|
||
""" | ||
Adds a license header to files. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
from license_header import license_header, has_license_header | ||
|
||
PROJECT_ROOT = Path(__file__).resolve().parents[1] | ||
|
||
|
||
def main(): | ||
add(PROJECT_ROOT.glob("*[!vendor]/**/*_k8s.go"), | ||
license_header("//", True)) | ||
add([p for p in PROJECT_ROOT.glob("*[!vendor]/**/*.go") | ||
if p.name[-7:] != "_k8s.go"], license_header("//")) | ||
add(PROJECT_ROOT.glob("*[!vendor]/**/*.py"), license_header("#")) | ||
add(PROJECT_ROOT.glob("*[!vendor]/**/*.sh"), license_header("#")) | ||
|
||
|
||
def add(paths, license_header): | ||
for p in paths: | ||
if has_license_header(p, license_header): | ||
continue | ||
|
||
print("Add license header to file", p.relative_to(PROJECT_ROOT)) | ||
|
||
with open(p) as f: | ||
content = f.readlines() | ||
|
||
if content[0][:2] == "#!": # reserve shebangs | ||
content_new = [content[0], "\n", license_header, "\n"] | ||
|
||
# put a newline after the license header only if necessary | ||
if content[1] != "\n": | ||
content_new += ["\n"] | ||
content_new += content[1:] | ||
else: | ||
content_new = [license_header, "\n", "\n"] + content | ||
|
||
with open(p, "w") as f: | ||
f.write(''.join(content_new)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This target is not used.
And to validate license headers, we can simply do
$ python3 ./scripts/license/check.py
.I think there is no need to use Make.
We can re-add this target later if we need.