generate variables.json from variables.yaml to avoid yaml dependency#3932
generate variables.json from variables.yaml to avoid yaml dependency#3932oharboe wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
Conversation
generate-variables-docs.py now also outputs variables.json alongside the FlowVariables.md documentation. This allows defaults.py, non_stage_variables.py, and AutoTuner/utils.py to use the built-in json module instead of depending on the external yaml module. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1955348 to
0cf8542
Compare
|
@maliberty @vvbandeira Unrelated CI error |
|
this is the precondition for The-OpenROAD-Project/OpenROAD#9558 to work |
|
If you really want to do this you should remove variables.yaml. It seems easier to just add yaml to |
But you also need to then have the package compiled in bazel to be used there. You can use pip in bazel, but having less dependencies (and Python in general..., personal opinion) is always good. |
|
We don't use bazel in ORFS so I'm not sure why it is relevant here? |
|
(You are going to lose the Python battle) |
but why did the bazel build fail when updating the Python library in the bazel dependencies ? |
|
There is no bazel build of ORFS. Are you talking about some other OR PR? |
|
When I updated the rules_python in bazel: The-OpenROAD-Project/OpenROAD#9558 |
|
I see this is OR -> bazel-ORFS -> ORFS for testing. In that case it would seem to be https://github.com/The-OpenROAD-Project/bazel-orfs/blob/main/requirements.in to add it to. |
The problem is that variables.yaml needs to be read by Bazel repository rules, which happens before the bazel build really begins and we can use requiremements.in. Hence it is nice to have the variables.yaml (human readable/editable) and a variables.json (computer ingestible automatically generated that stock python before dependencies are easy to use from repository rules). I have been considering fixing this for some time, but untl @hzeller ran into it and I had Claude to do it, I never got around to it. |
|
In fact, it is not Python, but Starlark that needs to ingest the variables.json file. .json is more computer friendly than .yaml. |
|
Fine the you need to remove the yaml file here |
I want to keep the yaml file, human friendly, I view ir as source code. |
|
I don't see anything that connects the two and they will drift apart. There should be one source of truth. If you want yaml you'll have to make it usable. |
|
|
||
| json_path = os.path.join(dir_path, "variables.json") | ||
| with open(json_path, "w") as file: | ||
| json.dump(data, file, indent=2) |
There was a problem hiding this comment.
@maliberty Wr already check that docs are regenerated and this script also updates .json file
automatically regenerated and enforced in CI via doc generation script. |
|
So in order to add/modify a variable or run the check you have to have yaml installed. This feels like an odd wart on the system. Why does variables.yaml have to be read so early that you can't install yaml first? |
Bazel starlark repository rules use system dependencies, not dependencies in MODULE.bazel. |
|
Gemini explains... A bit verbose, but I think it reads well. Why
|
|
@hzeller @maliberty Asked Claude to ingest the .yaml without requiring anything locally The-OpenROAD-Project/bazel-orfs#508 |
|
(A bit of outside-the-box idea here) Json is not easy to read and write as human (no comments, no trailing commas, obnoxiously annoying quoting of field names). YAML can be slightly more readable, but also very hard to edit as a human (very error-prone finicky white-space handling with no error detection). If there is something that should be easy to edit from humans but also easy to process by Python-like languages, why not have something that looks like bunch of Python-style tuples and can probably be ingested somewhat easily in Python and Starlark ? declare_variable(
name = "GENERATE_SOME_THING",
description = '''
some long winded description.
''',
# comments work as well
stages = [
"foo",
"bar",
"baz",
],
) |
|
I think yaml is easy to edit and we have the CI flow. Closing this as I think I have the fix merged in bazel-orfs. |
|
hmmm... this PR is probably an improvement, but I will tweak bazel-orfs to handle yaml dependency. |
generate-variables-docs.py now also outputs variables.json alongside the FlowVariables.md documentation. This allows defaults.py, non_stage_variables.py, and AutoTuner/utils.py to use the built-in json module instead of depending on the external yaml module.