Python: Fix import root computation for windows and 3.7

This commit is contained in:
Mark Shannon 2018-11-30 15:07:46 +00:00
Родитель 1956cd802f
Коммит 8e6c16d59f
3 изменённых файлов: 17 добавлений и 11 удалений

Просмотреть файл

@ -339,9 +339,21 @@ abstract class Container extends @container {
/** Holds if this folder is the root folder for the standard library. */
predicate isStdLibRoot(int major, int minor) {
allowable_version(major, minor) and
this.isImportRoot() and
this.getBaseName().regexpMatch("python" + major + "." + minor)
major = major_version() and minor = minor_version() and
this.isStdLibRoot()
}
/** Holds if this folder is the root folder for the standard library. */
predicate isStdLibRoot() {
/* Look for a standard lib module and find its import path
* We use `os` as it is the most likely to be imported and
* `tty` because it is small for testing.
*/
exists(Module m |
m.getName() = "os" or m.getName() = "tty"
|
m.getFile().getImportRoot() = this
)
}
/** Gets the path element from which this container would be loaded. */
@ -375,12 +387,6 @@ private string get_path(string name) {
py_flags_versioned(name, result, _)
}
private predicate allowable_version(int major, int minor) {
major = 2 and minor in [6..7]
or
major = 3 and minor in [3..6]
}
class Location extends @location {
/** Gets the file for this location */

Просмотреть файл

@ -158,7 +158,7 @@ class Module extends Module_, Scope, AstNode {
/** Holds if this module is in the standard library */
predicate inStdLib() {
this.inStdLib(_, _)
this.getLoadPath().isStdLibRoot()
}
override

Просмотреть файл

@ -50,7 +50,7 @@ class DistPackage extends ExternalPackage {
parent = this.(ModuleObject).getPath().getParent() and
parent.isImportRoot() and
/* Not in standard library */
not parent.isStdLibRoot(_, _) and
not parent.isStdLibRoot() and
/* Not in the source */
not exists(parent.getRelativePath())
)