Skip to content

Commit

Permalink
Merge pull request #193 from wwkimball/development
Browse files Browse the repository at this point in the history
Prepare v3.6.8
  • Loading branch information
wwkimball authored Nov 1, 2022
2 parents 9148aac + 9172938 commit 0819520
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 63 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand All @@ -32,11 +32,11 @@ jobs:
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install --upgrade wheel
python -m pip install --upgrade mypy pytest pytest-cov pytest-console-scripts pylint coveralls pep257
python -m pip install --upgrade mypy pytest pytest-cov pytest-console-scripts pylint coveralls pydocstyle
python -m pip install --editable .
- name: Validate Compliance with PEP257
- name: Validate Compliance with pydocstyle
run: |
pep257 yamlpath
pydocstyle yamlpath
- name: Validate Compliance with MyPY
run: |
mypy yamlpath
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/python-publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand All @@ -33,11 +33,11 @@ jobs:
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install --upgrade wheel
python -m pip install --upgrade mypy pytest pytest-cov pytest-console-scripts pylint coveralls pep257
python -m pip install --upgrade mypy pytest pytest-cov pytest-console-scripts pylint coveralls pydocstyle
python -m pip install --editable .
- name: Validate Compliance with PEP257
- name: Validate Compliance with pydocstyle
run: |
pep257 yamlpath
pydocstyle yamlpath
- name: Validate Compliance with MyPY
run: |
mypy yamlpath
Expand Down
10 changes: 10 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
3.6.8
Bug Fixes:
* Changes to format and value of child nodes under Anchored Hashes (maps/dicts)
caused unexpected expansion of the same key-value pair wherever a YAML Merge
Key Aliased the affected Anchored Hash. Thanks to
https://github.com/hemnstill for finding and reporting this issue!

Enhancements:
* Support for Python 3.10 has been added, thanks to https://github.com/mechie!

3.6.7
Bug Fixes:
* Release 3.6.6 had a broken package; it was unexpectedly missing the required
Expand Down
8 changes: 4 additions & 4 deletions run-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ ForEach ($EnvDir in $EnvDirs) {
}

Write-Output "...upgrading testing tools"
pip install --upgrade mypy pytest pytest-cov pytest-console-scripts pylint coveralls pep257
pip install --upgrade mypy pytest pytest-cov pytest-console-scripts pylint coveralls pydocstyle

Write-Output "`nPEP257..."
pep257 yamlpath | Out-String
Write-Output "`nPYDOCSTYLE..."
pydocstyle yamlpath | Out-String
if (!$?) {
& deactivate
Remove-Item -Recurse -Force $TmpVEnv
Write-Error "PEP257 Error: $?"
Write-Error "PYDOCSTYLE Error: $?"
exit 9
}

Expand Down
8 changes: 4 additions & 4 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ EOF

echo "...upgrading testing tools"
pip install --upgrade mypy pytest pytest-cov pytest-console-scripts \
pylint coveralls pep257 >/dev/null
pylint coveralls pydocstyle >/dev/null

echo -e "\nPEP257..."
if ! pep257 yamlpath; then
echo -e "\nPYDOCSTYLE..."
if ! pydocstyle yamlpath; then
deactivate
rm -rf "$tmpVEnv"
echo "PEP257 Error: $?"
echo "PYDOCSTYLE Error: $?"
exit 9
fi

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Operating System :: OS Independent",
"Environment :: Console",
"Topic :: Utilities",
Expand Down
50 changes: 32 additions & 18 deletions tests/test_commands_yaml_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,24 +346,6 @@ def test_broken_saveto(self, script_runner, tmp_path_factory):
assert not result.success, result.stderr
assert "Cannot add" in result.stderr

@requireseyaml
def test_bad_decryption(self, script_runner, tmp_path_factory, old_eyaml_keys):
content = """---
encrypted: ENC[PKCS7,MIIx...broken-on-purpose...==]
"""
yaml_file = create_temp_yaml_file(tmp_path_factory, content)
result = script_runner.run(
self.command,
"--change=encrypted",
"--random=1",
"--check=n/a",
"--privatekey={}".format(old_eyaml_keys[0]),
"--publickey={}".format(old_eyaml_keys[1]),
yaml_file
)
assert not result.success, result.stderr
assert "Unable to decrypt value!" in result.stderr

@requireseyaml
def test_good_encryption(self, script_runner, tmp_path_factory, old_eyaml_keys):
import re
Expand Down Expand Up @@ -1542,3 +1524,35 @@ def test_cannot_ymk_non_hashes(self, script_runner, tmp_path_factory):
)
assert not result.success, result.stderr
assert "Cannot add YAML Merge Keys to non-Hash" in result.stderr

def test_ymk_anchor_child_format_change(self, script_runner, tmp_path_factory):
"""
Test that changing the FORMAT and value of an anchored Hash node does
not cause unexpected expansion at the YAML Merge Key anchor of the
Hash.
"""
# Thanks to https://github.com/hemnstill!
yamlin = """---
common: &base
TEST_COMMON_SETTING: 'a1'
TestService:
<<: *base
"""
yamlout = """---
common: &base
TEST_COMMON_SETTING: a2
TestService:
<<: *base
"""
yaml_file = create_temp_yaml_file(tmp_path_factory, yamlin)
result = script_runner.run(
self.command,
"--change=common.TEST_COMMON_SETTING",
"--value=a2",
yaml_file
)
assert result.success, result.stderr

with open(yaml_file, 'r') as fhnd:
filedat = fhnd.read()
assert filedat == yamlout
2 changes: 1 addition & 1 deletion yamlpath/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Core YAML Path classes."""
# Establish the version number common to all components
__version__ = "3.6.7"
__version__ = "3.6.8"

from yamlpath.yamlpath import YAMLPath
from yamlpath.processor import Processor
5 changes: 4 additions & 1 deletion yamlpath/commands/eyaml_rotate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def validateargs(args, log):

# pylint: disable=locally-disabled,too-many-locals,too-many-branches,too-many-statements
def main():
"""Main code."""
"""Perform the work specified via CLI arguments and exit.
Main code.
"""
# Process any command-line arguments
args = processcli()
log = ConsolePrinter(args)
Expand Down
5 changes: 4 additions & 1 deletion yamlpath/commands/yaml_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ def get_doc(log, docs, index):

# pylint: disable=locally-disabled,too-many-locals
def main():
"""Main code."""
"""Perform the work specified via CLI arguments and exit.
Main code.
"""
args = processcli()
log = ConsolePrinter(args)
validateargs(args, log)
Expand Down
5 changes: 4 additions & 1 deletion yamlpath/commands/yaml_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ def validateargs(args, log):
sys.exit(1)

def main():
"""Main code."""
"""Perform the work specified via CLI arguments and exit.
Main code.
"""
args = processcli()
log = ConsolePrinter(args)
validateargs(args, log)
Expand Down
5 changes: 4 additions & 1 deletion yamlpath/commands/yaml_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,10 @@ def merge_docs(
return return_state

def main():
"""Main code."""
"""Perform the work specified via CLI arguments and exit.
Main code.
"""
args = processcli()
log = ConsolePrinter(args)
validateargs(args, log)
Expand Down
5 changes: 4 additions & 1 deletion yamlpath/commands/yaml_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,10 @@ def process_yaml_file(
return exit_state

def main():
"""Main code."""
"""Perform the work specified via CLI arguments and exit.
Main code.
"""
# Process any command-line arguments
args = processcli()
log = ConsolePrinter(args)
Expand Down
5 changes: 4 additions & 1 deletion yamlpath/commands/yaml_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ def _ymk_nodes(

# pylint: disable=locally-disabled,too-many-locals,too-many-branches,too-many-statements
def main():
"""Main code."""
"""Perform the work specified via CLI arguments and exit.
Main code.
"""
args = processcli()
log = ConsolePrinter(args)
validateargs(args, log)
Expand Down
5 changes: 4 additions & 1 deletion yamlpath/commands/yaml_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ def process_file(log, yaml, yaml_file):
return exit_state

def main():
"""Main code."""
"""Perform the work specified via CLI arguments and exit.
Main code.
"""
# Process any command-line arguments
args = processcli()
log = ConsolePrinter(args)
Expand Down
25 changes: 15 additions & 10 deletions yamlpath/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,17 +991,15 @@ def _get_nodes_by_key(

elif isinstance(data, (set, CommentedSet)):
for ele in data:
if ele == stripped_attrs or (
isinstance(ele, TaggedScalar)
and ele.value == stripped_attrs
):
ele_val = ele.value if isinstance(ele, TaggedScalar) else ele
if ele_val == stripped_attrs:
self.logger.debug((
"Processor::_get_nodes_by_key: FOUND set node by"
" name at {}."
).format(str_stripped))
next_translated_path = (translated_path +
YAMLPath.escape_path_section(
ele, translated_path.seperator))
ele_val, translated_path.seperator))
next_ancestry = ancestry + [(data, ele)]
yield NodeCoords(
ele, data, stripped_attrs,
Expand Down Expand Up @@ -1465,7 +1463,10 @@ def _collector_addition(
self, data: Any, peek_path: YAMLPath, node_coords: List[NodeCoords],
**kwargs
) -> List[NodeCoords]:
"""Helper for _get_nodes_by_collector."""
"""List nodes matching the given path of an Addition Collector.
Helper for _get_nodes_by_collector.
"""
updated_coords = node_coords
parent: Any = kwargs.pop("parent", None)
parentref: Any = kwargs.pop("parentref", None)
Expand Down Expand Up @@ -1503,7 +1504,10 @@ def _collector_subtraction(
self, data: Any, peek_path: YAMLPath, collected_ncs: List[NodeCoords],
**kwargs
) -> List[NodeCoords]:
"""Helper for _get_nodes_by_collector."""
"""List nodes matching the given path of a Subtraction Collector.
Helper for _get_nodes_by_collector.
"""
def get_del_nodes(
del_nodes: List[Any], node_coord: NodeCoords
) -> None:
Expand Down Expand Up @@ -2522,7 +2526,7 @@ def _get_optional_nodes(
# pylint: disable=too-many-arguments
def _update_node(
self, parent: Any, parentref: Any, value: Any,
value_format: YAMLValueFormats, value_tag: str = None
value_format: YAMLValueFormats, value_tag: Union[str, None] = None
) -> None:
"""
Set the value of a data node.
Expand Down Expand Up @@ -2554,13 +2558,13 @@ def _update_node(
# author of ruamel.yaml, to resolve how to update all references to an
# Anchor throughout the parsed data structure.
def recurse(data, parent, parentref, reference_node, replacement_node):
if isinstance(data, (CommentedMap, dict)):
if isinstance(data, CommentedMap):
for i, k in [
(idx, key) for idx, key in enumerate(data.keys())
if key is reference_node
]:
data.insert(i, replacement_node, data.pop(k))
for k, val in data.items():
for k, val in data.non_merged_items():
if val is reference_node:
if (hasattr(val, "anchor") or
(data is parent and k == parentref)):
Expand All @@ -2579,6 +2583,7 @@ def recurse(data, parent, parentref, reference_node, replacement_node):
data.discard(reference_node)
data.add(replacement_node)

change_node = None
if isinstance(parent, (set, CommentedSet)):
for ele in parent:
if ele == parentref:
Expand Down
Loading

0 comments on commit 0819520

Please sign in to comment.