Skip to content

Commit

Permalink
Code for automatically updating license headers (DeepLabCut#2028)
Browse files Browse the repository at this point in the history
  • Loading branch information
stes authored Nov 9, 2022
1 parent 5f5d616 commit 3e51125
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Now, please make a [pull request](https://github.com/DeepLabCut/DeepLabCut/pull/
- Please run black on the code to conform to our Black code style (see more at https://pypi.org/project/black/).
- Please assign a reviewer, typically @AlexEMG, @mmathislab, or @jeylau (i/e. the [core-developers](https://github.com/orgs/DeepLabCut/teams/core-developers/members))

**Code headers**

- The code headers can be standardized by running `python tools/update_license_headers.py`
- Edit `NOTICE.yml` to update the header.

**DeepLabCut is an open-source tool and has benefited from suggestions and edits by many individuals:**

Expand Down
118 changes: 118 additions & 0 deletions NOTICE.yml
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
13 changes: 13 additions & 0 deletions tools/README.md
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.
63 changes: 63 additions & 0 deletions tools/update_license_headers.py
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()

0 comments on commit 3e51125

Please sign in to comment.