-
Notifications
You must be signed in to change notification settings - Fork 133
Adding support for egg and zip files #1477
Changes from all commits
a1d95ab
7321be6
e1eb886
e9e5c72
17924b1
9eefbf7
a867af3
773f0d6
dfefa83
409eb33
3df60fe
dc39eea
d31c4f5
84ab8fe
a6430c2
8c17187
d732969
a3750e4
26ac805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,13 +68,18 @@ def clean(path): | |
BEFORE_SITE.discard(None) | ||
AFTER_SITE.discard(None) | ||
|
||
import zipfile | ||
|
||
for p in sys.path: | ||
p = clean(p) | ||
if os.path.isdir(p): | ||
if p in BEFORE_SITE: | ||
print("%s|stdlib|" % p) | ||
elif p in AFTER_SITE: | ||
if p in SITE_PKGS: | ||
print("%s|site|" % p) | ||
else: | ||
print("%s|pth|" % p) | ||
|
||
if not os.path.isdir(p) and not (os.path.isfile(p) and zipfile.is_zipfile(p)): | ||
continue | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this so interpreter paths would include .egg and .zip |
||
if p in BEFORE_SITE: | ||
print("%s|stdlib|" % p) | ||
elif p in AFTER_SITE: | ||
if p in SITE_PKGS: | ||
print("%s|site|" % p) | ||
else: | ||
print("%s|pth|" % p) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,13 @@ public long FileSize(string path) { | |
return fileInfo.Length; | ||
} | ||
|
||
public string ReadAllText(string path) => File.ReadAllText(path); | ||
public string ReadAllText(string filePath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should remain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's hard to do this because sometimes we may get paths like I'll think about this some more, instead of putting the logic here I suppose I could put it where ReadAllText is called; however I may end up with duplicate code. |
||
if (PathUtils.TryGetZipFilePath(filePath, out var zipPath, out var relativeZipPath)) { | ||
return PathUtils.GetZipContent(zipPath, relativeZipPath); | ||
} | ||
return File.ReadAllText(filePath); | ||
} | ||
|
||
public void WriteAllText(string path, string content) => File.WriteAllText(path, content); | ||
public IEnumerable<string> FileReadAllLines(string path) => File.ReadLines(path); | ||
public void FileWriteAllLines(string path, IEnumerable<string> contents) => File.WriteAllLines(path, contents); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright(c) Microsoft Corporation | ||
// All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the License); you may not use | ||
// this file except in compliance with the License. You may obtain a copy of the | ||
// License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY | ||
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
// MERCHANTABILITY OR NON-INFRINGEMENT. | ||
// | ||
// See the Apache Version 2.0 License for specific language governing | ||
// permissions and limitations under the License. | ||
|
||
using FluentAssertions; | ||
using Microsoft.Python.Core.IO; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.Python.Core.Tests { | ||
[TestClass] | ||
public class PathUtilsTests { | ||
[TestMethod, Priority(0)] | ||
public void ZipFileUNCPath() { | ||
PathUtils.TryGetZipFilePath(@"\\server\home\share\test.zip", out var zipPath, out var relativeZipPath); | ||
zipPath.Should().Be(@"\\server\home\share\test.zip"); | ||
relativeZipPath.Should().BeEmpty(); | ||
|
||
PathUtils.TryGetZipFilePath(@"\\server\home\share\test.zip\test\a.py", out zipPath, out relativeZipPath); | ||
zipPath.Should().Be(@"\\server\home\share\test.zip"); | ||
relativeZipPath.Should().Be("test/a.py"); | ||
|
||
PathUtils.TryGetZipFilePath("\\path\\foo\\baz\\test.zip\\test\\a.py", out zipPath, out relativeZipPath); | ||
zipPath.Should().Be("\\path\\foo\\baz\\test.zip"); | ||
relativeZipPath.Should().Be("test/a.py"); | ||
} | ||
|
||
[TestMethod, Priority(0)] | ||
public void ZipFilePath() { | ||
PathUtils.TryGetZipFilePath("\\path\\foo\\baz\\test.zip", out var zipPath, out var relativeZipPath); | ||
zipPath.Should().Be("\\path\\foo\\baz\\test.zip"); | ||
relativeZipPath.Should().BeEmpty(); | ||
|
||
PathUtils.TryGetZipFilePath("\\path\\foo\\baz\\test.zip\\test\\a.py", out zipPath, out relativeZipPath); | ||
zipPath.Should().Be("\\path\\foo\\baz\\test.zip"); | ||
relativeZipPath.Should().Be("test/a.py"); | ||
|
||
PathUtils.TryGetZipFilePath("\\path\\foo\\baz\\test.zip\\test\\foo\\baz.py", out zipPath, out relativeZipPath); | ||
zipPath.Should().Be("\\path\\foo\\baz\\test.zip"); | ||
relativeZipPath.Should().Be("test/foo/baz.py"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sys | ||
import test.a | ||
|
||
a = test.a.A() | ||
i = a.test() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what would be the
fullModuleName
returned by theTryAddModulePath
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fullModuleName
returns the empty string, not sure if that's what is supposed to happenedit - actually sorry was looking at init.py, for modules like
test.zip/test/a.py
it's returninga
as the full module nameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that an expected full module name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I should have clarified that a root was
test.zip/test
. I ran the test on the librarysimplejson
and for files likesimplejson/decoder.py
it returnssimplejson.decoder
and forsimplejson/tests/test_bitsize_int
it givessimplejson.tests.tesT_bitsize_int
etc, so I believe this is correct.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Then let's add an import test to ensure that import of the module from egg is resolved correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I did that in:
https://github.com/microsoft/python-language-server/pull/1477/files#diff-fc769198933ce6a497889cd518874a9dR897-R928
It loads up the simplejson library and checks to see if some variables have members