mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix for round_trip_load() YAML error, refs #2219
This commit is contained in:
parent
067cc75dfa
commit
89c8ca0f3f
1 changed files with 3 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import textwrap
|
import textwrap
|
||||||
from yaml import safe_dump
|
from yaml import safe_dump
|
||||||
from ruamel.yaml import round_trip_load
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
|
||||||
def metadata_example(cog, data=None, yaml=None):
|
def metadata_example(cog, data=None, yaml=None):
|
||||||
|
|
@ -11,8 +11,7 @@ def metadata_example(cog, data=None, yaml=None):
|
||||||
if yaml:
|
if yaml:
|
||||||
# dedent it first
|
# dedent it first
|
||||||
yaml = textwrap.dedent(yaml).strip()
|
yaml = textwrap.dedent(yaml).strip()
|
||||||
# round_trip_load to preserve key order:
|
data = YAML().load(yaml)
|
||||||
data = round_trip_load(yaml)
|
|
||||||
output_yaml = yaml
|
output_yaml = yaml
|
||||||
else:
|
else:
|
||||||
output_yaml = safe_dump(data, sort_keys=False)
|
output_yaml = safe_dump(data, sort_keys=False)
|
||||||
|
|
@ -27,8 +26,7 @@ def metadata_example(cog, data=None, yaml=None):
|
||||||
|
|
||||||
def config_example(cog, input):
|
def config_example(cog, input):
|
||||||
if type(input) is str:
|
if type(input) is str:
|
||||||
# round_trip_load to preserve key order:
|
data = YAML().load(input)
|
||||||
data = round_trip_load(input)
|
|
||||||
output_yaml = input
|
output_yaml = input
|
||||||
else:
|
else:
|
||||||
data = input
|
data = input
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue