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

load_configuration does not support JSON files with tab whitespace because of ruamel loader #1999

Closed
ghost opened this issue Jun 23, 2021 · 0 comments
Labels
bug Indicates an unexpected problem or unintended behavior component: core
Milestone

Comments

@ghost
Copy link

ghost commented Jun 23, 2021

For the switch to YAML in configuration files, we switched to the ruamel.yaml loader, which supports JSON and YAML:

def load_configuration(configuration_filepath: str) -> dict:
"""
Load JSON or YAML configuration file.
Parameters:
configuration_filepath: Path to file to load.
Returns:
config: Parsed configuration
Raises:
ValueError: if file not found
"""
if os.path.exists(configuration_filepath):
with open(configuration_filepath, 'r') as fpconfig:
config = yaml.load(fpconfig)

However, ruamel does not support JSON files with tabs as whitespace, because YAML does not support tabs. As this routine is used to load various JSON files, which can be formatted howsoever the user formatted them, we need to support JSON with tabs.

As a workaround, we could catch this specific exception and fallback to the JSON loader.
Or we use a parameter to the routine like we have it for the write equivalent:

def write_configuration(configuration_filepath: str,
content: dict, backup: bool = True,
new=False, useyaml=True) -> Optional[bool]:

@ghost ghost added bug Indicates an unexpected problem or unintended behavior component: core labels Jun 23, 2021
@ghost ghost added this to the 3.0.0 milestone Jun 23, 2021
ghost pushed a commit that referenced this issue Jun 30, 2021
ruamel can't load JSON files with tabs as whitespace
if this specific excpetion is thrown, try loading the file with
json.load instead

this adds some tests for the load_configuration function
with JSON files and YAML file

fixes #1999
@ghost ghost closed this as completed in 03fdd24 Jun 30, 2021
waldbauer-certat pushed a commit that referenced this issue Aug 16, 2021
ruamel can't load JSON files with tabs as whitespace
if this specific excpetion is thrown, try loading the file with
json.load instead

this adds some tests for the load_configuration function
with JSON files and YAML file

fixes #1999
waldbauer-certat pushed a commit that referenced this issue Sep 9, 2021
ruamel can't load JSON files with tabs as whitespace
if this specific excpetion is thrown, try loading the file with
json.load instead

this adds some tests for the load_configuration function
with JSON files and YAML file

fixes #1999
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior component: core
Projects
None yet
Development

No branches or pull requests

0 participants