Skip to content

Commit e3d3b96

Browse files
authored
Replaced unmaintained optional dependency ruyaml with ruamel.yaml (#768)
1 parent d714478 commit e3d3b96

File tree

14 files changed

+68
-60
lines changed

14 files changed

+68
-60
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ Changed
4949
- ``YAML`` comments feature is now implemented in a separate class to allow
5050
better support for custom help formatters without breaking the comments (`#754
5151
<https://github.com/omni-us/jsonargparse/pull/754>`__).
52+
- Replaced unmaintained optional dependency ``ruyaml`` with ``ruamel.yaml``
53+
(`#768 <https://github.com/omni-us/jsonargparse/pull/768>`__).
5254

5355
Deprecated
5456
^^^^^^^^^^
5557
- ``DefaultHelpFormatter.*_yaml*_comment*`` methods are deprecated and will be
5658
removed in v5.0.0. This logic has been moved to a new private class
5759
``YAMLCommentFormatter``. If deemed necessary, this class might be made public
5860
in the future (`#754 <https://github.com/omni-us/jsonargparse/pull/754>`__).
61+
- The ``ruyaml`` optional dependency is deprecated and will be removed in
62+
v5.0.0. Instead use the ``ruamel`` optional dependency (`#768
63+
<https://github.com/omni-us/jsonargparse/pull/768>`__).
5964

6065

6166
v4.40.2 (2025-08-06)

DOCUMENTATION.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,9 +1321,9 @@ Serialization
13211321
Parsers that have an `action="config"` argument also include a
13221322
``--print_config`` option. This is useful particularly for command line tools
13231323
with a large set of options to create an initial config file including all
1324-
default values. If the `ruyaml <https://ruyaml.readthedocs.io>`__ package is
1325-
installed, the config can be printed having the help descriptions content as
1326-
YAML comments by using ``--print_config=comments``. Another option is
1324+
default values. If the `ruamel.yaml <https://pypi.org/project/ruamel.yaml>`__
1325+
package is installed, the config can be printed having the help descriptions
1326+
content as YAML comments by using ``--print_config=comments``. Another option is
13271327
``--print_config=skip_null`` which skips entries whose value is ``null``.
13281328

13291329
From within Python it is also possible to serialize a config object by using

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ By default, the only dependency installed with ``jsonargparse`` is `PyYAML
183183
<https://pypi.org/project/PyYAML/>`__. However, several optional features can be
184184
enabled by specifying one or more of the following extras (optional
185185
dependencies): ``signatures``, ``jsonschema``, ``jsonnet``, ``urls``,
186-
``fsspec``, ``toml``, ``ruyaml``, ``omegaconf``, ``shtab``, and ``argcomplete``.
186+
``fsspec``, ``toml``, ``ruamel``, ``omegaconf``, ``shtab``, and ``argcomplete``.
187187
Additionally, the ``all`` extras can be used to enable all optional features
188188
(excluding tab completion ones). To install ``jsonargparse`` with extras, use
189189
the following syntax:

jsonargparse/_actions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ._common import Action, is_subclass, parser_context
1313
from ._loaders_dumpers import get_loader_exceptions, load_value
1414
from ._namespace import Namespace, NSKeyError, split_key, split_key_root
15-
from ._optionals import _get_config_read_mode, ruyaml_support
15+
from ._optionals import _get_config_read_mode, ruamel_support
1616
from ._type_checking import ActionsContainer, ArgumentParser
1717
from ._util import (
1818
Path,
@@ -254,13 +254,13 @@ def __init__(
254254
"flags customizes the output and are one or more keywords separated by comma. The "
255255
"supported flags are:%s skip_default, skip_null."
256256
)
257-
% (" comments," if ruyaml_support else ""),
257+
% (" comments," if ruamel_support else ""),
258258
)
259259

260260
def __call__(self, parser, namespace, value, option_string=None):
261261
kwargs = {"subparser": parser, "key": None, "skip_none": False, "skip_validation": False}
262262
valid_flags = {"": None, "skip_default": "skip_default", "skip_null": "skip_none"}
263-
if ruyaml_support:
263+
if ruamel_support:
264264
valid_flags["comments"] = "yaml_comments"
265265
if value is not None:
266266
flags = value[0].split(",")

jsonargparse/_deprecated.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ._common import Action, null_logger
1515
from ._common import LoggerProperty as InternalLoggerProperty
1616
from ._namespace import Namespace
17-
from ._type_checking import ArgumentParser, ruyamlCommentedMap
17+
from ._type_checking import ArgumentParser, ruamelCommentedMap
1818

1919
__all__ = [
2020
"ActionEnum",
@@ -711,34 +711,34 @@ def add_yaml_comments(self, cfg: str) -> str:
711711
return self._yaml_formatter.add_yaml_comments(cfg)
712712

713713
@deprecated("The set_yaml_start_comment method is deprecated and will be removed in v5.0.0.")
714-
def set_yaml_start_comment(self, text: str, cfg: ruyamlCommentedMap):
715-
"""Sets the start comment to a ruyaml object.
714+
def set_yaml_start_comment(self, text: str, cfg: ruamelCommentedMap):
715+
"""Sets the start comment to a ruamel.yaml object.
716716
717717
Args:
718718
text: The content to use for the comment.
719-
cfg: The ruyaml object.
719+
cfg: The ruamel.yaml object.
720720
"""
721721
self._yaml_formatter.set_yaml_start_comment(text, cfg)
722722

723723
@deprecated("The set_yaml_group_comment method is deprecated and will be removed in v5.0.0.")
724-
def set_yaml_group_comment(self, text: str, cfg: ruyamlCommentedMap, key: str, depth: int):
725-
"""Sets the comment for a group to a ruyaml object.
724+
def set_yaml_group_comment(self, text: str, cfg: ruamelCommentedMap, key: str, depth: int):
725+
"""Sets the comment for a group to a ruamel.yaml object.
726726
727727
Args:
728728
text: The content to use for the comment.
729-
cfg: The parent ruyaml object.
729+
cfg: The parent ruamel.yaml object.
730730
key: The key of the group.
731731
depth: The nested level of the group.
732732
"""
733733
self._yaml_formatter.set_yaml_group_comment(text, cfg, key, depth)
734734

735735
@deprecated("The set_yaml_argument_comment method is deprecated and will be removed in v5.0.0.")
736-
def set_yaml_argument_comment(self, text: str, cfg: ruyamlCommentedMap, key: str, depth: int):
737-
"""Sets the comment for an argument to a ruyaml object.
736+
def set_yaml_argument_comment(self, text: str, cfg: ruamelCommentedMap, key: str, depth: int):
737+
"""Sets the comment for an argument to a ruamel.yaml object.
738738
739739
Args:
740740
text: The content to use for the comment.
741-
cfg: The parent ruyaml object.
741+
cfg: The parent ruamel.yaml object.
742742
key: The key of the argument.
743743
depth: The nested level of the argument.
744744
"""

jsonargparse/_formatters.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
from ._deprecated import HelpFormatterDeprecations
3434
from ._link_arguments import ActionLink
3535
from ._namespace import Namespace, NSKeyError
36-
from ._optionals import import_ruyaml
37-
from ._type_checking import ArgumentParser, ruyamlCommentedMap
36+
from ._optionals import import_ruamel
37+
from ._type_checking import ArgumentParser, ruamelCommentedMap
3838
from ._typehints import ActionTypeHint, type_to_str
3939

4040
__all__ = ["DefaultHelpFormatter"]
@@ -63,7 +63,7 @@ def __init__(self, help_formatter: HelpFormatter):
6363

6464
def add_yaml_comments(self, cfg: str) -> str:
6565
"""Adds help text as yaml comments."""
66-
ruyaml = import_ruyaml("add_yaml_comments")
66+
ruyaml = import_ruamel("add_yaml_comments")
6767
yaml = ruyaml.YAML()
6868
cfg = yaml.load(cfg)
6969

@@ -119,28 +119,28 @@ def set_comments(cfg, prefix="", depth=0):
119119
def set_yaml_start_comment(
120120
self,
121121
text: str,
122-
cfg: ruyamlCommentedMap,
122+
cfg: ruamelCommentedMap,
123123
):
124-
"""Sets the start comment to a ruyaml object.
124+
"""Sets the start comment to a ruamel.yaml object.
125125
126126
Args:
127127
text: The content to use for the comment.
128-
cfg: The ruyaml object.
128+
cfg: The ruamel.yaml object.
129129
"""
130130
cfg.yaml_set_start_comment(text)
131131

132132
def set_yaml_group_comment(
133133
self,
134134
text: str,
135-
cfg: ruyamlCommentedMap,
135+
cfg: ruamelCommentedMap,
136136
key: str,
137137
depth: int,
138138
):
139-
"""Sets the comment for a group to a ruyaml object.
139+
"""Sets the comment for a group to a ruamel.yaml object.
140140
141141
Args:
142142
text: The content to use for the comment.
143-
cfg: The parent ruyaml object.
143+
cfg: The parent ruamel.yaml object.
144144
key: The key of the group.
145145
depth: The nested level of the group.
146146
"""
@@ -149,15 +149,15 @@ def set_yaml_group_comment(
149149
def set_yaml_argument_comment(
150150
self,
151151
text: str,
152-
cfg: ruyamlCommentedMap,
152+
cfg: ruamelCommentedMap,
153153
key: str,
154154
depth: int,
155155
):
156-
"""Sets the comment for an argument to a ruyaml object.
156+
"""Sets the comment for an argument to a ruamel.yaml object.
157157
158158
Args:
159159
text: The content to use for the comment.
160-
cfg: The parent ruyaml object.
160+
cfg: The parent ruamel.yaml object.
161161
key: The key of the argument.
162162
depth: The nested level of the argument.
163163
"""

jsonargparse/_loaders_dumpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import_toml_loads,
1414
omegaconf_support,
1515
pyyaml_available,
16-
ruyaml_support,
16+
ruamel_support,
1717
)
1818
from ._type_checking import ArgumentParser
1919

@@ -263,7 +263,7 @@ def toml_dump(data):
263263
"toml": toml_dump,
264264
"jsonnet": json_indented_dump,
265265
}
266-
if ruyaml_support:
266+
if ruamel_support:
267267
dumpers["yaml_comments"] = yaml_comments_dump
268268

269269
comment_prefix: Dict[str, str] = {

jsonargparse/_optionals.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
url_support = find_spec("requests") is not None
2323
docstring_parser_support = find_spec("docstring_parser") is not None
2424
fsspec_support = find_spec("fsspec") is not None
25-
ruyaml_support = find_spec("ruyaml") is not None
25+
ruamel_support = bool(find_spec("ruamel") and find_spec("ruamel.yaml"))
2626
omegaconf_support = find_spec("omegaconf") is not None
2727
reconplogger_support = find_spec("reconplogger") is not None
2828
attrs_support = find_spec("attrs") is not None
@@ -152,10 +152,10 @@ def import_fsspec(importer):
152152
return fsspec
153153

154154

155-
def import_ruyaml(importer):
156-
with missing_package_raise("ruyaml", importer):
157-
import ruyaml
158-
return ruyaml
155+
def import_ruamel(importer):
156+
with missing_package_raise("ruamel.yaml", importer):
157+
import ruamel.yaml
158+
return ruamel.yaml
159159

160160

161161
def import_reconplogger(importer):

jsonargparse/_type_checking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"ActionsContainer",
66
"ArgumentParser",
77
"docstring_parser",
8-
"ruyamlCommentedMap",
8+
"ruamelCommentedMap",
99
]
1010

1111
if TYPE_CHECKING: # pragma: no cover
1212
import docstring_parser
13-
from ruyaml.comments import CommentedMap as ruyamlCommentedMap
13+
from ruamel.yaml.comments import CommentedMap as ruamelCommentedMap
1414

1515
from ._core import ActionsContainer, ArgumentGroup, ArgumentParser
1616
else:

jsonargparse_tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from jsonargparse import CLI, auto_cli, auto_parser, capture_parser, lazy_instance
1919
from jsonargparse._namespace import Namespace
20-
from jsonargparse._optionals import docstring_parser_support, ruyaml_support
20+
from jsonargparse._optionals import docstring_parser_support, ruamel_support
2121
from jsonargparse.typing import final
2222
from jsonargparse_tests.conftest import json_or_yaml_dump, json_or_yaml_load, skip_if_docstring_parser_unavailable
2323

@@ -351,7 +351,7 @@ def test_function_and_class_print_config_before_subcommands():
351351

352352

353353
@skip_if_docstring_parser_unavailable
354-
@pytest.mark.skipif(not ruyaml_support, reason="ruyaml not installed")
354+
@pytest.mark.skipif(not ruamel_support, reason="ruamel.yaml package is required")
355355
def test_function_and_class_print_config_comments():
356356
out = get_cli_stdout([cmd1, Cmd2, cmd3], args=["--print_config=comments", "Cmd2", "method2"])
357357
assert "# Description of Cmd2" in out

0 commit comments

Comments
 (0)