-
Notifications
You must be signed in to change notification settings - Fork 5.3k
WIP: Validating config in docs #11394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
97e003b
Validation of configuration examples in docs
4975c02
Merge remote-tracking branch 'upstream' into validating-config-in-docs
906ff63
Responded to feedback
6b92ccb
Improved error reporting
204428d
Fixed rendering of BAZEL_BUILD_OPTIONS during bazel command generation
382c36d
Responded to feedback
c7bdb31
Fixed formatting
881e654
Dcoumented SPHINX_SKIP_CONFIG_VALIDATION env var
2bbe15c
Merge remote-tracking branch 'upstream' into validating-config-in-docs
0f0446b
Fixed build failure
071de20
Fixed formatting issues
ee0ef1d
Fixed format
3312681
Merge remote-tracking branch 'upstream' into validating-config-in-docs
77b7b75
Merge remote-tracking branch 'upstream' into validating-config-in-docs
4f0aecd
Switched to argparse in validate_fragment.py
1fb3282
Fixed format
8619b7a
Merge remote-tracking branch 'upstream' into validating-config-in-docs
6c13087
Responded to feedback
a60d3ff
Fixed build failure
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,62 @@ | ||
| from typing import List | ||
| from docutils import nodes | ||
| from docutils.parsers.rst import Directive | ||
| from docutils.parsers.rst import directives | ||
| from sphinx.application import Sphinx | ||
| from sphinx.util.docutils import SphinxDirective | ||
| from sphinx.directives.code import CodeBlock | ||
| from sphinx.errors import ExtensionError | ||
|
|
||
| import os | ||
| import subprocess | ||
|
|
||
|
|
||
| class ValidatingCodeBlock(CodeBlock): | ||
| """A directive that provides protobuf yaml formatting and validation. | ||
|
|
||
| 'type-name' option is required and expected to conain full Envoy API type. | ||
| An ExtensionError is raised on validation failure. | ||
| Validation will be skipped if SPHINX_SKIP_CONFIG_VALIDATION environment variable is set. | ||
| """ | ||
| has_content = True | ||
| required_arguments = CodeBlock.required_arguments | ||
| optional_arguments = CodeBlock.optional_arguments | ||
| final_argument_whitespace = CodeBlock.final_argument_whitespace | ||
| option_spec = { | ||
| 'type-name': directives.unchanged, | ||
| } | ||
| option_spec.update(CodeBlock.option_spec) | ||
| skip_validation = (os.getenv('SPHINX_SKIP_CONFIG_VALIDATION') or 'false').lower() == 'true' | ||
|
|
||
| def run(self): | ||
| source, line = self.state_machine.get_source_and_line(self.lineno) | ||
| # built-in directives.unchanged_required option validator produces a confusing error message | ||
| if self.options.get('type-name') == None: | ||
| raise ExtensionError("Expected type name in: {0} line: {1}".format(source, line)) | ||
|
|
||
| if not ValidatingCodeBlock.skip_validation: | ||
| args = [ | ||
| 'bazel-bin/tools/config_validation/validate_fragment', | ||
| self.options.get('type-name'), '-s', '\n'.join(self.content) | ||
| ] | ||
| completed = subprocess.run(args, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| encoding='utf-8') | ||
| if completed.returncode != 0: | ||
| raise ExtensionError( | ||
| "Failed config validation for type: '{0}' in: {1} line: {2}:\n {3}".format( | ||
| self.options.get('type-name'), source, line, completed.stderr)) | ||
|
|
||
| self.options.pop('type-name', None) | ||
| return list(CodeBlock.run(self)) | ||
|
|
||
|
|
||
| def setup(app): | ||
| app.add_directive("validated-code-block", ValidatingCodeBlock) | ||
|
|
||
| return { | ||
| 'version': '0.1', | ||
| 'parallel_read_safe': True, | ||
| 'parallel_write_safe': True, | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.