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

Commit 069910b

Browse files
author
MikhailArkhipov
committed
2 parents a731c2a + d6dd1ae commit 069910b

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

src/Analysis/Ast/Impl/Extensions/PythonTypeExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ public static bool IsGeneric(this IPythonType value)
3030

3131
public static void TransferDocumentationAndLocation(this IPythonType s, IPythonType d) {
3232
if (s != d && s is PythonType src && d is PythonType dst) {
33-
dst.TrySetTypeId(src.TypeId);
3433
var documentation = src.Documentation;
3534
if (!string.IsNullOrEmpty(documentation)) {
36-
dst.SetDocumentationProvider(_ => documentation);
35+
dst.SetDocumentation(documentation);
3736
}
3837
dst.SetLocation(src.Location);
3938
}

src/Analysis/Ast/Impl/Modules/ModuleCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public string ReadCachedModule(string filePath) {
139139
if (assemblyTime > cacheTime) {
140140
cachedFileOlderThanAssembly = true;
141141
} else {
142-
return _fs.ReadAllText(cachePath);
142+
return _fs.ReadTextWithRetry(cachePath);
143143
}
144144
}
145145
}

src/Analysis/Ast/Impl/Modules/PythonModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected virtual string LoadContent() {
212212
if (ContentState < State.Loading) {
213213
ContentState = State.Loading;
214214
try {
215-
var code = FileSystem.ReadAllText(FilePath);
215+
var code = FileSystem.ReadTextWithRetry(FilePath);
216216
ContentState = State.Loaded;
217217
return code;
218218
} catch (IOException) { } catch (UnauthorizedAccessException) { }

src/Analysis/Ast/Impl/Modules/SpecializedModule.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// See the Apache Version 2.0 License for specific language governing
1414
// permissions and limitations under the License.
1515

16-
using System;
17-
using System.IO;
16+
using Microsoft.Python.Analysis.Specializations.Typing;
1817
using Microsoft.Python.Core;
18+
using Microsoft.Python.Core.IO;
1919

2020
namespace Microsoft.Python.Analysis.Modules {
2121
/// <summary>
@@ -27,15 +27,15 @@ namespace Microsoft.Python.Analysis.Modules {
2727
/// Specialization is helpful when it is easier to express module members
2828
/// behavior to the analyzer in code. Example of specialization is 'typing'
2929
/// module. Specialized module can use actual library module as a source
30-
/// of documentation for its members. See <see cref="Typing.TypingModule"/>.
30+
/// of documentation for its members. See <see cref="TypingModule"/>.
3131
/// </remarks>
3232
public abstract class SpecializedModule : PythonModule {
3333
protected SpecializedModule(string name, string modulePath, IServiceContainer services)
3434
: base(name, modulePath, ModuleType.Specialized, null, services) { }
3535

3636
protected override string LoadContent() {
3737
// Exceptions are handled in the base
38-
return FileSystem.FileExists(FilePath) ? FileSystem.ReadAllText(FilePath) : string.Empty;
38+
return FileSystem.FileExists(FilePath) ? FileSystem.ReadTextWithRetry(FilePath) : string.Empty;
3939
}
4040
}
4141
}

src/Analysis/Ast/Impl/Modules/StubPythonModule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using Microsoft.Python.Core;
18+
using Microsoft.Python.Core.IO;
1819

1920
namespace Microsoft.Python.Analysis.Modules {
2021
/// <summary>
@@ -30,7 +31,7 @@ public StubPythonModule(string moduleName, string stubPath, bool isTypeshed, ISe
3031

3132
protected override string LoadContent() {
3233
// Exceptions are handled in the base
33-
return FileSystem.FileExists(FilePath) ? FileSystem.ReadAllText(FilePath) : string.Empty;
34+
return FileSystem.FileExists(FilePath) ? FileSystem.ReadTextWithRetry(FilePath) : string.Empty;
3435
}
3536

3637
protected override string[] GetScrapeArguments(IPythonInterpreter factory) => Array.Empty<string>();

src/Core/Impl/Extensions/IOExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ public static FileStream OpenWithRetry(this IFileSystem fs, string file, FileMod
109109
return null;
110110
}
111111

112+
public static string ReadTextWithRetry(this IFileSystem fs, string file) {
113+
// Retry for up to one second
114+
for (var retries = 100; retries > 0; --retries) {
115+
try {
116+
return fs.ReadAllText(file);
117+
} catch (UnauthorizedAccessException) {
118+
Thread.Sleep(10);
119+
}
120+
}
121+
return null;
122+
}
123+
112124
public static void WriteTextWithRetry(this IFileSystem fs, string filePath, string text) {
113125
try {
114126
using (var stream = fs.OpenWithRetry(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) {

0 commit comments

Comments
 (0)