Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publisher command: evaluate user expressions, support joysticks #19

Merged
merged 45 commits into from
Apr 15, 2021
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6a9201f
Add initial MIDI support
pavel-kirienko Apr 9, 2021
9d3cf7d
Fix channel treatment
pavel-kirienko Apr 9, 2021
d64ec76
Add joystick support via SDL2 and a monitoring command
pavel-kirienko Apr 9, 2021
2d6196f
Linting
pavel-kirienko Apr 10, 2021
5c6fc94
Add tests for the joystick command and fix deps
pavel-kirienko Apr 10, 2021
fd7f279
Fix SDL2 deps
pavel-kirienko Apr 10, 2021
72f5454
Fix syntax error in setup.cfg and add libsdl2
pavel-kirienko Apr 10, 2021
d25d3ad
Fix libsdl2 package name
pavel-kirienko Apr 10, 2021
b2fbf53
Add RtMidi
pavel-kirienko Apr 10, 2021
26fab46
Update package index
pavel-kirienko Apr 10, 2021
e2b09e9
Refactor the publisher into a package and add MessageBuilder and Cont…
pavel-kirienko Apr 11, 2021
a1ebcf7
Refactor things slightly
pavel-kirienko Apr 11, 2021
ac60785
Fix the state coupling problem
pavel-kirienko Apr 11, 2021
0a25d6c
Add message factory parser test
pavel-kirienko Apr 11, 2021
9789b0a
Add null controller
pavel-kirienko Apr 11, 2021
0baae49
Enhance tests
pavel-kirienko Apr 11, 2021
4e2204a
Message factory test
pavel-kirienko Apr 11, 2021
43c5a4e
Control reader test
pavel-kirienko Apr 11, 2021
3f0dba7
Log controller listing exception instead of propagating it to support…
pavel-kirienko Apr 11, 2021
6f804e2
Rename hid_controller
pavel-kirienko Apr 11, 2021
333c548
Suppress MyPy
pavel-kirienko Apr 11, 2021
b309c47
Mention the virtual controller
pavel-kirienko Apr 11, 2021
73b3843
Fix linter warnings
pavel-kirienko Apr 11, 2021
bd6272f
Refactor YAML
pavel-kirienko Apr 12, 2021
51b9730
Rename YAML classes
pavel-kirienko Apr 12, 2021
f9648d1
Fix list_controllers
pavel-kirienko Apr 12, 2021
107bee9
Ignore missing APT deps
pavel-kirienko Apr 12, 2021
160fe10
MyPy fix
pavel-kirienko Apr 12, 2021
ed39923
Ignore apt-get update failure
pavel-kirienko Apr 12, 2021
5a95b5b
MIDI: return defaultdicts
pavel-kirienko Apr 13, 2021
aa62277
Catch unsupported tags
pavel-kirienko Apr 13, 2021
5cff4c9
Integrate the evaluable loader with the publisher command
pavel-kirienko Apr 13, 2021
65593de
Fix YAML traversal
pavel-kirienko Apr 13, 2021
cd2fb8c
Fix linting errors
pavel-kirienko Apr 13, 2021
49b7956
Unbreak test
pavel-kirienko Apr 13, 2021
aba3f72
Add expression tests
pavel-kirienko Apr 13, 2021
f82b14f
Fix test
pavel-kirienko Apr 13, 2021
fe624fb
Fix the other test
pavel-kirienko Apr 13, 2021
551efdd
Advance the README
pavel-kirienko Apr 13, 2021
3c3e2fa
Add 'y' alias
pavel-kirienko Apr 15, 2021
e9c2702
Add pub docs
pavel-kirienko Apr 15, 2021
f125a37
Update the README
pavel-kirienko Apr 15, 2021
914706e
Update README
pavel-kirienko Apr 15, 2021
f4d6437
Manage blank lines
pavel-kirienko Apr 15, 2021
3bc32fd
Windows-specific SDL2-related fix: SDL_INIT_VIDEO is required on Windows
pavel-kirienko Apr 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Catch unsupported tags
  • Loading branch information
pavel-kirienko committed Apr 13, 2021
commit aa6227757fdb7cc02c714d35023a266bedda4f67
21 changes: 21 additions & 0 deletions yakut/yaml/_eval_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ class ConstructorWrapper(ruamel.yaml.constructor.RoundTripConstructor): # type:

self._impl.Constructor = ConstructorWrapper
self._impl.constructor.add_constructor(self.EVAL_TAG, construct_embedded_expression)
self._impl.constructor.add_multi_constructor("", catch_unknown_tags)

@property
def evaluation_context(self) -> Dict[str, Any]:
"""
This property allows the user to modify the evaluation context after the instance is constructed.
"""
return self._evaluation_context

def load(self, text: str, **evaluation_context: Any) -> Any:
"""
Expand Down Expand Up @@ -110,6 +118,10 @@ def construct_embedded_expression(_constructor: ruamel.yaml.Constructor, node: r
return out


def catch_unknown_tags(_constructor: ruamel.yaml.Constructor, tag: str, node: ruamel.yaml.Node) -> None:
raise ValueError(f"Unsupported YAML tag {tag!r} encountered in node {node!r}")


_logger = yakut.get_logger(__name__)


Expand All @@ -124,8 +136,17 @@ def _unittest_eval() -> None:
print(out)
assert out == {"a": 456, "b": 6, "c": [2, 1]}

evaluator = loader.load_unevaluated("!$ '[one, two, three]'")
assert evaluator(three=3) == [1, 2, 3]
loader.evaluation_context["one"] = 11
loader.evaluation_context["two"] = 222
assert evaluator(three=-3) == [11, 222, -3]

with pytest.raises(EmbeddedExpressionError, match=r"(?i).*YAML string.*"):
loader.load("baz: !$ []")

with pytest.raises(EmbeddedExpressionError, match=r"(?i).*expression.*"):
loader.load("baz: !$ 0syntax error")

with pytest.raises(ValueError, match=r"(?i).*YAML tag.*"):
loader.load("baz: !bad 123")