Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Remove temp folder from paths, fix site packages outside of stdlib paths #1325

Merged
merged 1 commit into from
Jul 12, 2019
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
34 changes: 34 additions & 0 deletions src/Analysis/Ast/Test/PathClassificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,39 @@ public void InsideStdLib() {
new PythonLibraryPath(src, PythonLibraryPathType.Unspecified),
});
}

[TestMethod]
public void SiteOutsideStdlib() {
var appPath = TestData.GetTestSpecificPath("app.py");
var root = Path.GetDirectoryName(appPath);

var venv = Path.Combine(root, "venv");
var venvLib = Path.Combine(venv, "Lib");
var sitePackages = Path.Combine(root, "site-packages");

var src = Path.Combine(root, "src");

var fromInterpreter = new[] {
new PythonLibraryPath(venvLib, PythonLibraryPathType.StdLib),
new PythonLibraryPath(venv, PythonLibraryPathType.StdLib),
new PythonLibraryPath(sitePackages, PythonLibraryPathType.Site),
};

var fromUser = new[] {
"./src",
};

var (interpreterPaths, userPaths) = PythonLibraryPath.ClassifyPaths(root, _fs, fromInterpreter, fromUser);

interpreterPaths.Should().BeEquivalentToWithStrictOrdering(new[] {
new PythonLibraryPath(venvLib, PythonLibraryPathType.StdLib),
new PythonLibraryPath(venv, PythonLibraryPathType.StdLib),
new PythonLibraryPath(sitePackages, PythonLibraryPathType.Site),
});

userPaths.Should().BeEquivalentToWithStrictOrdering(new[] {
new PythonLibraryPath(src, PythonLibraryPathType.Unspecified),
});
}
}
}
17 changes: 13 additions & 4 deletions src/Analysis/Core/Impl/Interpreter/PythonLibraryPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,14 @@ public static async Task<List<PythonLibraryPath>> GetSearchPathsFromInterpreterA
try {
var output = await ps.ExecuteAndCaptureOutputAsync(startInfo, cancellationToken);
return output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(s => {
if (PathUtils.PathStartsWith(s, tempWorkingDir)) {
return null;
}
try {
return Parse(s);
var p = Parse(s);

if (PathUtils.PathStartsWith(p.Path, tempWorkingDir)) {
return null;
}

return p;
} catch (ArgumentException) {
Debug.Fail("Invalid search path: " + (s ?? "<null>"));
return null;
Expand Down Expand Up @@ -249,6 +252,12 @@ IEnumerable<string> fromUser
continue;
}

// If Python says it's site, then treat is as interpreter.
if (p.Type == PythonLibraryPathType.Site) {
interpreterPaths.Add(p);
continue;
}

// If path is outside the workspace, then treat it as interpreter.
if (root == null || !fs.IsPathUnderRoot(root, p.Path)) {
interpreterPaths.Add(p);
Expand Down