Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ repos:
[
types-PyYAML,
types-requests,
types-toml,
]
verbose: true

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Changed
- The ``yaml`` dump format now writes multi-line strings as literal blocks, i.e.
``|``, instead of escaping the line breaks (`#972
<https://github.com/mauvilsa/jsonargparse/pull/972>`__).
- The ``toml`` extra now installs the maintained ``tomli-w`` for writing and
``tomli`` for reading in python 3.10, instead of the unmaintained ``toml``
package. Dumped toml arrays are now multi-line (`#973
<https://github.com/mauvilsa/jsonargparse/pull/973>`__).

Removed
^^^^^^^
Expand Down
16 changes: 8 additions & 8 deletions jsonargparse/_optionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from typing import Any, Union

pyyaml_available = bool(find_spec("yaml"))
toml_load_available = bool(find_spec("toml") or find_spec("tomllib"))
toml_dump_available = bool(find_spec("toml"))
toml_load_available = bool(find_spec("tomllib") or find_spec("tomli"))
toml_dump_available = bool(find_spec("tomli_w"))
typing_extensions_support = find_spec("typing_extensions") is not None
typeshed_client_support = find_spec("typeshed_client") is not None
jsonschema_support = find_spec("jsonschema") is not None
Expand Down Expand Up @@ -113,16 +113,16 @@ def import_toml_loads(importer):

return tomllib.loads, tomllib.TOMLDecodeError
else:
with missing_package_raise("toml", importer):
import toml
with missing_package_raise("tomli", importer):
import tomli

return toml.loads, toml.TomlDecodeError
return tomli.loads, tomli.TOMLDecodeError


def import_toml_dumps(importer):
with missing_package_raise("toml", importer):
import toml
return toml.dumps
with missing_package_raise("tomli-w", importer):
import tomli_w
return tomli_w.dumps


def import_jsonschema(importer):
Expand Down
9 changes: 6 additions & 3 deletions jsonargparse_tests/test_loaders_dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,14 @@ def test_nested_parser_mode(parser):

[group]
child1 = 1.2
child2 = [ 3.0, 4.5,]
child2 = [
3.0,
4.5,
]
"""


@pytest.mark.skipif(not toml_load_available, reason="tomllib or toml package is required")
@pytest.mark.skipif(not toml_load_available, reason="tomllib or tomli package is required")
def test_toml_parse_args_config(parser, tmp_cwd):
parser.parser_mode = "toml"
config_path = Path("config.toml")
Expand All @@ -212,7 +215,7 @@ def test_toml_parse_args_config(parser, tmp_cwd):
assert cfg.group.as_dict() == {"child1": 1.2, "child2": [3.0, 4.5]}


@pytest.mark.skipif(not toml_dump_available, reason="toml package is required")
@pytest.mark.skipif(not toml_dump_available, reason="tomli-w package is required")
def test_toml_print_config(parser):
parser.parser_mode = "toml"
parser.add_argument("--config", action="config")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ yaml = [
"PyYAML>=3.13",
]
toml = [
"toml>=0.10.2",
"tomli>=2.0.1; python_version < '3.11'",
"tomli-w>=1.0.0",
]
jsonnet = [
"jsonnet>=0.21.0",
Expand Down