Skip to content
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

[config-system] Validator rewrite: Use jsonschema #576

Merged
merged 17 commits into from
Jun 2, 2016

Conversation

ftsamis
Copy link
Member

@ftsamis ftsamis commented May 31, 2016

Note: Tests for the validator are not yet implemented

With this PR I rewrite the io.config_validator which was a custom-built validator written specifically for TARDIS. With the changes I made, the validator now uses jsonschema, a well-known and broadly-used validation module which validates schemas according to the json-schema specification.

For this purpose the configuration definition needed to be transcoded in json schema syntax, which was done at #549.

All currently used types are supported by this validator, as well as setting default values.

montecarlo_section['virtual_spectrum_range']['samples'] = \
virtual_spectrum_section[2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason we keep this?
I propose to delete lines 1031-1046 and rename montecarlo.virtual_spectrum_range.samples to montecarlo.virtual_spectrum_range.num wherever it is accessed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the next and final big milestone/PR (configuration system restructure). My purpose in this PR was to only do changes related and absolutely necessary to the validator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yeganer that's dangerous as older configuration files need to work. I would flag it but leave it for now.

Copy link
Contributor

@yeganer yeganer Jun 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have a function/module that provides the backwards compatibility.

if config.version < latest_config_version:
    config_dict = interpret_legacy_config(config_dict)

This function would then consecutively update from the config version the config is in to the latest verstion.

@@ -486,7 +487,9 @@ def parse_spectrum_list2dict(spectrum_list):
"""
Parse the spectrum list [start, stop, num] to a list
"""

if isinstance(spectrum_list, dict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about we change to 'if 'start' in spectrum_list and 'stop' in spectrum list and 'num' in spectrum_list`: 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting a comment on this line.
I even thought about adding a "Dear Wolfgang, this is as temporary as it can get, please act like you didn't notice the missing ducks" comment. 😛

I'll do the change...

@@ -487,7 +487,8 @@ def parse_spectrum_list2dict(spectrum_list):
"""
Parse the spectrum list [start, stop, num] to a list
"""
if isinstance(spectrum_list, dict):
if 'start' in spectrum_list and 'stop' in spectrum_list \
and 'num' in spectrum_list:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks complicated, why not try/except?

@@ -27,7 +27,6 @@

default_config_definition_file = os.path.join(data_dir,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, removed all the references to tardis_config_definition.yml and the file itself.

@wkerzendorf wkerzendorf merged commit 6ab52cf into tardis-sn:master Jun 2, 2016
@ftsamis ftsamis deleted the jsonschema-validator branch December 20, 2016 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants