Skip to content

Commit

Permalink
Merge pull request #1 from foliant-docs/add-strict-check
Browse files Browse the repository at this point in the history
add: strict check option
  • Loading branch information
holamgadol authored Apr 8, 2024
2 parents 02319dc + 50cb1a1 commit 94e000e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ preprocessors:
- checksources
```
You can add a list of unmentioned files that wouldn't throw warnings by `not_in_chapters` option:
You can add a list of unmentioned files that wouldn't throw warnings by `not_in_chapters` option.
To perform a strict check, use the `strict_check` option:

```yaml
preprocessors:
- checksources:
not_in_chapters:
- tags.md
strict_check: true
```

It is useful if you don't need to add some files to the table of contents.
The `not_in_chapters` option is useful if you don't need to add some files to the table of contents.

If the `strict_check` option is enabled, then if a critical error is detected, the build will be aborted after applying the preprocessor.



4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.1

- Added the `strict_check` option

# 1.0.0

- Initial release
20 changes: 17 additions & 3 deletions foliant/preprocessors/checksources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import os

from foliant.preprocessors.utils.preprocessor_ext import BasePreprocessorExt
from foliant.utils import output


class Preprocessor(BasePreprocessorExt):
defaults = {
'not_in_chapters': [],
'strict_check': True,
}

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

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

def apply(self):
self.logger.info('Applying preprocessor')
Expand All @@ -43,7 +46,13 @@ def _recursive_process_chapters(chapters_subset):
self.logger.debug(f'Adding file to the list of mentioned in chapters: {chapter_file_path}')
else:
self.logger.debug('Not exist, throw warning')
self._warning(f'{os.path.relpath(chapter_file_path)} does not exist')
msg = f'{os.path.relpath(chapter_file_path)} does not exist'
if self.options['strict_check']:
self.logger.error(msg)
self.critical_error.append(msg)
output(f'ERROR: {msg}')
else:
self._warning(msg)

chapters_files_paths.append(chapter_file_path)

Expand Down Expand Up @@ -82,5 +91,10 @@ def _fill_not_in_chapters():
else:
self.logger.debug('Not mentioned, throw warning')
self._warning(f'{os.path.relpath(markdown_file_path)} does not mentioned in chapters')

self.logger.info('Preprocessor applied')
if len(self.critical_error) > 0:
self.logger.info('Critical errors have occurred')
errors = '\n'.join(self.critical_error)
output(f'\nBuild failed: checksources preprocessor errors: \n{errors}\n')
os._exit(2)
else:
self.logger.info('Preprocessor applied')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
description=SHORT_DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',
version='1.0.0',
version='1.0.1',
url='https://github.com/foliant-docs/foliantcontrib.checksources',
packages=['foliant.preprocessors'],
author='foliant-docs',
Expand Down

0 comments on commit 94e000e

Please sign in to comment.