2019-07-29 18:51:01 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# Towncrier silently ignores files that do not match the expected ending.
|
|
|
|
# We use this script to ensure we catch these as errors in CI.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pathlib
|
2019-11-26 04:28:05 +08:00
|
|
|
import sys
|
2019-07-29 18:51:01 +08:00
|
|
|
|
|
|
|
ALLOWED_EXTENSIONS = {
|
|
|
|
'.bugfix.rst',
|
|
|
|
'.doc.rst',
|
|
|
|
'.feature.rst',
|
2019-11-26 04:28:05 +08:00
|
|
|
'.internal.rst',
|
2019-07-29 18:51:01 +08:00
|
|
|
'.misc.rst',
|
|
|
|
'.performance.rst',
|
|
|
|
'.removal.rst',
|
|
|
|
}
|
|
|
|
|
|
|
|
ALLOWED_FILES = {
|
|
|
|
'validate_files.py',
|
|
|
|
'README.md',
|
|
|
|
}
|
|
|
|
|
|
|
|
THIS_DIR = pathlib.Path(__file__).parent
|
|
|
|
|
2019-11-26 04:28:05 +08:00
|
|
|
num_args = len(sys.argv) - 1
|
|
|
|
assert num_args in {0, 1}
|
|
|
|
if num_args == 1:
|
|
|
|
assert sys.argv[1] in ('is-empty', )
|
|
|
|
|
2019-07-29 18:51:01 +08:00
|
|
|
for fragment_file in THIS_DIR.iterdir():
|
|
|
|
|
|
|
|
if fragment_file.name in ALLOWED_FILES:
|
|
|
|
continue
|
2019-11-26 04:28:05 +08:00
|
|
|
elif num_args == 0:
|
|
|
|
full_extension = "".join(fragment_file.suffixes)
|
|
|
|
if full_extension not in ALLOWED_EXTENSIONS:
|
|
|
|
raise Exception(f"Unexpected file: {fragment_file}")
|
|
|
|
elif sys.argv[1] == 'is-empty':
|
2019-07-29 18:51:01 +08:00
|
|
|
raise Exception(f"Unexpected file: {fragment_file}")
|
2019-11-26 04:28:05 +08:00
|
|
|
else:
|
|
|
|
raise RuntimeError("Strange: arguments {sys.argv} were validated, but not found")
|