-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Devops: Add pre-commit hook that validates optional dependencies
The `dev/validate_optional_dependencies.py` is added. It validates that the `all_plugins` extras specifies exactly the same dependency requirements that all other extras combined declare as well, except for the `docs`, `pre-commit`, and `tests` extras, which are only used for development. This is to ensure that the `all_plugins` extras provides the exact same dependencies as all the plugin specific extras combined. The script is called through a pre-commit hook.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
"""Script to validate the optional dependencies in the `pyproject.toml`.""" | ||
|
||
|
||
def main(): | ||
"""Validate the optional dependencies.""" | ||
import pathlib | ||
import sys | ||
|
||
import tomllib | ||
|
||
filepath_pyproject_toml = pathlib.Path(__file__).parent.parent / 'pyproject.toml' | ||
|
||
with filepath_pyproject_toml.open('rb') as handle: | ||
pyproject = tomllib.load(handle) | ||
|
||
exclude = ['all_plugins', 'docs', 'pre-commit', 'tests'] | ||
dependencies_all_plugins = pyproject['project']['optional-dependencies']['all_plugins'] | ||
dependencies_separate = [] | ||
|
||
for key, dependencies in pyproject['project']['optional-dependencies'].items(): | ||
if key in exclude: | ||
continue | ||
dependencies_separate.extend(dependencies) | ||
|
||
missing_all_plugins = set(dependencies_separate).difference(set(dependencies_all_plugins)) | ||
excess_all_plugins = set(dependencies_all_plugins).difference(set(dependencies_separate)) | ||
|
||
if missing_all_plugins: | ||
print( | ||
'ERROR: the `all_plugins` extras are inconsistent. The following plugin dependencies are missing: ' | ||
f'{", ".join(missing_all_plugins)}', | ||
file=sys.stderr, | ||
) | ||
sys.exit(1) | ||
|
||
if excess_all_plugins: | ||
print( | ||
'ERROR: the `all_plugins` extras are inconsistent. The following dependencies are not declared by any ' | ||
f'plugin extras: {", ".join(excess_all_plugins)}', | ||
file=sys.stderr, | ||
) | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |