<@U02KAN6061E> I'm looking at the preamble plugin ...
# development
p
@bitter-ability-32190 I'm looking at the preamble plugin in 2.16, trying to see if I can use it for StackStorm. It looks like it already handles shebang lines, which is good. We have some files that have multiple copyright lines, but when we add a new header it only has one. So, I want to allow for multiple copyright lines at the beginning of the header. Is there a way to provide one template for matching, and another template for adding a missing one?
b
I don't think so, not as is. Got an example? I'm a visual person 😛
p
Copy code
# 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|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.
b
Would you not just want your preamble to be the... Oh I see. The copyright line is for stackstorm, but the license part is after maybe other copyrights?
p
Here is what I came up with for the preamble config:
Copy code
"**/*.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.
And here's the same in the regex-lint plugin's config:
Copy code
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.
So: optional shebang + 1 or more copyright lines + license block So, what I would like: When the preamble plugin adds it to the top of a file, it would only add one copyright line, and optionally insert it after a shebang line if present.
b
I think maybe just another placeholder supported for ~anything. And it's only used for validation
p
What if the values in
template_by_globs
could be a dict of two templates instead of a string:
Copy code
<globs>:
  match: <regex string>
  new: "bla bla $year bla bla"
b
Having the match be regex is super annoying for non-regex because of the escaping. I'll sit on it though
p
Yeah writing multiline regex can be... Mind bending. What if it was an ordered list: each template must match in the order provided. Implicitly, that's what you have: 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. Yeah this needs more noodling.
Something else that I would like - I would love to target all python sources, no matter the name. So, when an executable like
st2-pack-install
(no extension) is owned by a
python_sources
target, then it should also get picked up by preamble.
b
You're touching new territory with that request. It's possible but we haven't dipped our toe in yet. Can you file issues for these?
👍 1