cool-easter-32542
03/14/2023, 9:12 PMpreamble
cannot currently handle the range of valid copyright headers in the StackStorm repo.
I need a template that lets me have:
• 0 or 1 shebang
• 1 or more copyright lines
• 1 license block
Describe the solution you'd like
When the preamble plugin adds the template to the top of a file, it should add only one copyright line, inserting it after the shebang line if present.
If a file has a header with more than one copyright line, the preamble plugin should accept that.
I'm not sure how to extend the template file format to include the additional information about the repeatable portions of the template.
Describe alternatives you've considered
regex-lint plugin can help with validating the header, but it can't automatically add it when missing. I really want to use preamble
so it can auto-add the header for me.
The regex-lint config looks like:
content_patterns:
- name: python_header
pattern: |+
^(?:#\!\/usr\/bin\/env python3
)?# Copyright 20\d\d The StackStorm Authors.
(?:# Copyright 20\d\d .*
)*#
# 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.
Along those lines, maybe the template_by_globs
file could be something like:
<globs>:
match: <regex string>
new: "bla bla $year bla bla"
Another ideas for `template_by_globs`: What if it was an ordered list: each template must match in the order provided. Implicitly, that's what the preamble
plugin does now: 0 or 1 shebang, and then the template. Except then it becomes odd figuring out how many times it can repeat... How would I tag to say that 0-1 shebang or 1+ for copyright, or only once for the rest.
Additional context
Here is an example of a header that should pass:
# Copyright 2020 The StackStorm Authors.
# Copyright 2019 Extreme Networks, Inc.
#
# 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 config, however, will add an extra preamble above what is already there:
"**/*.py:!**/__init__.py": |+
# Copyright $year The StackStorm Authors.
#
# 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.
pantsbuild/pants