Skip to content

Commit 94e000e

Browse files
authored
Merge pull request #1 from foliant-docs/add-strict-check
add: strict check option
2 parents 02319dc + 50cb1a1 commit 94e000e

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ preprocessors:
1919
- checksources
2020
```
2121
22-
You can add a list of unmentioned files that wouldn't throw warnings by `not_in_chapters` option:
22+
You can add a list of unmentioned files that wouldn't throw warnings by `not_in_chapters` option.
23+
To perform a strict check, use the `strict_check` option:
2324

2425
```yaml
2526
preprocessors:
2627
- checksources:
2728
not_in_chapters:
2829
- tags.md
30+
strict_check: true
2931
```
3032

31-
It is useful if you don't need to add some files to the table of contents.
33+
The `not_in_chapters` option is useful if you don't need to add some files to the table of contents.
34+
35+
If the `strict_check` option is enabled, then if a critical error is detected, the build will be aborted after applying the preprocessor.
36+
3237

3338

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.1
2+
3+
- Added the `strict_check` option
4+
15
# 1.0.0
26

37
- Initial release

foliant/preprocessors/checksources.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import os
77

88
from foliant.preprocessors.utils.preprocessor_ext import BasePreprocessorExt
9+
from foliant.utils import output
910

1011

1112
class Preprocessor(BasePreprocessorExt):
1213
defaults = {
1314
'not_in_chapters': [],
15+
'strict_check': True,
1416
}
1517

1618
def __init__(self, *args, **kwargs):
@@ -20,6 +22,7 @@ def __init__(self, *args, **kwargs):
2022

2123
self.logger.debug(f'Preprocessor inited: {self.__dict__}')
2224
self.src_dir = self.project_path / self.config['src_dir']
25+
self.critical_error = []
2326

2427
def apply(self):
2528
self.logger.info('Applying preprocessor')
@@ -43,7 +46,13 @@ def _recursive_process_chapters(chapters_subset):
4346
self.logger.debug(f'Adding file to the list of mentioned in chapters: {chapter_file_path}')
4447
else:
4548
self.logger.debug('Not exist, throw warning')
46-
self._warning(f'{os.path.relpath(chapter_file_path)} does not exist')
49+
msg = f'{os.path.relpath(chapter_file_path)} does not exist'
50+
if self.options['strict_check']:
51+
self.logger.error(msg)
52+
self.critical_error.append(msg)
53+
output(f'ERROR: {msg}')
54+
else:
55+
self._warning(msg)
4756

4857
chapters_files_paths.append(chapter_file_path)
4958

@@ -82,5 +91,10 @@ def _fill_not_in_chapters():
8291
else:
8392
self.logger.debug('Not mentioned, throw warning')
8493
self._warning(f'{os.path.relpath(markdown_file_path)} does not mentioned in chapters')
85-
86-
self.logger.info('Preprocessor applied')
94+
if len(self.critical_error) > 0:
95+
self.logger.info('Critical errors have occurred')
96+
errors = '\n'.join(self.critical_error)
97+
output(f'\nBuild failed: checksources preprocessor errors: \n{errors}\n')
98+
os._exit(2)
99+
else:
100+
self.logger.info('Preprocessor applied')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
description=SHORT_DESCRIPTION,
1717
long_description=LONG_DESCRIPTION,
1818
long_description_content_type='text/markdown',
19-
version='1.0.0',
19+
version='1.0.1',
2020
url='https://github.com/foliant-docs/foliantcontrib.checksources',
2121
packages=['foliant.preprocessors'],
2222
author='foliant-docs',

0 commit comments

Comments
 (0)