-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Parameter migration: code cleanup, migration script, and land_detector trial #19489
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
Open
coderkalyan
wants to merge
15
commits into
PX4:main
Choose a base branch
from
coderkalyan:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
108602b
tools/validate_yaml: code cleanup
coderkalyan 1292fdc
tools/validation: allow json with cerberus for future migration
coderkalyan 179255b
parameters: srcparser code cleanup
coderkalyan 9e9a087
land_detector: migrate c parameter definitions to yaml
coderkalyan 935d277
src/modules: parameter format migration (WIP)
coderkalyan 0817791
tools: add migrate_c_params helper script
coderkalyan 7358465
tools/generate_params: fix boolean property bug
coderkalyan 4b6179f
modules: migrate all modules to yaml parameter definitions
coderkalyan a5ffbe7
drivers: migrate all drivers to yaml parameter definitions
coderkalyan dfbb110
python/pip: add requirements.txt
coderkalyan 5cad5c2
validation: add new units and increase short description length
coderkalyan 22ff3b3
ci: temporarily add dataclasses dependency
coderkalyan 7fe65c6
battery: capitalize parameter category
coderkalyan 066ac8a
tools/generate_config: fix empty default value bug
coderkalyan ed941e7
parameters: update injected parameter descriptions
coderkalyan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #! /usr/bin/env python3 | ||
| """ Script to validate YAML file(s) against a YAML schema file """ | ||
|
|
||
| import argparse | ||
| import logging | ||
| import pprint | ||
| import sys | ||
| import os | ||
|
|
||
| try: | ||
| import yaml | ||
| except ImportError as e: | ||
| print("Failed to import yaml: " + str(e)) | ||
| print("") | ||
| print("You may need to install it using:") | ||
| print(" pip3 install --user pyyaml") | ||
| print("") | ||
| sys.exit(1) | ||
|
|
||
| try: | ||
| import cerberus | ||
| except ImportError as e: | ||
| print("Failed to import cerberus: " + str(e)) | ||
| print("") | ||
| print("You may need to install it using:") | ||
| print(" pip3 install --user cerberus") | ||
| print("") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def load_data_file(file_name: str): | ||
| with open(file_name) as stream: | ||
| try: | ||
| return yaml.safe_load(stream) | ||
| except: | ||
| raise Exception("Unable to parse schema file: syntax error or unsupported file format") | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description='Validate YAML or JSON file(s) against a schema') | ||
|
|
||
| parser.add_argument('data_file', nargs='+', help='data file(s)') | ||
| parser.add_argument('--schema-file', type=str, action='store', | ||
| help='schema file', required=True) | ||
| parser.add_argument('--skip-if-no-schema', dest='skip_if_no_schema', | ||
| action='store_true', | ||
| help='Skip test if schema file does not exist') | ||
| parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', | ||
| help='Verbose Output') | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| data_files = args.data_file | ||
| schema_file = args.schema_file | ||
|
|
||
| if args.verbose: | ||
| logging.basicConfig(level=logging.INFO) | ||
| else: | ||
| logging.basicConfig(level=logging.ERROR) | ||
|
|
||
| if args.skip_if_no_schema and not os.path.isfile(schema_file): | ||
| logging.info(f"Schema file {schema_file} not found, skipping") | ||
| sys.exit(0) | ||
|
|
||
| # load the schema | ||
| schema = load_data_file(schema_file) | ||
| validator = cerberus.Validator(schema, allow_unknown=False) | ||
|
|
||
| # validate the specified data files | ||
| for data_file in data_files: | ||
| logging.info(f"Validating {data_file}") | ||
|
|
||
| document = load_data_file(data_file) | ||
|
|
||
| # ignore top-level entries prefixed with __ for yaml module definitions | ||
| for key in list(document.keys()): | ||
| if key.startswith('__'): | ||
| del document[key] | ||
|
|
||
| if not validator.validate(document): | ||
| logging.error(f"Found validation errors with {data_file}:") | ||
| logging.error(pprint.pformat(validator.errors)) | ||
|
|
||
| raise Exception("Validation of {:} failed".format(data_file)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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 was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is json being handled?