Skip to content

Commit 0e971a4

Browse files
committed
bob: add pyyaml 6.0 compatibility
Somehow we missed the long pending deprecation of yaml.load without the 'Loader' parameter.
1 parent cb7ee2b commit 0e971a4

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

pym/bob/input.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
import sqlite3
2929
import struct
3030
import sys
31-
import yaml
31+
try:
32+
from yaml import load as yamlLoad, CSafeLoader as YamlSafeLoader
33+
except ImportError:
34+
from yaml import load as yamlLoad, SafeLoader as YamlSafeLoader
3235

3336
warnFilter = WarnOnce("The filter keyword is experimental and might change or vanish in the future.")
3437
warnDepends = WarnOnce("The same package is named multiple times as dependency!",
@@ -3887,7 +3890,7 @@ def __if_expression_constructor(loader, node):
38873890
expr = loader.construct_scalar(node)
38883891
return IfExpression(expr)
38893892

3890-
yaml.SafeLoader.add_constructor(u'!expr', __if_expression_constructor)
3893+
YamlSafeLoader.add_constructor(u'!expr', __if_expression_constructor)
38913894

38923895
def open(self):
38933896
try:
@@ -3945,7 +3948,7 @@ def loadYaml(self, name, yamlSchema, default, preValidate):
39453948
with open(name, "r", encoding='utf8') as f:
39463949
try:
39473950
rawData = f.read()
3948-
data = yaml.safe_load(rawData)
3951+
data = yamlLoad(rawData, Loader=YamlSafeLoader)
39493952
digest = hashlib.sha1(rawData.encode('utf8')).digest()
39503953
except Exception as e:
39513954
raise ParseError("Error while parsing {}: {}".format(name, str(e)))

test/show/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ run_bob show --format diff --show-common root/dep/ root/sandbox/ | grep -q scrip
2020
# Verify that empty properties are hidden by default but can be activated
2121
run_bob show root --no-indent | python3 -c '
2222
import sys, yaml
23-
d = yaml.load(sys.stdin.read())
23+
d = yaml.load(sys.stdin.read(), Loader=yaml.Loader)
2424
assert "checkoutTools" not in d
2525
'
2626

2727
run_bob show root --show-empty | python3 -c '
2828
import sys, yaml
29-
d = yaml.load(sys.stdin.read())
29+
d = yaml.load(sys.stdin.read(), Loader=yaml.Loader)
3030
assert d["checkoutTools"] == {}
3131
'
3232

3333
# Verify that filtering works as expected
3434
run_bob show root -f buildVars -f packageVars | python3 -c '
3535
import sys, yaml
36-
d = yaml.load(sys.stdin.read())
36+
d = yaml.load(sys.stdin.read(), Loader=yaml.Loader)
3737
assert set(d.keys()) == {"buildVars", "packageVars"}
3838
assert set(d["buildVars"].keys()) == {"FOO", "BAR"}
3939
assert set(d["packageVars"].keys()) == {"FOO", "BAR", "META"}

test/test_input_scmoverride.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,4 @@ def testDump(self):
206206
}
207207

208208
o = ScmOverride(spec)
209-
self.assertEqual(spec, yaml.load(str(o)))
209+
self.assertEqual(spec, yaml.load(str(o), Loader=yaml.Loader))

0 commit comments

Comments
 (0)