add CLIPlugin to accept arbitrary R shapes/JSON on the command-line #7252
add CLIPlugin to accept arbitrary R shapes/JSON on the command-line #7252wihobbs wants to merge 6 commits intoflux-framework:masterfrom
Conversation
25f1bbd to
bd2e57b
Compare
bd2e57b to
a432a63
Compare
|
@sam-maloney was kind enough to do a quick review on 1/8/26 and commented in Slack:
|
grondo
left a comment
There was a problem hiding this comment.
Nice work! Just a few comments or questions to address inline. Thanks!
a432a63 to
3d3172e
Compare
There was a problem hiding this comment.
It is getting to the point where @sam-maloney's --resource-shape option will be really useful so I made another pass on this one.
I'm also wondering if we should install the plugin so it is picked up by default, instead of requiring users to modify their plugin path to get the feature.
|
This would indeed be handy for toy scheduler experiments. Ping? |
3d3172e to
db89f76
Compare
|
... I have no idea why this closed. Edit: p.s. this is not ready for another review, a few more modifications needed, but will be soon. |
6683056 to
6e90be0
Compare
Problem: There is no parser for the CLI Jobspec Resource String Syntax proposed in RFC 46. Add a flux.shape.parser Python module which implements a parser using the 'ply' module (mimicking the constraint parser). For testing, the parser may be run from the command line with flux python -m flux.shape.parser [OPTIONS] -- EXPRESSION
Problem: currently, users have no way on the CLI of utilizing the experimental parser in RFC 46 for specifying a job shape or a resource set they'd like to use via JSON. This causes users to defer to cumbersome piping and JSON mangling when they want to submit jobs of arbitrary resource shapes on the command line. Add a /plugin subdirectory to src/bindings/python/flux/shape for and a plugin for specifying `--resources-json` or `--resources-shape` for specifying resources on the command line beyond the standard ones supported.
Problem: there are examples of valid job shapes listed in RFC 46 but there is currently no unit test for the python jobspec shape parser. Add a unit test with the examples in RFC 46.
Problem: the jobspec shape/JSON plugin is currently not tested on the command line. Add a sharness test.
Problem: the RFC 46 resource shape parser implementation needs comprehensive test coverage to ensure correct parsing of the various syntax elements including resource counts, ranges, labels, attributes, nested resources, and resource lists. Add t0039-shape-parser.t to test the flux.shape.parser module as a standalone CLI tool. The tests cover basic parsing, range syntax, idsets, attributes, nested resources, resource lists, output formats (JSON and YAML), command-line options, error handling for invalid syntax, and all value types (strings, booleans, numbers, arrays). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Problem: the closing quote handler in the shape parser lexer was returning the quote token even when the quote_empty flag was set, causing an extra token to be emitted after empty quoted strings. Return None instead of the token when quote_empty is not set, since the QSTRING tokens have already been returned by the QSTRING_END state handler. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
6e90be0 to
501c14e
Compare
|
This is ready for another review. I would like to get an ack from @sam-maloney before we merge, particularly on the testing and 501c14e, since it modifies his contribution and was Claude-generated. On balance, it looks reasonable to me, but Sam is the expert on the parser. If he's good with that, I will fold it up into the initial commit. As for
that will depend on #7244, which I plan to go work on now. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7252 +/- ##
==========================================
+ Coverage 83.72% 83.77% +0.04%
==========================================
Files 568 570 +2
Lines 95551 95865 +314
==========================================
+ Hits 80000 80310 +310
- Misses 15551 15555 +4
🚀 New features to boost your workflow:
|
| except TypeError: | ||
| jobspec.jobspec["resources"] = data | ||
| else: | ||
| pass |
There was a problem hiding this comment.
Is the
else:
passunnecessary here?
Also, just a suggestion: The function would be easier to read if it used args.shape and args.json directly instead of assigning to temporary local variables s and j.
|
I was able to reproduce the el8 issue locally: Generating LALR tables
Traceback (most recent call last):
File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/src/src/bindings/python/flux/shape/parser.py", line 666, in <module>
print(yaml.dump(result, sort_keys=False))
File "/usr/lib64/python3.6/site-packages/yaml/__init__.py", line 200, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
TypeError: dump_all() got an unexpected keyword argument 'sort_keys'
not ok 13 - flux.shape.parser --yaml produces yaml output
#
# cat >expected10 <<-EOF &&
# - type: slot
# count: 4
# label: task
# with:
# - type: node
# count: 1
#
# EOF
# $parser --yaml -- slot=4/node >output10 &&
# test_cmp expected10 output10
#According to the pyyaml changelog, support was added for the I tried removing that key, but it does change the output: --- expected10 2026-03-31 15:20:23.384955001 +0000
+++ output10 2026-03-31 15:20:23.489955001 +0000
@@ -1,7 +1,6 @@
-- type: slot
- count: 4
+- count: 4
label: task
+ type: slot
with:
- - type: node
- count: 1
+ - {count: 1, type: node}Perhaps that's not so bad, and would most likely be consistent across all distros? We could always add the key back in one glorious day when we finally no longer are tied to Python 3.6.8... |
|
We could vendor pyyaml-5.1, or build it ourselves with pip. It appears to support python 3.6 according to the same changelog. However, if we do something to the el8 container, we'll have to remember and find a similar solution for all the TOSS 4 systems. |
|
I don't think we'd want to vendor a python package just for testing purposes. Perhaps there is a workaround for sorting the output without |
This PR takes the excellent work done by @sam-maloney for RFC#46 and extends it into a command-line plugin that users can opt in to by setting
FLUX_CLI_PLUGINPATH. This was originally suggested by @grondo as a way for us to test/get user feedback on the ergonomics of specifying shape on the command line, and make progress toward incorporating that option into our standard command line.The plugin is relatively straightforward and the testing just references examples from the corresponding RFC. I know this is coming up right before many 🌴s, so no rush on reviews, but I wanted to get it to a stopping point before my own holiday begins :).