Skip to content

Commit

Permalink
Merge pull request #4 from faucetsdn/ruamel.yaml-0.17.20
Browse files Browse the repository at this point in the history
Upgrade ruamel.yaml to v0.17.20.
  • Loading branch information
gizmoguy authored Jan 13, 2022
2 parents a8ed9e4 + add1e14 commit d78db23
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 54 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/release-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
apt-get update
apt-get -y upgrade
apt-get -y install devscripts dpkg-dev debhelper equivs curl gnupg
echo "deb https://packagecloud.io/faucetsdn/faucet/${{ matrix.distro }}/ ${{ matrix.release }} main" | tee /etc/apt/sources.list.d/faucet.list
curl -1sLf https://packagecloud.io/faucetsdn/faucet/gpgkey -o /etc/apt/trusted.gpg.d/faucet.asc
echo "deb https://packagecloud.io/faucetsdn/faucet-test/${{ matrix.distro }}/ ${{ matrix.release }} main" | tee /etc/apt/sources.list.d/faucet-test.list
curl -1sLf https://packagecloud.io/faucetsdn/faucet-test/gpgkey -o /etc/apt/trusted.gpg.d/faucet-test.asc
apt-get update
Expand Down Expand Up @@ -140,8 +142,10 @@ jobs:
apt-get -y upgrade
apt-get -y install devscripts dpkg-dev debhelper equivs curl gnupg
/usr/bin/c_rehash
echo "deb https://packagecloud.io/faucetsdn/faucet/${{ matrix.distro }}/ ${{ matrix.release }} main" | tee /etc/apt/sources.list.d/faucet.list
curl -1sLf https://packagecloud.io/faucetsdn/faucet/gpgkey -o /etc/apt/trusted.gpg.d/faucet.asc
echo "deb https://packagecloud.io/faucetsdn/faucet-test/${{ matrix.distro }}/ ${{ matrix.release }} main" | tee /etc/apt/sources.list.d/faucet-test.list
curl -L https://packagecloud.io/faucetsdn/faucet-test/gpgkey | apt-key add -
curl -1sLf https://packagecloud.io/faucetsdn/faucet-test/gpgkey -o /etc/apt/trusted.gpg.d/faucet-test.asc
apt-get update
run: |
export DEBEMAIL='[email protected]'
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
apt-get update
apt-get -y upgrade
apt-get -y install devscripts dpkg-dev debhelper equivs curl gnupg
echo "deb https://packagecloud.io/faucetsdn/faucet/${{ matrix.distro }}/ ${{ matrix.release }} main" | tee /etc/apt/sources.list.d/faucet.list
curl -1sLf https://packagecloud.io/faucetsdn/faucet/gpgkey -o /etc/apt/trusted.gpg.d/faucet.asc
echo "deb https://packagecloud.io/faucetsdn/faucet-test/${{ matrix.distro }}/ ${{ matrix.release }} main" | tee /etc/apt/sources.list.d/faucet-test.list
curl -1sLf https://packagecloud.io/faucetsdn/faucet-test/gpgkey -o /etc/apt/trusted.gpg.d/faucet-test.asc
apt-get update
Expand Down Expand Up @@ -122,8 +124,10 @@ jobs:
apt-get -y upgrade
apt-get -y install devscripts dpkg-dev debhelper equivs curl gnupg
/usr/bin/c_rehash
echo "deb https://packagecloud.io/faucetsdn/faucet/${{ matrix.distro }}/ ${{ matrix.release }} main" | tee /etc/apt/sources.list.d/faucet.list
curl -1sLf https://packagecloud.io/faucetsdn/faucet/gpgkey -o /etc/apt/trusted.gpg.d/faucet.asc
echo "deb https://packagecloud.io/faucetsdn/faucet-test/${{ matrix.distro }}/ ${{ matrix.release }} main" | tee /etc/apt/sources.list.d/faucet-test.list
curl -L https://packagecloud.io/faucetsdn/faucet-test/gpgkey | apt-key add -
curl -1sLf https://packagecloud.io/faucetsdn/faucet-test/gpgkey -o /etc/apt/trusted.gpg.d/faucet-test.asc
apt-get update
run: |
export DEBEMAIL='[email protected]'
Expand Down
13 changes: 13 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
[0, 17, 20]: today
- fix error in microseconds while rounding datetime fractions >= 9999995
(reported by `Luis Ferreira <https://sourceforge.net/u/ljmf00/>`__)

[0, 17, 19]: 2021-12-26
- fix mypy problems (reported by `Arun <https://sourceforge.net/u/arunppsg/profile/>`__)

[0, 17, 18]: 2021-12-24
- copy-paste error in folded scalar comment attachment (reported by `Stephan Geulette
<https://sourceforge.net/u/sgeulette/profile/>`__)
- fix 411, indent error comment between key empty seq value (reported by `Guillermo Julián
<https://sourceforge.net/u/gjulianm/profile/>`__)

[0, 17, 17]: 2021-10-31
- extract timestamp matching/creation to util

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-2021 Anthon van der Neut, Ruamel bvba
Copyright (c) 2014-2022 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
17 changes: 15 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ruamel.yaml

``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python.

:version: 0.17.17
:updated: 2021-10-31
:version: 0.17.20
:updated: today
:documentation: http://yaml.readthedocs.io
:repository: https://sourceforge.net/projects/ruamel-yaml/
:pypi: https://pypi.org/project/ruamel.yaml/
Expand Down Expand Up @@ -72,6 +72,19 @@ ChangeLog

.. should insert NEXT: at the beginning of line for next key (with empty line)
0.17.20 (today):
- fix error in microseconds while rounding datetime fractions >= 9999995
(reported by `Luis Ferreira <https://sourceforge.net/u/ljmf00/>`__)

0.17.19 (2021-12-26):
- fix mypy problems (reported by `Arun <https://sourceforge.net/u/arunppsg/profile/>`__)

0.17.18 (2021-12-24):
- copy-paste error in folded scalar comment attachment (reported by `Stephan Geulette
<https://sourceforge.net/u/sgeulette/profile/>`__)
- fix 411, indent error comment between key empty seq value (reported by `Guillermo Julián
<https://sourceforge.net/u/gjulianm/profile/>`__)

0.17.17 (2021-10-31):
- extract timestamp matching/creation to util

Expand Down
8 changes: 5 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

_package_data = dict(
full_package_name='ruamel.yaml',
version_info=(0, 17, 17),
__version__='0.17.17',
version_info=(0, 17, 20),
__version__='0.17.20',
version_timestamp='2022-01-03 09:19:48',
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
entry_points=None,
since=2014,
extras_require={
':platform_python_implementation=="CPython" and python_version<"3.10"': ['ruamel.yaml.clib>=0.1.2'], # NOQA
':platform_python_implementation=="CPython" and python_version<"3.11"': ['ruamel.yaml.clib>=0.2.6'], # NOQA
'jinja2': ['ruamel.yaml.jinja2>=0.2'],
'docs': ['ryd'],
},
Expand All @@ -24,6 +25,7 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Text Processing :: Markup',
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.
13 changes: 13 additions & 0 deletions _test/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,16 @@ def test_deepcopy_datestring(self):
""")
data = copy.deepcopy(round_trip_load(x))
assert round_trip_dump(data) == x

def test_fraction_overflow(self):
# reported (indirectly) by Luís Ferreira
# https://sourceforge.net/p/ruamel-yaml/tickets/414/
inp = dedent("""\
- 2022-01-02T12:34:59.9999994
- 2022-01-02T12:34:59.9999995
""")
exp = dedent("""\
- 2022-01-02T12:34:59.999999
- 2022-01-02T12:35:00
""")
round_trip(inp, exp)
4 changes: 2 additions & 2 deletions comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ def comment_token(s, mark):
if c[1] is None:
c[1] = []
if before == '\n':
c[1].append(comment_token("", start_mark))
c[1].append(comment_token("", start_mark)) # type: ignore
else:
for com in before.split('\n'):
c[1].append(comment_token(com, start_mark))
c[1].append(comment_token(com, start_mark)) # type: ignore
if after:
start_mark = CommentMark(after_indent)
if c[3] is None:
Expand Down
24 changes: 5 additions & 19 deletions constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ def construct_scalar(self, node):
if node.comment is not None and node.comment[1]:
# nprintf('>>>>nc2', node.comment)
# EOL comment after >
lss.comment = self.comment(node.comment[1][0]) # type: ignore
fss.comment = self.comment(node.comment[1][0]) # type: ignore
if fold_positions:
fss.fold_pos = fold_positions # type: ignore
return fss
Expand Down Expand Up @@ -1759,20 +1759,7 @@ def construct_yaml_timestamp(self, node, values=None):
else:
return create_timestamp(**values)
# return SafeConstructor.construct_yaml_timestamp(self, node, values)
year = int(values['year'])
month = int(values['month'])
day = int(values['day'])
hour = int(values['hour'])
minute = int(values['minute'])
second = int(values['second'])
fraction = 0
if values['fraction']:
fraction_s = values['fraction'][:6]
while len(fraction_s) < 6:
fraction_s += '0'
fraction = int(fraction_s)
if len(values['fraction']) > 6 and int(values['fraction'][6]) > 4:
fraction += 1
dd = create_timestamp(**values) # this has delta applied
delta = None
if values['tz_sign']:
tz_hour = int(values['tz_hour'])
Expand All @@ -1782,17 +1769,16 @@ def construct_yaml_timestamp(self, node, values=None):
if values['tz_sign'] == '-':
delta = -delta
# should check for None and solve issue 366 should be tzinfo=delta)
data = TimeStamp(
dd.year, dd.month, dd.day, dd.hour, dd.minute, dd.second, dd.microsecond
)
if delta:
dt = datetime.datetime(year, month, day, hour, minute)
dt -= delta
data = TimeStamp(dt.year, dt.month, dt.day, dt.hour, dt.minute, second, fraction)
data._yaml['delta'] = delta
tz = values['tz_sign'] + values['tz_hour']
if values['tz_minute']:
tz += ':' + values['tz_minute']
data._yaml['tz'] = tz
else:
data = TimeStamp(year, month, day, hour, minute, second, fraction)
if values['tz']: # no delta
data._yaml['tz'] = values['tz']

Expand Down
58 changes: 41 additions & 17 deletions emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Indents:
# replacement for the list based stack of None/int
def __init__(self):
# type: () -> None
self.values = [] # type: List[Tuple[int, bool]]
self.values = [] # type: List[Tuple[Any, bool]]

def append(self, val, seq):
# type: (Any, Any) -> None
Expand All @@ -73,14 +73,19 @@ def last_seq(self):
except IndexError:
return False

def seq_flow_align(self, seq_indent, column):
# type: (int, int) -> int
def seq_flow_align(self, seq_indent, column, pre_comment=False):
# type: (int, int, Optional[bool]) -> int
# extra spaces because of dash
# nprint('seq_flow_align', self.values, pre_comment)
if len(self.values) < 2 or not self.values[-1][1]:
return 0
# -1 for the dash
if len(self.values) == 0 or not pre_comment:
return 0
base = self.values[-1][0] if self.values[-1][0] is not None else 0
return base + seq_indent - column - 1
if pre_comment:
return base + seq_indent # type: ignore
# return (len(self.values)) * seq_indent
# -1 for the dash
return base + seq_indent - column - 1 # type: ignore

def __len__(self):
# type: () -> int
Expand Down Expand Up @@ -405,6 +410,7 @@ def expect_node(self, root=False, sequence=False, mapping=False, simple_key=Fals
# type: (bool, bool, bool, bool) -> None
self.root_context = root
self.sequence_context = sequence # not used in PyYAML
force_flow_indent = False
self.mapping_context = mapping
self.simple_key_context = simple_key
if isinstance(self.event, AliasEvent):
Expand All @@ -430,34 +436,44 @@ def expect_node(self, root=False, sequence=False, mapping=False, simple_key=Fals
# nprint('@', self.indention, self.no_newline, self.column)
i2, n2 = self.indention, self.no_newline # NOQA
if self.event.comment:
if self.event.flow_style is False and self.event.comment:
if self.event.flow_style is False:
if self.write_post_comment(self.event):
self.indention = False
self.no_newline = True
if self.event.flow_style:
column = self.column
if self.write_pre_comment(self.event):
if self.event.flow_style:
# force_flow_indent = True
force_flow_indent = not self.indents.values[-1][1]
self.indention = i2
self.no_newline = not self.indention
if self.event.flow_style:
self.column = column
if (
self.flow_level
or self.canonical
or self.event.flow_style
or self.check_empty_sequence()
):
self.expect_flow_sequence()
self.expect_flow_sequence(force_flow_indent)
else:
self.expect_block_sequence()
elif isinstance(self.event, MappingStartEvent):
if self.event.flow_style is False and self.event.comment:
self.write_post_comment(self.event)
if self.event.comment and self.event.comment[1]:
self.write_pre_comment(self.event)
if self.event.flow_style:
force_flow_indent = not self.indents.values[-1][1]
if (
self.flow_level
or self.canonical
or self.event.flow_style
or self.check_empty_mapping()
):
self.expect_flow_mapping(single=self.event.nr_items == 1)
self.expect_flow_mapping(single=self.event.nr_items == 1,
force_flow_indent=force_flow_indent)
else:
self.expect_block_mapping()
else:
Expand All @@ -481,11 +497,15 @@ def expect_scalar(self):

# Flow sequence handlers.

def expect_flow_sequence(self):
# type: () -> None
ind = self.indents.seq_flow_align(self.best_sequence_indent, self.column)
def expect_flow_sequence(self, force_flow_indent=False):
# type: (Optional[bool]) -> None
if force_flow_indent:
self.increase_indent(flow=True, sequence=True)
ind = self.indents.seq_flow_align(self.best_sequence_indent, self.column,
force_flow_indent)
self.write_indicator(' ' * ind + '[', True, whitespace=True)
self.increase_indent(flow=True, sequence=True)
if not force_flow_indent:
self.increase_indent(flow=True, sequence=True)
self.flow_context.append('[')
self.state = self.expect_first_flow_sequence_item

Expand Down Expand Up @@ -533,9 +553,12 @@ def expect_flow_sequence_item(self):

# Flow mapping handlers.

def expect_flow_mapping(self, single=False):
# type: (Optional[bool]) -> None
ind = self.indents.seq_flow_align(self.best_sequence_indent, self.column)
def expect_flow_mapping(self, single=False, force_flow_indent=False):
# type: (Optional[bool], Optional[bool]) -> None
if force_flow_indent:
self.increase_indent(flow=True, sequence=False)
ind = self.indents.seq_flow_align(self.best_sequence_indent, self.column,
force_flow_indent)
map_init = '{'
if (
single
Expand All @@ -548,7 +571,8 @@ def expect_flow_mapping(self, single=False):
map_init = ''
self.write_indicator(' ' * ind + map_init, True, whitespace=True)
self.flow_context.append(map_init)
self.increase_indent(flow=True, sequence=False)
if not force_flow_indent:
self.increase_indent(flow=True, sequence=False)
self.state = self.expect_first_flow_mapping_key

def expect_first_flow_mapping_key(self):
Expand Down
3 changes: 2 additions & 1 deletion parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ def parse_document_start(self):
# end_mark.line != self.scanner.peek_token().start_mark.line:
# self.loader.scalar_after_indicator = False
event = DocumentStartEvent(
start_mark, end_mark, explicit=True, version=version, tags=tags
start_mark, end_mark, explicit=True, version=version, tags=tags,
comment=token.comment
) # type: Any
self.states.append(self.parse_document_end)
self.state = self.parse_document_content
Expand Down
1 change: 1 addition & 0 deletions representer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ def represent_scalar_bool(self, data):
return SafeRepresenter.represent_bool(self, data, anchor=anchor)

def represent_yaml_object(self, tag, data, cls, flow_style=None):
# type: (Any, Any, Any, Optional[Any]) -> Any
if hasattr(data, '__getstate__'):
state = data.__getstate__()
else:
Expand Down
2 changes: 1 addition & 1 deletion scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,7 @@ def scan_empty_or_full_line_comments(self):
mark = self.reader.get_mark()
comment = '#'
else:
# print('breaking on', repr(ch))
# xprintf('breaking on', repr(ch))
break
else:
comment += ch
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def pckg_entry_point(name):
if package_name is None:
package_name = self.full_package_name
if not script_name:
script_name = package_name.split('.')[-1]
script_name = package_name.rsplit('.', 1)[-1]
return {
'console_scripts': [
'{0} = {1}'.format(script_name, pckg_entry_point(package_name))
Expand Down
Loading

0 comments on commit d78db23

Please sign in to comment.