Skip to content

709/from imports #759

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

Conversation

aptenodytes-forsteri
Copy link
Contributor

@aptenodytes-forsteri aptenodytes-forsteri commented Jul 17, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

  • from foo import bar adds //foo as a dep instead of //foo/bar.
  • from foo.bar import baz adds //foo/bar as a dep instead of //foo/bar:baz (when //foo/bar:baz is a separate py_library that contains foo/bar/baz.py as a source).
  • from google.cloud import aiplatform does not add "@gazelle_python_test_google_cloud_aiplatform//:pkg", as a dep (fails to resolve from imports for pip packages).

Issue Number: #709

What is the new behavior?

When gazelle encounters from foo.bar import baz, try to resolve, in order from most specific to least specific:

foo.bar.baz
foo.bar
foo

This way, if foo.bar.baz is in the manifest file or in the index of existing rules (e.g. from a rule that contains the source file foo/bar/baz, it can be found). If foo.bar.baz can't be resolved, try foo.bar (maybe baz is just a function or variable in foo/bar.py).

Does this PR introduce a breaking change?

  • Yes
  • No - all existing tests continue to pass.

Other information

May want to consider antagonistic cases - are there cases where imports are truly ambiguous?

@google-cla
Copy link

google-cla bot commented Jul 17, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

2 participants