Skip to content

Commit

Permalink
Manage import of modules in subpackages but removing the management o…
Browse files Browse the repository at this point in the history
…f import adding to the context
  • Loading branch information
jecisc committed Sep 23, 2024
1 parent aa97793 commit db9fdf4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 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 @@ -25,6 +25,19 @@ FamixPythonProject1Test >> testModel [
self assert: self model rootFolder equals: FamixPythonBridge parsingExamples / 'project1'
]

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

| importingModule importedModule import |
self denyEmpty: self model allImports.
importingModule := self moduleNamed: 'moduleInRootPackage2'.
importedModule := self moduleNamed: 'moduleInSubPackage1'.
import := importingModule outgoingImports detect: [ :pimport | pimport target name = 'moduleInSubPackage1' ].

self assert: import importingEntity equals: importingModule.
self assert: import importedEntity equals: importedModule
]

{ #category : 'tests - modules' }
FamixPythonProject1Test >> testModuleInRootPackage [

Expand Down
4 changes: 2 additions & 2 deletions src/Famix-Python-Importer/FamixPythonImport.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ FamixPythonImport >> displayStringOn: aStream [
nextPutAll: 'a ' ;
nextPutAll: self class name ;
nextPutAll: '('.
self fromName displayStringOn: aStream.
self source displayStringOn: aStream.
aStream nextPutAll: ' -> '.
self entityName displayStringOn: aStream.
self target displayStringOn: aStream.
aStream nextPutAll: ')'
]
11 changes: 7 additions & 4 deletions src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,18 @@ FamixPythonImporterVisitor >> createImport: anImport ofName: aName from: fromNam
self setSourceAnchor: import from: anImport.

self currentEntity addOutgoingImport: import.

self flag: #todo. "Check how to manage the push before the main entity and the pops."
(self solver
pushResolvableAsScopeBeforeMainEntityScope: (FamixPythonImportResolvable path: aName)
foundAction: [ :entity :currentEntity | entity addIncomingImport: import ]) notFoundReplacementEntity: [ :unresolvedImport :currentEntity |
"pushResolvableAsScopeBeforeMainEntityScope: (FamixPythonImportResolvable path: aName)"
resolve:((FamixPythonImportResolvable path: aName)
notFoundReplacementEntity: [ :unresolvedImport :currentEntity |
self flag: #todo. "Add infos and check that we do not already have this stub"
model newModule
isStub: true;
addIncomingImport: import;
yourself ].
yourself ];
yourself)
foundAction: [ :entity :currentEntity | entity addIncomingImport: import ]) .

^ import
]
Expand Down

0 comments on commit db9fdf4

Please sign in to comment.