Skip to content

feat(gazelle): Allow disabling sibling module resolution #3106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

amartani
Copy link
Contributor

@amartani amartani commented Jul 19, 2025

Currently, gazelle allows absolute imports to be resolved to sibling modules: an import foo statement will resolve to a foo.py file in the same folder if such file exists. This seems to be a Python 2 behavior (ie. pre-from __future__ import absolute_import), and doesn't work on the current rules_python setup.

This behavior is explicitly tested in the siblings_import test case. However, recreating the exact same repository layout from this test case and running bazel test //pkg:unit_test, the test fails with the import failing.

This PR adds a new directive, gazelle:python_resolve_sibling_imports, to allow disabling such behavior.

The actual changes are in 2 places:

  • In gazelle/python/target.go, the directive is added to if t.siblingSrcs.Contains(fileName) && fileName != filepath.Base(dep.Filepath), which is where the import is converted to a full absolute import if it matches a sibling file;
  • In gazelle/python/generate.go, the handling of conftest.py was dependent on this behavior (ie. it added a dependency on the module conftest, assuming that it would be resolved to the relative module). That was modified to compute the full absolute module path instead.

I also explicitly added gazelle:python_resolve_sibling_imports true to any test that breaks if the default value of this directive is changed to false.

@amartani amartani marked this pull request as ready for review July 19, 2025 01:58
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.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy