@@ -117,18 +117,18 @@ FamixPythonImporter >> commentVisitorClass [
117117]
118118
119119{ #category : ' api' }
120- FamixPythonImporter >> computeFilesToParseFrom: fileReference [
120+ FamixPythonImporter >> computeFilesToParse [
121121 " This method will gather the .py files to parse."
122122
123123 | foldersToVisit |
124124 filesToParse := OrderedCollection new .
125125
126126 " If we get only one file, no need to iterate over any folder."
127- fileReference isPythonFile ifTrue: [
128- filesToParse add: fileReference .
127+ rootReference isPythonFile ifTrue: [
128+ filesToParse add: rootReference .
129129 ^ filesToParse ].
130130
131- foldersToVisit := { fileReference }.
131+ foldersToVisit := { rootReference }.
132132
133133 [
134134 foldersToVisit do: [ :folder |
@@ -138,7 +138,7 @@ FamixPythonImporter >> computeFilesToParseFrom: fileReference [
138138]
139139
140140{ #category : ' api' }
141- FamixPythonImporter >> determineSourceRootFolderFrom: fileReference [
141+ FamixPythonImporter >> determineSourceRootFolder [
142142 " We decided in the parser to define a folder as the root of the project to be used as the base of relative imports. This folder will be the first package of the project.
143143 To find it we have two solutions:
144144 - The user specified the rootPackagePath and we use this (see class comment)
@@ -148,7 +148,7 @@ FamixPythonImporter >> determineSourceRootFolderFrom: fileReference [
148148 ifNil: [ " Since we have all files to parse, we need to find the common parent.
149149 To do that, I'l taking all parents of all files and I check the ones present everywhere. Then I'm using the one with the longest path."
150150 (((filesToParse collect: #allParents ) reduce: [ :a :b | a intersection: b ]) sort: [ :file | file pathString size ] descending) first ]
151- ifNotNil: [ :path | fileReference / path ]
151+ ifNotNil: [ :path | rootReference / path ]
152152]
153153
154154{ #category : ' accessing' }
@@ -166,23 +166,7 @@ FamixPythonImporter >> filesToIgnoreBlock: anObject [
166166{ #category : ' api' }
167167FamixPythonImporter >> import: aFileReference [
168168
169- | fileReference |
170- fileReference := aFileReference asFileReference. " In case the user provided a file name instead of a file reference."
171-
172- self initializeVisitorAndModelUsing: fileReference.
173-
174- " This will be useful for logs and determining the root folder"
175- self computeFilesToParseFrom: fileReference.
176-
177- " If we parse a unique file, we do nothing. If we have a folder, we check what is the source root to start creating our packages."
178- fileReference isPythonFile ifFalse: [ fileReference := self determineSourceRootFolderFrom: fileReference ].
179-
180- self importFileReference: fileReference.
181-
182- visitor resolveUnresolvedPythonSymbols.
183-
184- self flag: #todo . " We should probably handle it another way in production."
185- self errorReport ifNotEmpty: [ self errorReport inspect ].
169+ super import: aFileReference.
186170
187171 " I'm adding some properties to help with the import. Cleaning up afterward."
188172 self model entities do: #flush .
@@ -236,6 +220,16 @@ FamixPythonImporter >> initialize [
236220 numberOfParsedFiles := 0
237221]
238222
223+ { #category : ' api' }
224+ FamixPythonImporter >> preparsingHook [
225+
226+ " This will be useful for logs and determining the root folder"
227+ self computeFilesToParse.
228+
229+ " If we parse a unique file, we do nothing. If we have a folder, we check what is the source root to start creating our packages."
230+ rootReference isPythonFile ifFalse: [ rootReference := self determineSourceRootFolder ]
231+ ]
232+
239233{ #category : ' accessing' }
240234FamixPythonImporter >> rootPackagePath [
241235 " See comment of FamixPythonImporter class>>#import:rootPackagePath:"
0 commit comments