fix(gazelle): Correctly resolve deps that have top-level module overlap with a gazelle_python.yaml dep module (#2160)

In https://github.com/bazelbuild/rules_python/pull/2048,
`FindThirdPartyDependency` was updated to walk up the module import path
to try to find a match in gazelle_python.yaml. This is unnecessary, as
the main resolve loop will accomplish the same task.

Additionally, the change broke the ability to configure a more specific
resolve override or resolve more specific indexed libraries.

For a real-world example of where this is a problem, `pytype` has a
`third_party` module at its top-level. In a repo that also has a
`third_party` directory, we can no longer resolve our indexed libraries
in `third_party`. When the resolve loop tried to resolve
`third_party.foo.bar`, `FindThirdPartyDependency` will immediately match
`third_party` and not give the resolve loop a chance to look in the rule
index for `third_party.foo.bar`.

The same issue appears for providing overrides that are more specific
(see the updated testcase).

This PR reverts the change to FindThirdPartyDependency and updates the
testcases to ensure that we can still resolve specific indexed packages,
explicit resolve overrides, and third party modules even when there is
an overlap in the top-level module name.
9 files changed
tree: c531eee82dd1c36f66a6f3186a1c92219df82675
  1. .bazelci/
  2. .bcr/
  3. .ci/
  4. .github/
  5. docs/
  6. examples/
  7. gazelle/
  8. python/
  9. sphinxdocs/
  10. tests/
  11. third_party/
  12. tools/
  13. .bazelignore
  14. .bazelrc
  15. .bazelversion
  16. .git-blame-ignore-revs
  17. .gitattributes
  18. .gitignore
  19. .pre-commit-config.yaml
  20. .readthedocs.yml
  21. addlicense.sh
  22. AUTHORS
  23. BUILD.bazel
  24. BZLMOD_SUPPORT.md
  25. CHANGELOG.md
  26. CONTRIBUTING.md
  27. CONTRIBUTORS
  28. DEVELOPING.md
  29. internal_deps.bzl
  30. internal_setup.bzl
  31. LICENSE
  32. MODULE.bazel
  33. README.md
  34. version.bzl
  35. WORKSPACE
  36. 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, py_proto_library, 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

  • Status: Beta
  • Full Feature Parity: No

See Bzlmod support for more details.