py-libp2p/newsfragments/validate_files.py

44 lines
1.1 KiB
Python
Raw Normal View History

#!/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
ALLOWED_EXTENSIONS = {
'.bugfix.rst',
'.doc.rst',
'.feature.rst',
2019-11-26 04:28:05 +08:00
'.internal.rst',
'.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', )
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':
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")