-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set up automatic license header for source files
- Loading branch information
Showing
3 changed files
with
64 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,39 @@ | ||
import os | ||
|
||
# Path to the license header | ||
HEADER_FILE = "license-header.txt" | ||
|
||
# read license header | ||
with open(HEADER_FILE) as file: | ||
license_header = file.read() | ||
|
||
|
||
# Add license header to a file | ||
def add_license_header(file_path, header): | ||
with open(file_path) as f: | ||
content = f.read() | ||
|
||
# Check if the header is already there | ||
if content.startswith(header): | ||
return | ||
|
||
# If not, add it | ||
with open(file_path, "w") as f: | ||
f.write(header + "\n" + content) | ||
print(f"Header added to {file_path}") | ||
|
||
|
||
# Check the header in every file in root_dir | ||
def apply_license_header_to_all_py_files(root_dir): | ||
for subdir, _, files in os.walk(root_dir): | ||
for file in files: | ||
if file.endswith(".py"): | ||
file_path = os.path.join(subdir, file) | ||
add_license_header(file_path, license_header) | ||
|
||
|
||
# Source repertory | ||
PROJECT_SRC = "xdem" | ||
|
||
# Add header to every source files | ||
apply_license_header_to_all_py_files(PROJECT_SRC) |
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,16 @@ | ||
# Copyright (c) 2024 xDEM developers | ||
# | ||
# This file is part of xDEM project: | ||
# https://github.com/glaciohack/xdem | ||
# | ||
# 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. |