2018-06-05 03:07:14 +02:00
|
|
|
#!/usr/bin/env python
|
2019-07-12 08:46:20 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2018-06-05 03:07:14 +02:00
|
|
|
|
2019-03-09 06:05:25 +01:00
|
|
|
import os
|
2018-06-05 03:07:14 +02:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
paths = sys.argv[1:] or sys.stdin.read().splitlines()
|
2019-03-09 06:05:25 +01:00
|
|
|
|
|
|
|
allowed_extensions = ('.yml', '.yaml')
|
2020-06-11 20:40:07 +02:00
|
|
|
config_path = 'changelogs/config.yaml'
|
2019-03-09 06:05:25 +01:00
|
|
|
|
2020-06-11 20:40:07 +02:00
|
|
|
# config must be detected independent of the file list since the file list only contains files under test (changed)
|
|
|
|
has_config = os.path.exists(config_path)
|
2020-06-11 20:21:21 +02:00
|
|
|
paths_to_check = []
|
2019-03-09 06:05:25 +01:00
|
|
|
for path in paths:
|
2020-06-11 20:40:07 +02:00
|
|
|
if path == config_path:
|
2020-06-11 20:21:21 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if path.startswith('changelogs/fragments/.'):
|
2020-08-06 17:49:39 +02:00
|
|
|
if path in ('changelogs/fragments/.keep', 'changelogs/fragments/.gitkeep'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
print('%s:%d:%d: file must not be a dotfile' % (path, 0, 0))
|
2020-06-11 20:21:21 +02:00
|
|
|
continue
|
|
|
|
|
2019-03-09 06:05:25 +01:00
|
|
|
ext = os.path.splitext(path)[1]
|
|
|
|
|
|
|
|
if ext not in allowed_extensions:
|
|
|
|
print('%s:%d:%d: extension must be one of: %s' % (path, 0, 0, ', '.join(allowed_extensions)))
|
|
|
|
|
2020-06-11 20:21:21 +02:00
|
|
|
paths_to_check.append(path)
|
|
|
|
|
|
|
|
if not has_config:
|
|
|
|
print('changelogs/config.yaml:0:0: config file does not exist')
|
|
|
|
return
|
|
|
|
|
|
|
|
if not paths_to_check:
|
|
|
|
return
|
|
|
|
|
|
|
|
cmd = [sys.executable, '-m', 'antsibull_changelog', 'lint'] + paths_to_check
|
2021-01-28 07:42:59 +01:00
|
|
|
|
|
|
|
# The sphinx module is a soft dependency for rstcheck, which is used by the changelog linter.
|
|
|
|
# If sphinx is found it will be loaded by rstcheck, which can affect the results of the test.
|
|
|
|
# To maintain consistency across environments, loading of sphinx is blocked, since any version (or no version) of sphinx may be present.
|
|
|
|
env = os.environ.copy()
|
|
|
|
env.update(PYTHONPATH='%s:%s' % (os.path.join(os.path.dirname(__file__), 'changelog'), env['PYTHONPATH']))
|
|
|
|
|
|
|
|
subprocess.call(cmd, env=env) # ignore the return code, rely on the output instead
|
2018-06-05 03:07:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|