Skip to content

feat(gazelle): simplify gazelle_python.yaml#2048

Merged
aignas merged 4 commits intobazel-contrib:mainfrom
hunshcn:feat/simplify-gazelle-yaml
Jul 26, 2024
Merged

feat(gazelle): simplify gazelle_python.yaml#2048
aignas merged 4 commits intobazel-contrib:mainfrom
hunshcn:feat/simplify-gazelle-yaml

Conversation

@hunshcn
Copy link
Copy Markdown
Contributor

@hunshcn hunshcn commented Jul 9, 2024

Simplify and make gazelle_python.yaml have only top level package name.

It would work well in cases to reduce merge conflicts.

Resolve #1890

This is a compatible change and seems to have no side effects, so no options are provided.

@hunshcn hunshcn force-pushed the feat/simplify-gazelle-yaml branch from 050df26 to 3f00830 Compare July 9, 2024 15:01
@hunshcn hunshcn changed the title feat: simplify gazelle_python.yaml feat(gazelle): simplify gazelle_python.yaml Jul 9, 2024
Copy link
Copy Markdown
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@linzhp, @dougthor42, you have bigger projects using gazelle so it would be great to hear if this has any negative impacts. @alexeagle, since you have clients using gazelle maybe you have time to test this change out with bigger projects to let us know how this would work in cases where there is a lot of traffic and changes to what internal files packages have would cause merge conflicts?

@dougthor42
Copy link
Copy Markdown
Collaborator

Just FYI this is still on my radar. I expect to have some time in the next 48hrs.

@aignas
Copy link
Copy Markdown
Collaborator

aignas commented Jul 11, 2024

Yeah, I'll wait to give enough time for people to look into this.

@dougthor42
Copy link
Copy Markdown
Collaborator

Note: I had to cherry-pick cca1d4e (#2058) to get this to work, but that's expected.

gazelle_python.yaml is now just 2% ❗ of the original size: It went from 28737 lines down to 549 lines. The "1 insertion" was simply the file hash changing.

 gazelle_python.yaml | 28190 +----------------------------------------------------------------------------------
 1 file changed, 1 insertion(+), 28189 deletions(-)

We have 505 BUILD.bazel files. I tried randomly deleting some of them and having gazelle remake them. No change1 👍

$ find src/ -type f -name BUILD.bazel -print0 | xargs -0 -I {} bash -c '[ $[ $RANDOM % 100 ] == 0 ] && echo deleting {} && rm {}'
list of 6 files
$ bazel run //:gazelle
$ git status
On branch u/dthor/bazel-simplify-gazelle-check
nothing to commit, working tree clean

I did the "randomly delete" again a couple more times. All good!

I also ran some bazel test, but I'd expect this to have zero impact on them. They ran just fine.

Overall I think this is 💯 . Very nice! 🎉 🥳

Footnotes

  1. Aside from expected changes that gazelle doesn't deal with, like data attribute or when my random delete removed a hand-made BUILD file.

@linzhp
Copy link
Copy Markdown
Contributor

linzhp commented Jul 13, 2024

Shorten gazelle_python.yaml greatly. I didn't run into issues with some quick test

Copy link
Copy Markdown
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, but otherwise looks good. I'll wait for a few more days for someone form Aspect to chime in.

Signed-off-by: hunshcn <hunsh.cn@gmail.com>
@alexeagle
Copy link
Copy Markdown
Contributor

I'm sorry, I have no time the rest of this month - maybe @jbedard has an idea since he worked on python gazelle recently

@aignas aignas enabled auto-merge July 26, 2024 04:02
@aignas aignas added this pull request to the merge queue Jul 26, 2024
Merged via the queue into bazel-contrib:main with commit 014ad58 Jul 26, 2024
alexeagle pushed a commit to aspect-build/bazel-examples that referenced this pull request Aug 19, 2024
github-merge-queue bot pushed a commit that referenced this pull request Aug 28, 2024
…ap with a gazelle_python.yaml dep module (#2160)

In #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.
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.

[FR] simplify gazelle_python.yaml

5 participants