Skip to content

Commit

Permalink
Import ruamel.yaml 0.18.6 source.
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmoguy committed Feb 22, 2024
1 parent b698194 commit 1283e71
Show file tree
Hide file tree
Showing 39 changed files with 464 additions and 171 deletions.
1 change: 1 addition & 0 deletions .hgtags
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,4 @@ c0da0ba934877fdfe63bee77ec12a7d2341f5398 0.18.1
a35908655d678b8463ee6198869a0708b3446e06 0.18.2
e32fbfcda1a48d808542670d91f1e84d14f69956 0.18.3
08d87cada1f6e5fedde079b55536061e4fe246a0 0.18.4
eb3ecf31085135283908fc8449befebbc1fff4b3 0.18.5
3 changes: 2 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ build:
python: "3.11"
jobs:
pre_build:
- pip install ryd>=0.8.2
- pip install ryd>=0.9.2
- ryd --version -v
- ryd convert --generate-mkdocs-config mkdocs.yaml _doc

python:
Expand Down
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[0.18.6, 2024-02-07]:
- fixed an issue with dataclass loading when the fields were collections (bug found
as a result of a question by [FibroMyAlgebra](https://stackoverflow.com/users/6855070/fibromyalgebra)
on [StackOverflow](https://stackoverflow.com/a/77485786/1307905))
- fixed an issue loading dataclasses with `InitVar` fields when `from __future__ import
annotations` was used to delay evaluation of typing.

[0.18.5, 2023-11-03]:
- there is some indication that dependent packages have been pinned to use specific
(tested) and just install the latest even in Python versions that have end-of-life
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2023 Anthon van der Neut, Ruamel bvba
Copyright (c) 2014-2024 Anthon van der Neut, Ruamel bvba

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

# ruamel.yaml

`ruamel.yaml` is a YAML 1.2 loader/dumper package for Python.
<table class="docutils">
<tr> <td>version</td>
<td>0.18.5</td>
<td>0.18.6</td>
</tr>
<tr> <td>updated</td>
<td>2023-11-03</td>
<td>2024-02-07</td>
</tr>
<tr> <td>documentation</td>
<td><a href="https://yaml.readthedocs.io">https://yaml.readthedocs.io</a></td>
Expand All @@ -19,6 +20,7 @@
</tr>
</table>


As announced, in 0.18.0, the old PyYAML functions have been deprecated.
(`scan`, `parse`, `compose`, `load`, `emit`, `serialize`, `dump` and their variants
(`_all`, `safe_`, `round_trip_`, etc)). If you only read this after your program has
Expand Down Expand Up @@ -120,6 +122,7 @@ the API is stable enough to make the transition.
</pre>



[![image](https://readthedocs.org/projects/yaml/badge/?version=latest)](https://yaml.readthedocs.org/en/latest?badge=latest)[![image](https://bestpractices.coreinfrastructure.org/projects/1128/badge)](https://bestpractices.coreinfrastructure.org/projects/1128)
[![image](https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/_doc/_static/license.svg?format=raw)](https://opensource.org/licenses/MIT)
[![image](https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/_doc/_static/pypi.svg?format=raw)](https://pypi.org/project/ruamel.yaml/)
Expand All @@ -128,6 +131,11 @@ the API is stable enough to make the transition.

# ChangeLog

0.18.6 (2024-02-07):

- fixed an issue with dataclass loading when the fields were collections (bug found as a result of a question by [FibroMyAlgebra](https://stackoverflow.com/users/6855070/fibromyalgebra) on [StackOverflow](https://stackoverflow.com/a/77485786/1307905))
- fixed an issue loading dataclasses with `InitVar` fields when `from __future__ import annotations` was used to delay evaluation of typing.

0.18.5 (2023-11-03):

- there is some indication that dependent packages have been pinned to use specific (tested) and just install the latest even in Python versions that have end-of-life
Expand Down Expand Up @@ -390,6 +398,7 @@ scalar to start before the `#` column of a following comment.
Effectively making the comment part of the scalar in the output.
(reported by [Bence Nagy](https://sourceforge.net/u/underyx/))


------------------------------------------------------------------------

For older changes see the file
Expand Down
9 changes: 5 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# coding: utf-8

from __future__ import annotations

if False: # MYPY
from typing import Dict, Any # NOQA

_package_data = dict(
full_package_name='ruamel.yaml',
version_info=(0, 18, 5),
__version__='0.18.5',
version_timestamp='2023-11-03 08:54:26',
version_info=(0, 18, 6),
__version__='0.18.6',
version_timestamp='2024-02-07 07:43:33',
author='Anthon van der Neut',
author_email='[email protected]',
description='ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order', # NOQA
Expand Down
2 changes: 1 addition & 1 deletion _doc/_static/pypi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions _test/test_dataclass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from __future__ import annotations

from dataclasses import dataclass, fields, InitVar # NOQA
from textwrap import dedent
Expand Down Expand Up @@ -133,3 +134,47 @@ def __post_init__(self, xyz: Union[str, None]) -> None:
dc2 = yaml.load(yaml_str)
assert dc2.xyz == 'hello'
assert dc2.klm == 55 + len('hello')

def test_collection_field(self) -> None:
# https://stackoverflow.com/a/77485786/1307905
import ruamel.yaml
from dataclasses import dataclass

@dataclass
class Msg:

id: int
desc: str
fields: list[Field]

def __post_init__(self) -> None:
idx: int = 0
for field in self.fields: # why is this empty??
field.index = idx
idx += field.size

@dataclass
class Field:
id: int
name: str
units: str
size: int
index: int = -1

yaml = ruamel.yaml.YAML()
yaml.register_class(Msg)
yaml.register_class(Field)

msg: Msg = yaml.load("""\
!Msg
id: 1
desc: status
fields:
- !Field
id: 1
name: Temp
units: degC
size: 2
""")

assert msg.fields[0].index != -1
33 changes: 33 additions & 0 deletions _test/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"""

import sys
import copy
import pytest # type: ignore # NOQA
from datetime import datetime as DateTime, timezone as TimeZone, timedelta as TimeDelta

from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # type: ignore # NOQA

Expand Down Expand Up @@ -138,6 +140,21 @@ def test_issue_45(self) -> None:
dt: 2016-08-19T22:45:47Z
""")

def test_issue_366(self) -> None:
import ruamel.yaml
import io

round_trip("""
[2021-02-01 22:34:48.696868-03:00]
""")
yaml = ruamel.yaml.YAML()
dd = DateTime(2021, 2, 1, 22, 34, 48, 696868, TimeZone(TimeDelta(hours=-3), name=''))
buf = io.StringIO()
yaml.dump(dd, buf)
assert buf.getvalue() == '2021-02-01 22:34:48.696868-03:00\n...\n'
rd = yaml.load(buf.getvalue())
assert rd == dd

def test_deepcopy_datestring(self) -> None:
# reported by Quuxplusone, http://stackoverflow.com/a/41577841/1307905
x = dedent("""\
Expand All @@ -158,3 +175,19 @@ def test_fraction_overflow(self) -> None:
- 2022-01-02T12:35:00
""")
round_trip(inp, exp)

def Xtest_tzinfo(self) -> None:
import ruamel.yaml

yaml = ruamel.yaml.YAML()
dts = '2011-10-02T16:45:00.930619+01:00'
d = yaml.load(dts)
print('d', repr(d), d._yaml)
yaml.dump(dict(x=d), sys.stdout)
print('----')
# dx = DateTime.fromisoformat(dts)
# print('dx', dx, repr(dx))
dd = DateTime(2011, 10, 2, 16, 45, 00, 930619, TimeZone(TimeDelta(hours=1, minutes=0), name='+01:00')) # NOQA
yaml.dump([dd], sys.stdout)
print('dd', dd, dd.tzinfo)
raise AssertionError()
14 changes: 14 additions & 0 deletions _test/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,17 @@ def test_01(self) -> None:
def test_so_45681626(self) -> None:
# was not properly parsing
round_trip_load('{"in":{},"out":{}}')


class TestVersionComparison:
def test_vc(self) -> None:
from ruamel.yaml.docinfo import Version

assert Version(1, 1) <= Version(2, 0)
assert Version(1, 1) <= Version(1, 2)
assert Version(1, 1) <= Version(1, 1)
assert Version(1, 3) == Version(1, 3)
assert Version(1, 2) > Version(1, 1)
assert Version(2, 0) > Version(1, 1)
assert Version(2, 0) >= Version(1, 1)
assert Version(1, 2) >= Version(1, 2)
6 changes: 4 additions & 2 deletions anchor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# coding: utf-8

from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA
from __future__ import annotations

if False: # MYPY
from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA

anchor_attrib = '_yaml_anchor'

Expand Down
6 changes: 4 additions & 2 deletions comments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8

from __future__ import annotations

"""
stuff to deal with comments and formatting on dict/list/ordereddict/set
Expand All @@ -18,7 +19,8 @@

from collections.abc import MutableSet, Sized, Set, Mapping

from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA
if False: # MYPY
from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA

# fmt: off
__all__ = ['CommentedSeq', 'CommentedKeySeq',
Expand Down
27 changes: 14 additions & 13 deletions compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8

from __future__ import annotations

Expand All @@ -7,18 +6,23 @@
import sys
import os
import io
import traceback
from abc import abstractmethod
import collections.abc


from ruamel.yaml.docinfo import Version # NOQA
# fmt: off
from typing import Any, Dict, Optional, List, Union, BinaryIO, IO, Text, Tuple # NOQA
from typing import Optional # NOQA
try:
from typing import SupportsIndex as SupportsIndex # in order to reexport for mypy
except ImportError:
SupportsIndex = int # type: ignore
if False: # MYPY
from typing import Any, Dict, Optional, List, Union, BinaryIO, IO, Text, Tuple # NOQA
from typing import Optional # NOQA
try:
from typing import SupportsIndex as SupportsIndex # in order to reexport for mypy
except ImportError:
SupportsIndex = int # type: ignore

StreamType = Any
StreamTextType = StreamType
VersionType = Union[str , Tuple[int, int] , List[int] , Version , None]
# fmt: on

_DEFAULT_YAML_VERSION = (1, 2)
Expand Down Expand Up @@ -51,11 +55,6 @@ def insert(self, pos: int, key: Any, value: Any) -> None:
StringIO = io.StringIO
BytesIO = io.BytesIO

StreamType = Any

StreamTextType = StreamType
from ruamel.yaml.docinfo import Version # NOQA
VersionType = Union[str , Tuple[int, int] , List[int] , Version , None]

builtins_module = 'builtins'

Expand Down Expand Up @@ -117,6 +116,8 @@ def __init__(self, file_name: Any = None) -> None:
self._file_name = file_name

def __call__(self, *args: Any, **kw: Any) -> None:
import traceback

if not bool(_debug):
return
out = sys.stdout if self._file_name is None else open(self._file_name, 'a')
Expand Down
6 changes: 4 additions & 2 deletions composer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8

from __future__ import annotations

import warnings

Expand All @@ -17,7 +18,8 @@
)
from ruamel.yaml.nodes import MappingNode, ScalarNode, SequenceNode

from typing import Any, Dict, Optional, List # NOQA
if False: # MYPY
from typing import Any, Dict, Optional, List # NOQA

__all__ = ['Composer', 'ComposerError']

Expand Down
6 changes: 4 additions & 2 deletions configobjwalker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# coding: utf-8

from __future__ import annotations

import warnings

from ruamel.yaml.util import configobj_walker as new_configobj_walker

from typing import Any
if False: # MYPY
from typing import Any


def configobj_walker(cfg: Any) -> Any:
Expand Down
Loading

0 comments on commit 1283e71

Please sign in to comment.