Make boilerplate.py smarter about generated

Don't just grep for DO NOT EDIT - anchor it in something that looks like
a comment and alone on a line.

Also ignore __* dirs

Prevent it from triggering on update-generated-swagger-docs (hack, but
better than before)
This commit is contained in:
Tim Hockin 2023-01-11 23:58:37 -08:00
parent 4d42fbccbc
commit 965d5d8608
No known key found for this signature in database
2 changed files with 22 additions and 26 deletions

View File

@ -62,10 +62,6 @@ def get_refs():
def is_generated_file(filename, data, regexs):
for d in skipped_ungenerated_files:
if d in filename:
return False
p = regexs["generated"]
return p.search(data)
@ -151,21 +147,15 @@ def file_extension(filename):
return os.path.splitext(filename)[1].split(".")[-1].lower()
skipped_dirs = ['third_party', '_gopath', '_output', '.git', 'cluster/env.sh',
"vendor", "test/e2e/generated/bindata.go", "hack/boilerplate/test",
"staging/src/k8s.io/kubectl/pkg/generated/bindata.go"]
# list all the files contain 'DO NOT EDIT', but are not generated
skipped_ungenerated_files = [
'hack/update-generated-swagger-docs.sh',
'hack/boilerplate/boilerplate.py'
]
skipped_names = ['third_party', '_gopath', '_output', '.git', 'cluster/env.sh',
"vendor", "test/e2e/generated/bindata.go", "hack/boilerplate/test",
"staging/src/k8s.io/kubectl/pkg/generated/bindata.go"]
def normalize_files(files):
newfiles = []
for pathname in files:
if any(x in pathname for x in skipped_dirs):
if any(x in pathname for x in skipped_names):
continue
newfiles.append(pathname)
for i, pathname in enumerate(newfiles):
@ -184,9 +174,13 @@ def get_files(extensions):
# as we would prune these later in normalize_files(). But doing it
# cuts down the amount of filesystem walking we do and cuts down
# the size of the file list
for d in skipped_dirs:
for d in skipped_names:
if d in dirs:
dirs.remove(d)
for d in dirs:
# dirs that start with __ are ignored
if re.match("^__", d):
dirs.remove(d)
for name in walkfiles:
pathname = os.path.join(root, name)
@ -222,7 +216,7 @@ def get_regexs():
# strip #!.* from scripts
regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE)
# Search for generated files
regexs["generated"] = re.compile('DO NOT EDIT')
regexs["generated"] = re.compile(r"^[/*#]+ +.* DO NOT EDIT\.$", re.MULTILINE)
return regexs

View File

@ -41,19 +41,21 @@ gen_types_swagger_doc() {
{
echo -e "$(cat hack/boilerplate/boilerplate.generatego.txt)\n"
echo "package ${group_version##*/}"
# Indenting here prevents the boilerplate checker from thinking this file
# is generated - gofmt will fix the indents anyway.
cat <<EOF
// This file contains a collection of methods that can be used from go-restful to
// generate Swagger API documentation for its models. Please read this PR for more
// information on the implementation: https://github.com/emicklei/go-restful/pull/215
//
// TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if
// they are on one line! For multiple line or blocks that you want to ignore use ---.
// Any context after a --- is ignored.
//
// Those methods can be generated by using hack/update-generated-swagger-docs.sh
// This file contains a collection of methods that can be used from go-restful to
// generate Swagger API documentation for its models. Please read this PR for more
// information on the implementation: https://github.com/emicklei/go-restful/pull/215
//
// TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if
// they are on one line! For multiple line or blocks that you want to ignore use ---.
// Any context after a --- is ignored.
//
// Those methods can be generated by using hack/update-generated-swagger-docs.sh
// AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT.
// AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT.
EOF
} > "${TMPFILE}"