forked from DeepLabCut/DeepLabCut
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code for automatically updating license headers (DeepLabCut#2028)
- Loading branch information
Showing
4 changed files
with
198 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# This notice file contains license headers for all code files | ||
# in the repository (currently all *.py files). | ||
# | ||
# When updating headers, lower entries take precedence over higher | ||
# entries. For each header, include/exclude statements can be used | ||
# to define files to apply them to. | ||
# | ||
# When adding code from an external repo, make sure to cover the | ||
# added code files with the correct license header. | ||
|
||
# Main repository license | ||
- header: | | ||
DeepLabCut Toolbox (deeplabcut.org) | ||
© A. & M.W. Mathis Labs | ||
https://github.com/DeepLabCut/DeepLabCut | ||
Please see AUTHORS for contributors. | ||
https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS | ||
Licensed under GNU Lesser General Public License v3.0 | ||
include: | ||
- 'deeplabcut/**/*.py' | ||
- 'tests/**/*.py' | ||
- 'examples/**/*.py' | ||
- 'docs/**/*.py' | ||
- 'conda-environments/**/*.yaml' | ||
|
||
# License for files adapted from DeeperCut by Eldar Insafutdinov | ||
# https://github.com/eldar/pose-tensorflow | ||
# Applies to most files in deeplabcut.pose_estimation_tensorflow | ||
- header: | | ||
DeepLabCut Toolbox (deeplabcut.org) | ||
© A. & M.W. Mathis Labs | ||
https://github.com/DeepLabCut/DeepLabCut | ||
Please see AUTHORS for contributors. | ||
https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS | ||
Adapted from DeeperCut by Eldar Insafutdinov | ||
https://github.com/eldar/pose-tensorflow | ||
Licensed under GNU Lesser General Public License v3.0 | ||
include: | ||
# This filelist was generated by running | ||
# find deeplabcut/pose_estimation_tensorflow -iname '*.py' | xargs grep 'Eldar Insafutdinov' | ||
# from the repo base directory. | ||
- deeplabcut/pose_estimation_tensorflow/config.py | ||
- deeplabcut/pose_estimation_tensorflow/datasets/factory.py | ||
- deeplabcut/pose_estimation_tensorflow/vis_dataset.py | ||
- deeplabcut/pose_estimation_tensorflow/core/train.py | ||
- deeplabcut/pose_estimation_tensorflow/core/predict.py | ||
- deeplabcut/pose_estimation_tensorflow/core/test.py | ||
- deeplabcut/pose_estimation_tensorflow/default_config.py | ||
- deeplabcut/pose_estimation_tensorflow/util/visualize.py | ||
- deeplabcut/pose_estimation_tensorflow/util/__init__.py | ||
- deeplabcut/pose_estimation_tensorflow/util/logging.py | ||
- deeplabcut/pose_estimation_tensorflow/nnets/resnet.py | ||
- deeplabcut/pose_estimation_tensorflow/__init__.py | ||
exclude: [] | ||
|
||
# Tensorflow licenses | ||
- header: | | ||
Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
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. | ||
include: | ||
- deeplabcut/pose_estimation_tensorflow/backbones/*.py | ||
- deeplabcut/pose_estimation_tensorflow/nnets/utils.py | ||
|
||
- header: | | ||
Copyright 2018 The TensorFlow Authors. All Rights Reserved. | ||
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. | ||
include: | ||
- deeplabcut/pose_estimation_tensorflow/nnets/conv_blocks.py | ||
- deeplabcut/pose_estimation_tensorflow/backbones/mobilenet.py | ||
- deeplabcut/pose_estimation_tensorflow/backbones/mobilenet_v2.py | ||
|
||
# TIMM license | ||
- header: | | ||
Copyright 2019 Ross Wightman | ||
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. | ||
Hacked together by / Copyright 2020 Ross Wightman | ||
https://github.com/rwightman/pytorch-image-models/blob/main/timm/scheduler/scheduler_factory.py | ||
include: | ||
- deeplabcut/pose_tracking_pytorch/solver/scheduler_factory.py |
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,13 @@ | ||
# Developer tools useful for maintaining the repository | ||
|
||
## Code headers | ||
|
||
The code headers can be standardized by running | ||
|
||
``` bash | ||
python tools/update_license_headers.py | ||
``` | ||
|
||
from the repository root. | ||
|
||
You can edit the `NOTICE.yml` to update the header. |
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,63 @@ | ||
"""Apply copyright headers to all code files in the repository. | ||
This file can be called as a python script without arguments. For | ||
configuration, see the instructions in NOTICE.yml. | ||
""" | ||
|
||
import tempfile | ||
import glob | ||
import yaml | ||
import fnmatch | ||
import subprocess | ||
|
||
|
||
def load_config(filename): | ||
with open(filename, "r") as fh: | ||
config = yaml.safe_load(fh) | ||
return config | ||
|
||
|
||
def walk_directory(entry): | ||
"""Talk the directory""" | ||
|
||
if "header" not in entry: | ||
raise ValueError("Current entry does not have a header.") | ||
if "include" not in entry: | ||
raise ValueError("Current entry does not have an include list.") | ||
|
||
def _list_include(): | ||
"""List all files specified in the include list.""" | ||
for include_pattern in entry["include"]: | ||
for filename in glob.iglob(include_pattern, recursive=True): | ||
yield filename | ||
|
||
def _filter_exclude(iterable): | ||
"""Filter filenames from an iterator by the exclude patterns.""" | ||
for filename in iterable: | ||
for exclude_pattern in entry.get("exclude", []): | ||
if fnmatch.fnmatch(filename, exclude_pattern): | ||
break | ||
else: | ||
yield filename | ||
|
||
files = _filter_exclude(set(_list_include())) | ||
return list(files) | ||
|
||
|
||
def main(input_file="NOTICE.yml"): | ||
config = load_config(input_file) | ||
for entry in config: | ||
filelist = list(walk_directory(entry)) | ||
with tempfile.NamedTemporaryFile(mode="w") as header_file: | ||
header_file.write(entry["header"]) | ||
header_file.flush() | ||
header_file.seek(0) | ||
command = ["licenseheaders", "-t", str(header_file.name), "-f"] + filelist | ||
result = subprocess.run(command, capture_output=True) | ||
if result.returncode != 0: | ||
print(result.stdout.decode()) | ||
print(result.stderr.decode()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |