Skip to content

fix: remove PyYAML runtime dependency from Bazel flow scripts#4113

Open
oksaumya wants to merge 2 commits intoThe-OpenROAD-Project:masterfrom
oksaumya:fix-yaml-module-dependency
Open

fix: remove PyYAML runtime dependency from Bazel flow scripts#4113
oksaumya wants to merge 2 commits intoThe-OpenROAD-Project:masterfrom
oksaumya:fix-yaml-module-dependency

Conversation

@oksaumya
Copy link
Copy Markdown
Contributor

@oksaumya oksaumya commented Apr 6, 2026

Fixes #4103

Summary

  • non_stage_variables.py and defaults.py fail with ModuleNotFoundError: No module named 'yaml' when running in the Bazel sandbox, where the system Python does not have PyYAML
  • Switched these runtime scripts to use json (stdlib) by reading from a checked-in variables.json
  • Added yaml_to_json.py developer tool to regenerate the JSON from variables.yaml
  • Added CI check to ensure variables.json stays in sync with variables.yaml

Test plan

  • Verify python3 flow/scripts/non_stage_variables.py synth works without PyYAML installed
  • Verify python3 flow/scripts/defaults.py works without PyYAML installed
  • Run bazel test -c opt test/... in OpenROAD and confirm no more yaml import errors

Copilot AI review requested due to automatic review settings April 6, 2026 19:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json and switch defaults.py + non_stage_variables.py to load variables via json (stdlib) instead of PyYAML.
  • Add flow/scripts/yaml_to_json.py to regenerate variables.json from variables.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.yamlvariables.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.

@oksaumya oksaumya force-pushed the fix-yaml-module-dependency branch 2 times, most recently from c31df6c to c43b4d8 Compare April 6, 2026 19:43
@maliberty
Copy link
Copy Markdown
Member

Developers will still need to install it so this doesn't help them out. Is it hard to simply install it?

@oksaumya
Copy link
Copy Markdown
Contributor Author

oksaumya commented Apr 7, 2026

@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:

  • Developers with PyYAML installed: works exactly as before, no change
  • Bazel sandbox: automatically falls back to the checked-in variables.json

This keeps the developer workflow unchanged while fixing the sandbox issue. Want me to update the PR?

@maliberty
Copy link
Copy Markdown
Member

Yes. Claude also suggests

  1. scripts/*.json glob in BUILD.bazel is too broad. This matches any future JSON file added to scripts/. Should be narrowed to the specific file: "scripts/variables.json", instead of "scripts/*.json".
  2. Mark variables.json as generated. Add to .gitattributes:
    flow/scripts/variables.json linguist-generated=true

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>
@oksaumya oksaumya force-pushed the fix-yaml-module-dependency branch from c43b4d8 to aacb9b4 Compare April 7, 2026 10:06
@oksaumya
Copy link
Copy Markdown
Contributor Author

oksaumya commented Apr 7, 2026

@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).

@maliberty
Copy link
Copy Markdown
Member

In the future please don't force push after review has started as it breaks the "see changes since last review" feature.

@maliberty
Copy link
Copy Markdown
Member

CI error is unrelated

@oksaumya
Copy link
Copy Markdown
Contributor Author

oksaumya commented Apr 7, 2026

Understood, I’ll avoid

@maliberty
Copy link
Copy Markdown
Member

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>
@oksaumya
Copy link
Copy Markdown
Contributor Author

oksaumya commented Apr 7, 2026

Pushed a new commit with:

  • yamlfix bumped to 1.19.1
  • Added --exit-code to git diff in the yamlfix step so it properly fails on differences

@oksaumya
Copy link
Copy Markdown
Contributor Author

oksaumya commented Apr 9, 2026

@maliberty could you take a look when you have a moment? Let me know if there’s anything else to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Call to non_stage_variables.py requires yaml, but is not provided in build environment

3 participants