Skip to content

Commit 49d1937

Browse files
authored
Merge pull request github#5552 from RasmusWL/revert-import-change
Python: Revert github#5506 due to bad performance
2 parents d4877a9 + 51c27de commit 49d1937

File tree

26 files changed

+1
-108
lines changed

26 files changed

+1
-108
lines changed

python/ql/src/semmle/python/Files.qll

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,33 +72,6 @@ class File extends Container {
7272
* are specified to be extracted.
7373
*/
7474
string getContents() { file_contents(this, result) }
75-
76-
/** Holds if this file is likely to get executed directly, and thus act as an entry point for execution. */
77-
predicate maybeExecutedDirectly() {
78-
// Only consider files in the source code, and not things like the standard library
79-
exists(this.getRelativePath()) and
80-
(
81-
// The file doesn't have the extension `.py` but still contains Python statements
82-
not this.getExtension().matches("py%") and
83-
exists(Stmt s | s.getLocation().getFile() = this)
84-
or
85-
// The file contains the usual `if __name__ == '__main__':` construction
86-
exists(If i, Name name, StrConst main, Cmpop op |
87-
i.getScope().(Module).getFile() = this and
88-
op instanceof Eq and
89-
i.getTest().(Compare).compares(name, op, main) and
90-
name.getId() = "__name__" and
91-
main.getText() = "__main__"
92-
)
93-
or
94-
// The file contains a `#!` line referencing the python interpreter
95-
exists(Comment c |
96-
c.getLocation().getFile() = this and
97-
c.getLocation().getStartLine() = 1 and
98-
c.getText().regexpMatch("^#! */.*python(2|3)?[ \\\\t]*$")
99-
)
100-
)
101-
}
10275
}
10376

10477
private predicate occupied_line(File f, int n) {
@@ -148,9 +121,6 @@ class Folder extends Container {
148121
this.getBaseName().regexpMatch("[^\\d\\W]\\w*") and
149122
result = this.getParent().getImportRoot(n)
150123
}
151-
152-
/** Holds if execution may start in a file in this directory. */
153-
predicate mayContainEntryPoint() { any(File f | f.getParent() = this).maybeExecutedDirectly() }
154124
}
155125

156126
/**

python/ql/src/semmle/python/Module.qll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,8 @@ private string moduleNameFromBase(Container file) {
204204
string moduleNameFromFile(Container file) {
205205
exists(string basename |
206206
basename = moduleNameFromBase(file) and
207-
legalShortName(basename)
208-
|
207+
legalShortName(basename) and
209208
result = moduleNameFromFile(file.getParent()) + "." + basename
210-
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
214209
)
215210
or
216211
isPotentialSourcePackage(file) and

python/ql/test/3/library-tests/modules/entry_point/hash_bang/main.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

python/ql/test/3/library-tests/modules/entry_point/hash_bang/module.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

python/ql/test/3/library-tests/modules/entry_point/hash_bang/namespace_package/namespace_package_main.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

python/ql/test/3/library-tests/modules/entry_point/hash_bang/namespace_package/namespace_package_module.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

python/ql/test/3/library-tests/modules/entry_point/hash_bang/package/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

python/ql/test/3/library-tests/modules/entry_point/hash_bang/package/package_main.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

python/ql/test/3/library-tests/modules/entry_point/hash_bang/package/package_module.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

python/ql/test/3/library-tests/modules/entry_point/modules.expected

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)