Skip to content

Commit 0e9e096

Browse files
committed
update
1 parent 0ba3087 commit 0e9e096

File tree

1 file changed

+3
-47
lines changed

1 file changed

+3
-47
lines changed

gazelle/python/resolve.go

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -148,56 +148,12 @@ func (py *Resolver) Resolve(
148148
modules := modulesRaw.(*treeset.Set)
149149
it := modules.Iterator()
150150
explainDependency := os.Getenv("EXPLAIN_DEPENDENCY")
151-
// Resolve relative paths for package generation
152-
isPackageGeneration := !cfg.PerFileGeneration() && !cfg.CoarseGrainedGeneration()
153151
hasFatalError := false
154152
MODULES_LOOP:
155153
for it.Next() {
156154
mod := it.Value().(module)
157-
moduleName := mod.Name
158-
// Transform relative imports `.` or `..foo.bar` into the package path from root.
159-
if strings.HasPrefix(moduleName, ".") {
160-
// If not package generation mode, skip relative imports
161-
if !isPackageGeneration {
162-
continue MODULES_LOOP
163-
}
164-
relativeDepth := 0
165-
for i := 0; i < len(moduleName); i++ {
166-
if moduleName[i] == '.' {
167-
relativeDepth++
168-
} else {
169-
break
170-
}
171-
}
172-
173-
// Extract suffix after leading dots
174-
relativeSuffix := moduleName[relativeDepth:]
175-
var relativeSuffixParts []string
176-
if relativeSuffix != "" {
177-
relativeSuffixParts = strings.Split(relativeSuffix, ".")
178-
}
179-
180-
// Split current package label into parts
181-
pkgParts := strings.Split(from.Pkg, "/")
182-
183-
if relativeDepth- 1 > len(pkgParts) {
184-
// Trying to go above the root
185-
log.Printf("ERROR: Invalid relative import %q in %q: exceeds package root.", moduleName, mod.Filepath)
186-
continue MODULES_LOOP
187-
}
188-
189-
// Go up `relativeDepth - 1` levels
190-
baseParts := pkgParts
191-
if relativeDepth > 1 {
192-
baseParts = pkgParts[:len(pkgParts)-(relativeDepth-1)]
193-
}
194-
195-
absParts := append(baseParts, relativeSuffixParts...)
196-
moduleName = strings.Join(absParts, ".")
197-
}
198-
199-
moduleParts := strings.Split(moduleName, ".")
200-
possibleModules := []string{moduleName}
155+
moduleParts := strings.Split(mod.Name, ".")
156+
possibleModules := []string{mod.Name}
201157
for len(moduleParts) > 1 {
202158
// Iterate back through the possible imports until
203159
// a match is found.
@@ -251,7 +207,7 @@ func (py *Resolver) Resolve(
251207
log.Printf("Explaining dependency (%s): "+
252208
"in the target %q, the file %q imports %q at line %d, "+
253209
"which resolves from the third-party module %q from the wheel %q.\n",
254-
explainDependency, from.String(), mod.Filepath, moduleName, mod.Name, dep)
210+
explainDependency, from.String(), mod.Filepath, moduleName, mod.LineNumber, mod.Name, dep)
255211
}
256212
continue MODULES_LOOP
257213
} else {

0 commit comments

Comments
 (0)