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

Rework license scripts #185

Merged
merged 11 commits into from Apr 8, 2019
131 changes: 126 additions & 5 deletions .gitignore
@@ -1,3 +1,5 @@
### https://raw.github.com/github/gitignore/f908e51bcf38ae5ede449c55189a7b25d8c507cc/Go.gitignore

# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -11,15 +13,134 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out


### https://raw.github.com/github/gitignore/f908e51bcf38ae5ede449c55189a7b25d8c507cc/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/


### Project-specific config

# Log files
*.log

# Coverage files
*.cov
# Coverage file
profile.cov

# Misc
.envrc
dist/
tmp/
/config.yaml
AUTHORS
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -11,4 +11,4 @@ script:
- make lint test coverage
- goveralls -coverprofile=profile.cov -service=travis-ci
- make e2e
# - make check-license
# - python3 ./scripts/license/check.py
4 changes: 0 additions & 4 deletions Makefile
Expand Up @@ -29,7 +29,3 @@ e2e:
coverage:
go test -covermode=count -coverprofile=profile.cov $(shell go list ./... | grep -v /vendor/)
go tool cover -func=profile.cov

.PHONY: check-license
check-license:
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

./scripts/check_license.sh
2 changes: 1 addition & 1 deletion pkg/queue/priority_queue_k8s.go
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Modifications copyright (C) 2019 Preferred Networks, Inc.
// Modifications 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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/generic_scheduler_k8s.go
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Modifications copyright (C) 2019 Preferred Networks, Inc.
// Modifications 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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/util_k8s.go
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Modifications copyright (C) 2019 Preferred Networks, Inc.
// Modifications 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.
Expand Down
76 changes: 0 additions & 76 deletions scripts/add_license.sh

This file was deleted.

36 changes: 0 additions & 36 deletions scripts/check_license.sh

This file was deleted.

60 changes: 60 additions & 0 deletions scripts/license/add.py
@@ -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()