[IMP] tests: check resource file referenced
Part-of: odoo/documentation#12074 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com> Signed-off-by: Samuel Lieber (sali) <sali@odoo.com>
This commit is contained in:
parent
faca8a4bda
commit
3f1f02200b
@ -57,6 +57,27 @@ def check_resource_file_name(file_path):
|
|||||||
'resource-file-name'
|
'resource-file-name'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def check_resource_file_referenced(file, options=None):
|
||||||
|
""" Check that resource files are referenced in at least one RST file. """
|
||||||
|
resource_file = Path(file)
|
||||||
|
resource_folder = resource_file.parent
|
||||||
|
rst_file = resource_folder.with_suffix('.rst')
|
||||||
|
if rst_file.exists():
|
||||||
|
if resource_file.name not in rst_file.read_text():
|
||||||
|
log_error(
|
||||||
|
file,
|
||||||
|
0,
|
||||||
|
f"the resource file is not referenced in {rst_file}",
|
||||||
|
"resource-file-referenced",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
log_error(
|
||||||
|
rst_file,
|
||||||
|
0,
|
||||||
|
f"resource folder name '{resource_folder.name}' does not match an rst file name.",
|
||||||
|
'resource-folder-match',
|
||||||
|
)
|
||||||
|
|
||||||
@sphinxlint.checker('')
|
@sphinxlint.checker('')
|
||||||
def check_file_extensions(file, lines, options=None):
|
def check_file_extensions(file, lines, options=None):
|
||||||
""" Check that there is no file without extension. """
|
""" Check that there is no file without extension. """
|
||||||
|
@ -18,15 +18,14 @@ CUSTOM_RST_DIRECTIVES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
ADDITIONAL_CHECKERS = [
|
ADDITIONAL_CHECKERS = [
|
||||||
checkers.resource_files.check_image_size,
|
checkers.resource_files.check_resource_file_referenced
|
||||||
checkers.resource_files.check_resource_file_name,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def run_additional_checks(argv=None):
|
def run_additional_checks(argv=None):
|
||||||
_enabled_checkers, args = sphinxlint.parse_args(argv)
|
_enabled_checkers, args = sphinxlint.parse_args(argv)
|
||||||
for path in chain.from_iterable(sphinxlint.walk(path, args.ignore) for path in args.paths):
|
for path in chain.from_iterable(sphinxlint.walk(path, args.ignore) for path in args.paths):
|
||||||
if not path.endswith('.rst'):
|
if path.startswith('content') and not path.endswith('.rst'):
|
||||||
for checker in ADDITIONAL_CHECKERS:
|
for checker in ADDITIONAL_CHECKERS:
|
||||||
checker(path)
|
checker(path)
|
||||||
|
|
||||||
@ -88,6 +87,10 @@ if __name__ == '__main__':
|
|||||||
if os.getenv('REVIEW') == '1': # Enable checkers for `make review`.
|
if os.getenv('REVIEW') == '1': # Enable checkers for `make review`.
|
||||||
setattr(sphinxlint.check_line_too_long, 'enabled', True)
|
setattr(sphinxlint.check_line_too_long, 'enabled', True)
|
||||||
setattr(checkers.rst_style.check_early_line_breaks, 'enabled', True)
|
setattr(checkers.rst_style.check_early_line_breaks, 'enabled', True)
|
||||||
ADDITIONAL_CHECKERS.extend([checkers.resource_files.check_image_color_depth])
|
ADDITIONAL_CHECKERS.extend([
|
||||||
run_additional_checks()
|
checkers.resource_files.check_image_size,
|
||||||
|
checkers.resource_files.check_image_color_depth,
|
||||||
|
checkers.resource_files.check_resource_file_name,
|
||||||
|
])
|
||||||
|
run_additional_checks()
|
||||||
sys.exit(sphinxlint.main())
|
sys.exit(sphinxlint.main())
|
||||||
|
Loading…
Reference in New Issue
Block a user