-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New checks added: liccheck, copyright_check AEA-1690 (#31)
* Liccheck added. * Copywrite check added. * Copywrites added. * Comment updated. * Makefile updated. * Copyright check added. * Makefile updated. * Misprint fixed. * Misprint fixed.
- Loading branch information
1 parent
381c686
commit 304db06
Showing
40 changed files
with
856 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ build/ | |
|
||
# IDEs | ||
.idea/ | ||
|
||
# Requirements file generated for license check (liccheck) | ||
requirements.txt |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,98 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2018-2019 Fetch.AI Limited | ||
# | ||
# 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. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
""" | ||
This script checks that all the Python files of the repository have: | ||
- (optional) the Python shebang | ||
- the encoding header; | ||
- the copyright notice; | ||
It is assumed the script is run from the repository root. | ||
""" | ||
|
||
import itertools | ||
import re | ||
import sys | ||
from pathlib import Path | ||
|
||
|
||
SUPPORTED_YEARS = ["2019", "2020", "2021"] | ||
|
||
|
||
HEADER_REGEX = fr"""(#!/usr/bin/env python3 | ||
)?# -\*- coding: utf-8 -\*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# (Copyright 2018-({"|".join(SUPPORTED_YEARS)}) Fetch.AI Limited|Copyright [0-9]{{4}}(-[0-9]{{4}})? [a-zA-Z_]+) | ||
# | ||
# 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\. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
""" | ||
|
||
|
||
def check_copyright(file: Path) -> bool: | ||
""" | ||
Given a file, check if the header stuff is in place. | ||
Return True if the files has the encoding header and the copyright notice, | ||
optionally prefixed by the shebang. Return False otherwise. | ||
:param file: the file to check. | ||
:return: True if the file is compliant with the checks, False otherwise. | ||
""" | ||
content = file.read_text() | ||
header_regex = re.compile(HEADER_REGEX, re.MULTILINE) | ||
return re.match(header_regex, content) is not None | ||
|
||
|
||
if __name__ == "__main__": | ||
python_files = itertools.chain( | ||
Path("src/cosm").glob("**/*.py"), | ||
[Path("setup.py")], | ||
) | ||
|
||
# filter out protobuf files (*_pb2.py) | ||
python_files_filtered = filter( | ||
lambda x: not str(x).endswith("_pb2.py"), python_files | ||
) | ||
|
||
bad_files = [ | ||
filepath for filepath in python_files_filtered if not check_copyright(filepath) | ||
] | ||
|
||
if len(bad_files) > 0: | ||
print("The following files are not well formatted:") | ||
print("\n".join(map(str, bad_files))) | ||
sys.exit(1) | ||
else: | ||
print("OK") | ||
sys.exit(0) |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
[flake8] | ||
paths=src | ||
copyright-check = True | ||
select = C | ||
exclude=.md, vulture_whitelist.py | ||
ignore = E501,E701 | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2018-2021 Fetch.AI Limited | ||
# | ||
# 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. | ||
# | ||
# ------------------------------------------------------------------------------ |
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 |
---|---|---|
@@ -1 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2018-2021 Fetch.AI Limited | ||
# | ||
# 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. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""This package contains the Auth modules.""" |
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
Oops, something went wrong.