in src/server/install.ts [280:311]
private async patchPythonAspect(root: string) {
// Get the current contents of the Python aspect template, as added by the installer.
const targetFile = path.join(
root,
'.bazelbsp/aspects/rules/python/python_info.bzl.template'
)
let content = ''
try {
content = await fs.readFile(targetFile, 'utf8')
} catch {
this.outputChannel.appendLine(
`Failed to read file ${targetFile}. Skipping patch.`
)
}
// Make rules_python load statement non-conditional for compatibility with rules_py.
const regex =
/#if\( \$pythonEnabled == "true" && \$bazel8OrAbove == "true" \)[\s\S]*?#end/
const replacement =
'load("@rules_python//python:defs.bzl", "PyInfo", "PyRuntimeInfo")'
// Replace the matched block with the replacement.
content = content.replace(regex, replacement)
try {
await fs.writeFile(targetFile, content, 'utf8')
} catch (err) {
this.outputChannel.appendLine(
`Failed to write updated Python aspect to ${targetFile}. Skipping patch.`
)
}
}