Repository navigation
fix: remove PyYAML runtime dependency from Bazel flow scripts - #4113
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the runtime PyYAML dependency from the Bazel sandbox execution path by switching flow runtime scripts to consume a checked-in variables.json (generated from variables.yaml), and adds CI tooling to keep the JSON in sync.
Changes:
- Add
flow/scripts/variables.jsonand switchdefaults.py+non_stage_variables.pyto load variables viajson(stdlib) instead of PyYAML. - Add
flow/scripts/yaml_to_json.pyto regeneratevariables.jsonfromvariables.yaml. - Update Bazel packaging and GitHub Actions to include/check the new JSON artifact.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
flow/scripts/yaml_to_json.py |
New developer utility to convert variables.yaml → variables.json. |
flow/scripts/variables.json |
Checked-in JSON representation of flow variables for runtime use without PyYAML. |
flow/scripts/non_stage_variables.py |
Switch runtime parsing from YAML to JSON. |
flow/scripts/defaults.py |
Switch runtime parsing from YAML to JSON. |
flow/BUILD.bazel |
Ensure scripts/*.json is available to Bazel flow targets. |
.github/workflows/github-actions-yaml-test.yml |
Add CI step intended to verify variables.json stays in sync with variables.yaml. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c31df6c to
c43b4d8
Compare
|
Developers will still need to install it so this doesn't help them out. Is it hard to simply install it? |
|
@maliberty Good point, I want to keep the developer experience unchanged. The issue is specifically the Bazel sandbox: these scripts are exec'd from Tcl (flow/scripts/util.tcl:162), so they use the sandbox's isolated Python which can't access pip-installed packages. There's no way to pip install into the sandbox. I can simplify the approach though: have the scripts try import yaml first and fall back to import json only when yaml isn't available. That way:
This keeps the developer workflow unchanged while fixing the sandbox issue. Want me to update the PR? |
|
Yes. Claude also suggests
|
non_stage_variables.py and defaults.py are called at runtime via exec from Tcl/Make inside the Bazel sandbox, where the system Python does not have PyYAML installed, causing ModuleNotFoundError. Switch these scripts to use json (stdlib) by reading from a checked-in variables.json instead of variables.yaml. A CI check ensures the JSON stays in sync with the YAML source of truth. Signed-off-by: saumya <saumyakr2006@gmail.com>
c43b4d8 to
aacb9b4
Compare
|
@maliberty Updated with all suggestions, narrowed glob to scripts/variables.json, added linguist-generated to .gitattributes, and fixed CI (sparse-checkout, dependency ordering, explicit pyyaml install). |
|
In the future please don't force push after review has started as it breaks the "see changes since last review" feature. |
|
CI error is unrelated |
|
Understood, I’ll avoid |
|
A noticed an issue that I don't think you created but since you are improving this maybe you can fix it. yamlfix check step is passing even though it is flagging differences. That should be a fail. |
- Bump yamlfix from 1.17.0 to 1.19.1 - Add --exit-code to git diff in yamlfix step so CI fails when yamlfix flags formatting differences Signed-off-by: saumya <saumyakr2006@gmail.com>
|
Pushed a new commit with:
|
|
@maliberty could you take a look when you have a moment? Let me know if there’s anything else to do. |
|
@maliberty, is there anything else to address in this PR? |
|
It is flagging variables.json as out of date. Please update it as part of this PR. |
…endency Signed-off-by: saumya <saumyakr2006@gmail.com>
Sync variables.json after upstream changes added new tunable fields to CAP_MARGIN, SLEW_MARGIN, TNS_END_PERCENT and other variables. Signed-off-by: saumya <saumyakr2006@gmail.com>
- Apply yamlfix formatting to variables.yaml per yamlfix.toml rules - Regenerate variables.json from updated variables.yaml - Regenerate docs/user/FlowVariables.md from updated variables.yaml Signed-off-by: saumya <saumyakr2006@gmail.com>
|
@maliberty fixed |
variables.json was added in #4113 for #4103: OpenROAD's `bazel test test/...` ran the flow through bazel-orfs, and non_stage_variables.py, exec'd from util.tcl inside the Bazel sandbox, found no PyYAML. OpenROAD has since dropped bazel-orfs and test/orfs (The-OpenROAD-Project/OpenROAD#11546), ORFS no longer carries Bazel build files (c4d858d), and bazel-orfs sets PYTHON_EXE to a Python that has PyYAML for every action. A plain make run uses the host python3, and the DependencyInstaller (etc/requirements-common.in) and flake.nix install PyYAML, as they did before #4113. defaults.py and non_stage_variables.py go back to reading variables.yaml as they did before #4113, and variables.json, yaml_to_json.py, the CI check that kept them in sync and the linguist-generated attribute go away. Both scripts print the same lines as before, in the YAML's order rather than sorted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Fixes #4103
Summary
non_stage_variables.pyanddefaults.pyfail withModuleNotFoundError: No module named 'yaml'when running in the Bazel sandbox, where the system Python does not have PyYAMLjson(stdlib) by reading from a checked-invariables.jsonyaml_to_json.pydeveloper tool to regenerate the JSON fromvariables.yamlvariables.jsonstays in sync withvariables.yamlTest plan
python3 flow/scripts/non_stage_variables.py synthworks without PyYAML installedpython3 flow/scripts/defaults.pyworks without PyYAML installedbazel test -c opt test/...in OpenROAD and confirm no moreyamlimport errors