Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions python/ql/src/semmle/python/Files.qll
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,6 @@ class File extends Container {
* are specified to be extracted.
*/
string getContents() { file_contents(this, result) }

/** Holds if this file is likely to get executed directly, and thus act as an entry point for execution. */
predicate maybeExecutedDirectly() {
// Only consider files in the source code, and not things like the standard library
exists(this.getRelativePath()) and
(
// The file doesn't have the extension `.py` but still contains Python statements
not this.getExtension().matches("py%") and
exists(Stmt s | s.getLocation().getFile() = this)
or
// The file contains the usual `if __name__ == '__main__':` construction
exists(If i, Name name, StrConst main, Cmpop op |
i.getScope().(Module).getFile() = this and
op instanceof Eq and
i.getTest().(Compare).compares(name, op, main) and
name.getId() = "__name__" and
main.getText() = "__main__"
)
or
// The file contains a `#!` line referencing the python interpreter
exists(Comment c |
c.getLocation().getFile() = this and
c.getLocation().getStartLine() = 1 and
c.getText().regexpMatch("^#! */.*python(2|3)?[ \\\\t]*$")
)
)
}
}

private predicate occupied_line(File f, int n) {
Expand Down Expand Up @@ -148,9 +121,6 @@ class Folder extends Container {
this.getBaseName().regexpMatch("[^\\d\\W]\\w*") and
result = this.getParent().getImportRoot(n)
}

/** Holds if execution may start in a file in this directory. */
predicate mayContainEntryPoint() { any(File f | f.getParent() = this).maybeExecutedDirectly() }
}

/**
Expand Down
7 changes: 1 addition & 6 deletions python/ql/src/semmle/python/Module.qll
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,8 @@ private string moduleNameFromBase(Container file) {
string moduleNameFromFile(Container file) {
exists(string basename |
basename = moduleNameFromBase(file) and
legalShortName(basename)
|
legalShortName(basename) and
result = moduleNameFromFile(file.getParent()) + "." + basename
or
// If execution can start in the folder containing this module, then we will assume `file` can
// be imported as an absolute import, and hence return `basename` as a possible name.
file.getParent().(Folder).mayContainEntryPoint() and result = basename
)
or
isPotentialSourcePackage(file) and
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.