Metadata-Version: 2.4
Name: foliantcontrib.checksources
Version: 1.0.5
Summary: Foliant preprocessor that checks the project for missing and unmentioned files.
Home-page: https://github.com/foliant-docs/foliantcontrib.checksources
Author: foliant-docs
Author-email: foliant-shared@yandex.ru
License: MIT
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Documentation
Classifier: Topic :: Utilities
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: foliant>=1.0.8
Requires-Dist: foliantcontrib.utils>=1.0.3
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: platform
Dynamic: requires-dist
Dynamic: summary

[![](https://img.shields.io/pypi/v/foliantcontrib.checksources.svg)](https://pypi.org/project/foliantcontrib.checksources/) [![](https://img.shields.io/github/v/tag/foliant-docs/foliantcontrib.checksources.svg?label=GitHub)](https://github.com/foliant-docs/foliantcontrib.checksources)

# CheckSources

CheckSources is a preprocessor that checks the project’s `chapters` for missing and unmentioned files in the sources directory.

## Installation

```bash
$ pip install foliantcontrib.checksources
```

## Usage

To enable the preprocessor, add `checksources` to `preprocessors` section in the project config:

```yaml
preprocessors:
    - checksources
```

### Options

- `not_in_chapters` –  a list of files not mentioned in the the chapters.
  No warnings will be displayed for the specified files.
  This option is useful if you don't need to add some files to the table of contents.
- `strict_check` – if a critical error is detected, the build will be failed after applying the preprocessor.
  Several checks are supported:
    - `not_exist` – checking the existence of the file.
      Checks if the file specified in chapters exists (enabled by default);
    - `duplicate` – checking for duplicate in the chapters.

  To disable strict check, use `strict_check: false`. And in order to enable all available checks, use `strict_check: true`.
- `disable_warnings` – disabling the output of warnings, just like `strict_check` supports: `not_exist` and `duplicate`.

**Example of options:**
```yaml
preprocessors:
    - checksources:
        not_in_chapters:
          - tags.md
        strict_check:
          - not_exist
        disable_warnings:
          - duplicate
```

## Integration with preprocessor Includes

All source files that are not mentioned in `chapters` or `not_in_chapters` cause warnings.

However, some files or parts of files may be included by the preprocessor [Includes](https://foliant-docs.github.io/docs/preprocessors/includes/) in other files. 
Warnings about such included files may be unnecessary. 
CheckSources can process the `includes_map.json` file generated by Includes and create a list of included files. Files from this list do not cause warnings.

To create a list of included files and avoid unnecessary warnings, enable generation of a map in the project config:

```yaml
preprocessors:
    - includes:             #includes defined before checksources
        includes_map: true
    - ...
    - checksources

```

### Included files and MultiProject
[MultiProject](https://github.com/foliant-docs/foliantcontrib.multiproject) is an extension for Foliant to generate the documentation from multiple sources.

To create a list of included files for the entire project, CheckSources can process the `multiproject_includes_map.json` file generated by the [Includesmap](https://github.com/foliant-docs/foliantcontrib.multiproject#includesmap-preprocessor) preprocessor from multiple `includes_map.json` files. If `multiproject_includes_map.json` and `includes_map.json` exist for the main project at the same time, CheckSources will use `multiproject_includes_map.json`.

To create a list of included files for the entire project, enable generation of maps in all configs and combining of maps in the config of the main project.

Config of main project:

```yaml
preprocessors:              
    - includes:             
        includes_map: true  
    - includesmap           
    - ...
    - checksources

```

Config of subproject:

```yaml
preprocessors:              
    - includes:             
        includes_map: true  
    - ...

```
