Skip to content
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

feat(gazelle): use relative paths for resolved imports #1554

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ A brief description of the categories of changes:
or `requirements_in` attributes are unspecified, matching the upstream
`pip-compile` behaviour more closely.

* Make Gazelle use relative paths if possible for dependencies added through
the use of the `resolve` directive.

Breaking changes:

* (pip) `pip_install` repository rule in this release has been disabled and
Expand Down
2 changes: 1 addition & 1 deletion gazelle/python/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (py *Resolver) Resolve(
if override.Repo == from.Repo {
override.Repo = ""
}
dep := override.String()
dep := override.Rel(from.Repo, from.Pkg).String()
deps.Add(dep)
if explainDependency == dep {
log.Printf("Explaining dependency (%s): "+
Expand Down
1 change: 1 addition & 0 deletions gazelle/python/testdata/relative_imports/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# gazelle:resolve py resolved_package //package2:resolved_package
2 changes: 2 additions & 0 deletions gazelle/python/testdata/relative_imports/BUILD.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_library")

# gazelle:resolve py resolved_package //package2:resolved_package

py_library(
name = "relative_imports",
srcs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ py_library(
"subpackage1/module5.py",
],
visibility = ["//:__subpackages__"],
deps = [":resolved_package"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from . import Class1
from .subpackage1.module5 import function5

import resolved_package

def function3():
c1 = Class1()
Expand Down