File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
test/3/library-tests/modules/entry_point Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -201,16 +201,31 @@ private string moduleNameFromBase(Container file) {
201
201
file instanceof File and result = file .getStem ( )
202
202
}
203
203
204
+ /**
205
+ * Holds if `file` may be transitively imported from a file that may serve as the entry point of
206
+ * the execution.
207
+ */
208
+ private predicate transitively_imported_from_entry_point ( File file ) {
209
+ file .getExtension ( ) .matches ( "%py%" ) and
210
+ exists ( File importer |
211
+ importer .getParent ( ) = file .getParent ( ) and
212
+ exists ( ImportExpr i | i .getLocation ( ) .getFile ( ) = importer and i .getName ( ) = file .getStem ( ) )
213
+ |
214
+ importer .maybeExecutedDirectly ( ) or transitively_imported_from_entry_point ( importer )
215
+ )
216
+ }
217
+
204
218
string moduleNameFromFile ( Container file ) {
205
219
exists ( string basename |
206
220
basename = moduleNameFromBase ( file ) and
207
221
legalShortName ( basename )
208
222
|
209
223
result = moduleNameFromFile ( file .getParent ( ) ) + "." + basename
210
224
or
211
- // If execution can start in the folder containing this module, then we will assume `file` can
212
- // be imported as an absolute import, and hence return `basename` as a possible name.
213
- file .getParent ( ) .( Folder ) .mayContainEntryPoint ( ) and result = basename
225
+ // If `file` is a transitive import of a file that's executed directly, we allow references
226
+ // to it by its `basename`.
227
+ transitively_imported_from_entry_point ( file ) and
228
+ result = basename
214
229
)
215
230
or
216
231
isPotentialSourcePackage ( file ) and
Original file line number Diff line number Diff line change 1
- | main | hash_bang/main.py:0:0:0:0 | Script main |
2
- | main | name_main/main.py:0:0:0:0 | Module main |
3
1
| module | hash_bang/module.py:0:0:0:0 | Module module |
4
2
| module | name_main/module.py:0:0:0:0 | Module module |
5
3
| package | hash_bang/package:0:0:0:0 | Package package |
You can’t perform that action at this time.
0 commit comments