Skip to content

Commit

Permalink
Use tomlkit instead of toml
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Apr 4, 2023
1 parent fb92fe4 commit e507357
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ the ``xq --xml-output``/``xq -x`` option. Multiple XML documents can be passed i
TOML support
------------
``yq`` supports `TOML <https://toml.io/>`_ as well. The ``yq`` package installs an executable, ``tomlq``, which uses the
`toml library <https://github.com/uiri/toml>`_ to transcode TOML to JSON, then pipes it to ``jq``. Roundtrip transcoding
is available with the ``tomlq --toml-output``/``tomlq -t`` option.
`tomlkit library <https://github.com/sdispater/tomlkit>`_ to transcode TOML to JSON, then pipes it to ``jq``. Roundtrip
transcoding is available with the ``tomlq --toml-output``/``tomlq -t`` option.

.. admonition:: Compatibility note

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
install_requires=[
"PyYAML >= 5.3.1",
"xmltodict >= 0.11.0",
"toml >= 0.10.0",
"tomlkit >= 0.11.7",
"argcomplete >= 1.8.1",
],
extras_require={
Expand Down
12 changes: 6 additions & 6 deletions yq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ def yq(
json.dump(doc, json_buffer, cls=JSONDateTimeEncoder)
json_buffer.write("\n")
elif input_format == "toml":
import toml
import tomlkit

doc = toml.load(input_stream) # type: ignore
doc = tomlkit.load(input_stream) # type: ignore
json.dump(doc, json_buffer, cls=JSONDateTimeEncoder)
json_buffer.write("\n")
else:
Expand Down Expand Up @@ -295,13 +295,13 @@ def yq(
raise
output_stream.write(b"\n" if sys.version_info < (3, 0) else "\n")
elif output_format == "toml":
import toml
import tomlkit

for doc in decode_docs(jq_out, json_decoder):
if not isinstance(doc, dict):
msg = "{}: Error converting JSON to TOML: cannot represent non-object types at top level."
exit_func(msg.format(program_name))
toml.dump(doc, output_stream)
tomlkit.dump(doc, output_stream)
else:
if input_format == "yaml":
loader_class = get_loader(
Expand All @@ -327,10 +327,10 @@ def yq(
)
jq.stdin.write("\n") # type: ignore
elif input_format == "toml":
import toml
import tomlkit

for input_stream in input_streams:
json.dump(toml.load(input_stream), jq.stdin, cls=JSONDateTimeEncoder) # type: ignore
json.dump(tomlkit.load(input_stream), jq.stdin, cls=JSONDateTimeEncoder) # type: ignore
jq.stdin.write("\n") # type: ignore
else:
raise Exception("Unknown input format")
Expand Down

0 comments on commit e507357

Please sign in to comment.