fix(bootstrap): manual runfiles path construction when using submodules (#3636)

This fixes https://github.com/bazel-contrib/rules_python/issues/3563.
Verified by running the repro in
https://github.com/mering/reproduction_rules_python_1_7.

The identified regression in
https://github.com/bazel-contrib/rules_python/commit/b8e32c454a1158cd78ce4ecaef809b99bef4e5da
is problematic because prepending `ctx.workspace_name` to `short_path`
results in paths containing `..` (e.g., `_main/../sub+/path/to/file.py`)
when building from a root module that includes other modules. This
causes the `_find_runfiles_root`
[logic](https://github.com/faximan/rules_python/blob/eb6ac472eb86cc263acc336a2b73982043069aae/python/private/site_init_template.py#L73),
which _counts slashes_, to incorrectly calculate the runfiles root.

The fix is simply using the available `runfiles_root_path` function
instead. In the example above, this makes the path simply
`sub+/path/to/file.py`.

---------

Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
5 files changed
tree: 1536aef15d1535eab69c7b9deb7cb10c772f6a8d
  1. .bazelci/
  2. .bcr/
  3. .ci/
  4. .github/
  5. command_line_option/
  6. docs/
  7. examples/
  8. gazelle/
  9. private/
  10. python/
  11. sphinxdocs/
  12. tests/
  13. tools/
  14. .bazelignore
  15. .bazelrc
  16. .bazelrc.deleted_packages
  17. .bazelversion
  18. .editorconfig
  19. .git-blame-ignore-revs
  20. .gitattributes
  21. .gitignore
  22. .pre-commit-config.yaml
  23. .python-version
  24. .readthedocs.yml
  25. addlicense.sh
  26. AGENTS.md
  27. AUTHORS
  28. BUILD.bazel
  29. BZLMOD_SUPPORT.md
  30. CHANGELOG.md
  31. CONTRIBUTING.md
  32. CONTRIBUTORS
  33. GEMINI.md
  34. internal_dev_deps.bzl
  35. internal_dev_setup.bzl
  36. LICENSE
  37. MODULE.bazel
  38. README.md
  39. RELEASING.md
  40. version.bzl
  41. WORKSPACE
  42. WORKSPACE.bzlmod
README.md

Python Rules for Bazel

Build status

Overview

This repository is the home of the core Python rules -- py_library, py_binary, py_test, and related symbols that provide the basis for Python support in Bazel. It also contains package installation rules for integrating with PyPI and other indices.

Documentation for rules_python is at https://rules-python.readthedocs.io and in the Bazel Build Encyclopedia.

Examples live in the examples directory.

The core rules are stable. Their implementation is subject to Bazel's backward compatibility policy. This repository aims to follow semantic versioning.

The Bazel community maintains this repository. Neither Google nor the Bazel team provides support for the code. However, this repository is part of the test suite used to vet new Bazel releases. See How to contribute page for information on our development workflow.

Documentation

For detailed documentation, see https://rules-python.readthedocs.io

Bzlmod support

See Bzlmod support for more details.