|
| 1 | +{# |
| 2 | +# license_header.j2 for cookiecutter-cookiecutter |
| 3 | +# |
| 4 | +# Copyright (c) 2025, Jared Cook |
| 5 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <www.gnu.org>. |
| 19 | +#} |
| 20 | + |
| 21 | +{%- macro license_header( |
| 22 | + license_type, |
| 23 | + author, |
| 24 | + project_name, |
| 25 | + file_name='none', |
| 26 | + comment_style='hash' |
| 27 | +) -%} |
| 28 | + {# |
| 29 | + This renders license header depending on user selection of cookiecutter.license. |
| 30 | + Args: license_type, author, file_name, comment_style. |
| 31 | + #} |
| 32 | +{# This macro generates the correct license header based on input #} |
| 33 | +{# Define variables for start/end comment delimiters #} |
| 34 | +{%- set start_comment = "" -%} |
| 35 | +{%- set end_comment = "" -%} |
| 36 | +{%- set newline = "\n" -%} |
| 37 | +{# Determine the correct comment style #} |
| 38 | +{%- if comment_style == 'python' -%} |
| 39 | + {%- set start_comment = '"""' + newline -%} |
| 40 | + {%- set end_comment = newline + '"""' -%} |
| 41 | +{%- elif comment_style == 'html' -%} |
| 42 | + {%- set start_comment = '<!-- ' + newline -%} |
| 43 | + {%- set end_comment = newline + '-->' -%} |
| 44 | +{%- else -%} |
| 45 | + {# Default to hash/pound symbol for yaml, toml, shell scripts, etc. #} |
| 46 | + {%- set start_comment = '#' -%} |
| 47 | + {%- set end_comment = newline -%} |
| 48 | +{%- endif -%} |
| 49 | +{# Generate the core license text #} |
| 50 | +{% set license_text %} |
| 51 | +{{ file_name }} for {{ project_name }} |
| 52 | + |
| 53 | +Copyright (c) {% now 'utc', '%Y' %}, {{ author }} |
| 54 | +{% if license_type == "Apache-2.0" -%} |
| 55 | +SPDX-License-Identifier: Apache-2.0 |
| 56 | + |
| 57 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 58 | +you may not use this file except in compliance with the License. |
| 59 | +You may obtain a copy of the License at |
| 60 | + |
| 61 | + www.apache.org |
| 62 | + |
| 63 | +Unless required by applicable law or agreed to in writing, software |
| 64 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 65 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 66 | +See the License for the specific language governing permissions and |
| 67 | +limitations under the License. |
| 68 | +{% elif license_type == "BSD-3-Clause" -%} |
| 69 | +SPDX-License-Identifier: BSD-3-Clause |
| 70 | + |
| 71 | +Redistribution and use in source and binary forms, with or without |
| 72 | +modification, are permitted provided that the following conditions are met: |
| 73 | + |
| 74 | +1. Redistributions of source code must retain the above copyright notice, this |
| 75 | + list of conditions and the following disclaimer. |
| 76 | + |
| 77 | +2. Redistributions in binary form must reproduce the above copyright notice, |
| 78 | + this list of conditions and the following disclaimer in the documentation |
| 79 | + and/or other materials provided with the distribution. |
| 80 | + |
| 81 | +3. Neither the name of the copyright holder nor the names of its |
| 82 | + contributors may be used to endorse or promote products derived from |
| 83 | + this software without specific prior written permission. |
| 84 | + |
| 85 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 86 | +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 87 | +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 88 | +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 89 | +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 90 | +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 91 | +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 92 | +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 93 | +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 94 | +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 95 | +{% elif license_type == "GPL-3.0" -%} |
| 96 | +SPDX-License-Identifier: GPL-3.0-or-later |
| 97 | + |
| 98 | +This program is free software: you can redistribute it and/or modify |
| 99 | +it under the terms of the GNU General Public License as published by |
| 100 | +the Free Software Foundation, either version 3 of the License, or |
| 101 | +(at your option) any later version. |
| 102 | + |
| 103 | +This program is distributed in the hope that it will be useful, |
| 104 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 105 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 106 | +GNU General Public License for more details. |
| 107 | + |
| 108 | +You should have received a copy of the GNU General Public License |
| 109 | +along with this program. If not, see <www.gnu.org>. |
| 110 | +{% elif license_type == "MIT" -%} |
| 111 | +SPDX-License-Identifier: MIT |
| 112 | + |
| 113 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 114 | +of this software and associated documentation files (the "Software"), to deal |
| 115 | +in the Software without restriction, including without limitation the rights |
| 116 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 117 | +copies of the Software, and to permit persons to whom the Software is |
| 118 | +furnished to do so, subject to the following conditions: |
| 119 | + |
| 120 | +The above copyright notice and this permission notice shall be included in all |
| 121 | +copies or substantial portions of the Software. |
| 122 | + |
| 123 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 124 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 125 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 126 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 127 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 128 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 129 | +SOFTWARE. |
| 130 | +{% endif -%} |
| 131 | +{%- endset -%} |
| 132 | +{# Wrap the generated text with the appropriate start and end delimiters #} |
| 133 | +{%- if comment_style == 'python' or comment_style == 'html' -%} |
| 134 | +{{ start_comment -}} |
| 135 | +{{ license_text | trim }} |
| 136 | +{{- end_comment }} |
| 137 | +{%- else -%} |
| 138 | +{%- set text = license_text.split('\n') -%} |
| 139 | +{# For hash comments, prefix every line with '#' #} |
| 140 | +{%- for line in text -%} |
| 141 | +{%- if line == '' or line == '\n' -%} |
| 142 | +{%- set commented_line = line -%} |
| 143 | +{%- else -%} |
| 144 | +{%- set commented_line = " " + line -%} |
| 145 | +{%- endif -%} |
| 146 | +#{{ commented_line }} |
| 147 | +{% endfor -%} |
| 148 | +{%- endif -%} |
| 149 | +{%- endmacro -%} |
0 commit comments