Skip to content

Commit

Permalink
Manage going up in packages for relative imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Oct 1, 2024
1 parent 3402479 commit 4456b8f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,19 @@ FamixPythonProject1Test >> testModuleImportsGlobalVariableFromAModule [
self assert: import importedEntity equals: global
]

{ #category : 'tests - from-import relative' }
FamixPythonProject1Test >> testModuleImportsGlobalVariableFromAModuleInAPackageOneLevelHigherRelatively [

| module global import |
self denyEmpty: self model allImports.
module := self moduleNamed: 'moduleInSubPackage3'.
global := self globalVariableNamed: 'moduleInRoot3Variable'.
import := module outgoingImports detect: [ :pimport | pimport target name = 'moduleInRoot3Variable' ].

self assert: import importingEntity equals: module.
self assert: import importedEntity equals: global
]

{ #category : 'tests - from-import relative' }
FamixPythonProject1Test >> testModuleImportsGlobalVariableFromAModuleInASubpackageRelatively [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ FamixPythonFromImportResolvable >> resolveInScope: aScope currentEntity: current
FamixPythonFromImportResolvable >> resolveRelativePathFor: currentEntity [

| possibleEntities splittedPath |
self flag: #todo. "manage .. And chaining of submodules and also spaces after dots"

possibleEntities := currentEntity parentPackage children.
splittedPath := path allButFirst.
splittedPath := path.
possibleEntities := currentEntity.
[ splittedPath beginsWith: '.' ] whileTrue: [
possibleEntities := possibleEntities parentPackage.
splittedPath := splittedPath allButFirst ].
possibleEntities := possibleEntities children.
splittedPath := splittedPath splitOn: $..
possibleEntities := possibleEntities select: [ :possibleEntity | possibleEntity name = splittedPath first ].
splittedPath removeFirst.
Expand Down

0 comments on commit 4456b8f

Please sign in to comment.