Skip to content

Commit

Permalink
Fix bug in resolution of imports that was taking stubs into account f…
Browse files Browse the repository at this point in the history
…or packages and modules resolutions
  • Loading branch information
jecisc committed Jan 16, 2025
1 parent b3d4f11 commit 8e4a9f1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,15 @@ FamixPythonProject1Test >> testImportTwoStubPackagesOfTheSameName [
self assert: ((self moduleNamed: 'moduleWithStubs') outgoingImports anySatisfy: [ :import | import importedEntity = numpy ])
]

{ #category : 'tests - imports' }
FamixPythonProject1Test >> testImportWithTheNameOfAStubClass [

| module |
module := self moduleNamed: 'moduleWithStubImport'.

module outgoingImports do: [ :import | self deny: (import importedEntity isKindOf: FamixPythonClass) ]
]

{ #category : 'tests - inheritances' }
FamixPythonProject1Test >> testInheritanceDoesNotCreateReference [
"Regression test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ FamixPythonAbstractImportResolvable >> findTargetEntityFor: aPath from: startEnt
| possibleEntities splittedPath |
"We need to trim because we can have spaces between the dots."
splittedPath := (aPath splitOn: $.) collect: [ :segment | segment trim ].
possibleEntities := startEntities select: [ :possibleEntity | possibleEntity name = splittedPath first ].
possibleEntities := startEntities select: [ :possibleEntity | possibleEntity name = splittedPath first and: [ possibleEntity isStub not ] ].
splittedPath removeFirst.
[ splittedPath isNotEmpty ] whileTrue: [
| childName |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ FamixPythonFromImportResolvable >> resolveInScope: aScope currentEntity: current
possibleEntities := currentPackage children ]
ifFalse: [ "If we have an absolute path we just start at the root."
remainingPath := path.
possibleEntities := currentEntity mooseModel rootEntities ].
possibleEntities := currentEntity mooseModel modelRootEntities ].

"We trim the path because we can have spaces after the dots in relativ paths."
possibleEntities := (self findTargetEntityFor: remainingPath trim from: possibleEntities) allChildren select: [ :child |
Expand Down
14 changes: 14 additions & 0 deletions src/Famix-Python-Importer/FamixPythonImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ FamixPythonImporter class >> import: aFileName [
import: aFileName
]

{ #category : 'dev-utils' }
FamixPythonImporter class >> importBeerTradingBot [

<script>
(self import: '/Users/cyril/testPython/beer-trading-bot-main' asFileReference) inspect
]

{ #category : 'dev-utils' }
FamixPythonImporter class >> importReader [

<script>
(self import: '/Users/cyril/testPython/reader' asFileReference) inspect
]

{ #category : 'accessing' }
FamixPythonImporter >> errorReport [

Expand Down
7 changes: 7 additions & 0 deletions src/Famix-Python-Importer/MooseAbstractGroup.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : 'MooseAbstractGroup' }

{ #category : '*Famix-Python-Importer' }
MooseAbstractGroup >> modelRootEntities [

^ self propertyNamed: #modelRootEntities ifAbsentPut: [ self withoutStubs select: [ :entity | entity isQueryable and: [ entity isRoot ] ] ]
]

0 comments on commit 8e4a9f1

Please sign in to comment.