当前位置: 首页>>代码示例>>C#>>正文


C# PythonLanguageVersion.ToVersion方法代码示例

本文整理汇总了C#中PythonLanguageVersion.ToVersion方法的典型用法代码示例。如果您正苦于以下问题:C# PythonLanguageVersion.ToVersion方法的具体用法?C# PythonLanguageVersion.ToVersion怎么用?C# PythonLanguageVersion.ToVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PythonLanguageVersion的用法示例。


在下文中一共展示了PythonLanguageVersion.ToVersion方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartCrossThreadAnalysisCalls

        private IEnumerable<Task> StartCrossThreadAnalysisCalls(
            CancellationToken cancel,
            PythonLanguageVersion version
        ) {
            var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
            var state = PythonAnalyzer.CreateSynchronously(fact);

            const string testCode = @"from mod{0:000} import test_func as other_test_func, MyClass as other_mc

c = None
def test_func(a, b={1}()):
    '''My test function'''
    globals c
    a = b
    a = {1}(a)
    b = other_test_func(a)
    c = other_mc.fn(b)
    return b

class MyClass:
    fn = test_func

my_test_func = test_func
my_test_func = other_test_func
my_test_func('abc')

mc = MyClass()
mc.fn([])
";

            var entries = Enumerable.Range(0, 100)
                .Select(i => {
                    var entry = state.AddModule(string.Format("mod{0:000}", i), string.Format("mod{0:000}.py", i));
                    entry.ParseFormat(PythonLanguageVersion.V34, testCode, i + 1, PythonTypes[i % PythonTypes.Count]);
                    return entry;
                })
                .ToList();

            // One analysis before we start
            foreach (var e in entries) {
                e.Analyze(cancel, true);
            }
            state.AnalyzeQueuedEntries(cancel);

            // Repeatedly re-analyse the code
            yield return Task.Run(() => {
                var rnd = new Random();
                while (!cancel.IsCancellationRequested) {
                    var shufEntries = entries
                        .Select(e => Tuple.Create(rnd.Next(), e))
                        .OrderBy(t => t.Item1)
                        .Take(entries.Count / 2)
                        .Select(t => t.Item2)
                        .ToList();
                    foreach (var e in shufEntries) {
                        e.Analyze(cancel, true);
                    }

                    state.AnalyzeQueuedEntries(cancel);
                    Console.WriteLine("Analysis complete");
                    Thread.Sleep(1000);
                }
            }, cancel);

            // Repeatedly re-parse the code
            yield return Task.Run(() => {
                var rnd = new Random();
                while (!cancel.IsCancellationRequested) {
                    var shufEntries = entries
                        .Select((e, i) => Tuple.Create(rnd.Next(), e, i))
                        .OrderBy(t => t.Item1)
                        .Take(entries.Count / 4)
                        .ToList();
                    foreach (var t in shufEntries) {
                        var i = t.Item3;
                        t.Item2.ParseFormat(PythonLanguageVersion.V34, testCode, i + 1, PythonTypes[i % PythonTypes.Count]);
                    }
                    Thread.Sleep(1000);
                }
            }, cancel);

            // Repeatedly request signatures
            yield return Task.Run(() => {
                var entry = entries[1];
                while (!cancel.IsCancellationRequested) {
                    var sigs = entry.Analysis.GetSignaturesByIndex("my_test_func", 0).ToList();

                    if (sigs.Any()) {
                        AssertUtil.ContainsExactly(
                            sigs.Select(s => s.Name),
                            "test_func"
                        );

                        foreach (var s in sigs) {
                            AssertUtil.ContainsExactly(s.Parameters.Select(p => p.Name), "a", "b");
                        }
                    }
                }
            }, cancel);

//.........这里部分代码省略.........
开发者ID:RussBaz,项目名称:PTVS,代码行数:101,代码来源:ThreadingTest.cs

示例2: Parse

 private static IPythonModule Parse(string path, PythonLanguageVersion version) {
     var interpreter = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion()).CreateInterpreter();
     if (!Path.IsPathRooted(path)) {
         path = TestData.GetPath(Path.Combine("TestData", "AstAnalysis", path));
     }
     return AstPythonModule.FromFile(interpreter, path, version);
 }
开发者ID:jsschultz,项目名称:PTVS,代码行数:7,代码来源:AstAnalysisTests.cs

示例3: MockCompletionDB

 public MockCompletionDB(string path, PythonLanguageVersion version) {
     DBPath = path;
     LanguageVersion = version;
     _factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion(), null, DBPath);
     Directory.CreateDirectory(DBPath);
 }
开发者ID:wenh123,项目名称:PTVS,代码行数:6,代码来源:MockCompletionDB.cs

示例4: PythonEditor

        public PythonEditor(
            string content = null,
            PythonLanguageVersion version = PythonLanguageVersion.V27,
            MockVs vs = null,
            IPythonInterpreterFactory factory = null,
            VsProjectAnalyzer analyzer = null,
            string filename = null
        ) {
            if (vs == null) {
                _disposeVS = true;
                vs = new MockVs();
            }
            MockVsTextView view = null;
            try {
                AdvancedOptions = vs.GetPyService().AdvancedOptions;
                AdvancedOptions.AutoListMembers = true;
                AdvancedOptions.AutoListIdentifiers = false;

                if (factory == null) {
                    _disposeFactory = true;
                    factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
                }
                if (analyzer == null) {
                    _disposeAnalyzer = true;
                    analyzer = new VsProjectAnalyzer(vs.ServiceProvider, factory);
                    var task = analyzer.ReloadTask;
                    if (task != null) {
                        task.WaitAndUnwrapExceptions();
                    }
                }

                var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
                using (var mre = new ManualResetEventSlim()) {
                    EventHandler evt = (s, e) => mre.Set();
                    analyzer.AnalysisStarted += evt;
                    view = vs.CreateTextView(PythonCoreConstants.ContentType, content ?? "", v => {
                        v.TextView.TextBuffer.Properties.AddProperty(typeof(VsProjectAnalyzer), analyzer);
                    }, filename);

                    try {
                        mre.Wait(cts.Token);
                        analyzer.WaitForCompleteAnalysis(x => !cts.IsCancellationRequested);
                    } catch (OperationCanceledException) {
                    } finally {
                        analyzer.AnalysisStarted -= evt;
                    }
                    if (cts.IsCancellationRequested) {
                        Assert.Fail("Timed out waiting for code analysis");
                    }
                }

                View = view;
                view = null;
                Analyzer = analyzer;
                analyzer = null;
                Factory = factory;
                factory = null;
                VS = vs;
                vs = null;
            } finally {
                if (view != null) {
                    view.Dispose();
                }
                if (analyzer != null && _disposeAnalyzer) {
                    analyzer.Dispose();
                }
                if (factory != null && _disposeFactory) {
                    var disp = factory as IDisposable;
                    if (disp != null) {
                        disp.Dispose();
                    }
                }
                if (vs != null && _disposeVS) {
                    vs.Dispose();
                }
            }
        }
开发者ID:RussBaz,项目名称:PTVS,代码行数:77,代码来源:PythonEditor.cs

示例5: CreateAnalyzer

        public PythonAnalyzer CreateAnalyzer(PythonLanguageVersion version = PythonLanguageVersion.V27, string[] analysisDirs = null) {
            // Explicitly provide the builtins name, since we aren't recreating
            // the interpreter for each version like we should be.
            var fact = InterpreterFactory;
            var interp = Interpreter;
            var builtinsName = "__builtin__";
            if (version != fact.GetLanguageVersion()) {
                fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
                interp = fact.CreateInterpreter();
                builtinsName = null;
            }
            var state = PythonAnalyzer.CreateSynchronously(fact, interp, builtinsName);

            if (ShouldUseUnicodeLiterals(version)) {
                var types = (KnownTypes)state.Types;
                types._types[(int)BuiltinTypeId.Str] = state.Types[BuiltinTypeId.Unicode];
                types._types[(int)BuiltinTypeId.StrIterator] = state.Types[BuiltinTypeId.UnicodeIterator];
                types._classInfos[(int)BuiltinTypeId.Str] = state.ClassInfos[BuiltinTypeId.Unicode];
                types._classInfos[(int)BuiltinTypeId.StrIterator] = state.ClassInfos[BuiltinTypeId.UnicodeIterator];
            }

            state.Limits = GetLimits();
            if (analysisDirs != null) {
                foreach (var dir in analysisDirs) {
                    state.AddAnalysisDirectory(dir);
                }
            }

            return state;
        }
开发者ID:RussBaz,项目名称:PTVS,代码行数:30,代码来源:BaseAnalysisTest.cs

示例6: AnalyzeDir

        internal PythonAnalyzer AnalyzeDir(string dir, PythonLanguageVersion version = PythonLanguageVersion.V27, IEnumerable<string> excludeDirectories = null, CancellationToken? cancel = null) {
            List<string> files = new List<string>();
            try {
                ISet<string> excluded = null;
                if (excludeDirectories != null) {
                    excluded = new HashSet<string>(excludeDirectories, StringComparer.InvariantCultureIgnoreCase);
                }
                CollectFiles(dir, files, excluded);
            } catch (DirectoryNotFoundException) {
                return null;
            }

            List<FileStreamReader> sourceUnits = new List<FileStreamReader>();
            foreach (string file in files) {
                sourceUnits.Add(
                    new FileStreamReader(file)
                );
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            long start0 = sw.ElapsedMilliseconds;
            // Explicitly specify the builtins name because we are using a 2.7
            // interpreter for all versions.
            var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
            var projectState = new PythonAnalyzer(fact, fact.CreateInterpreter(), "__builtin__");
            projectState.ReloadModulesAsync().WaitAndUnwrapExceptions();

            projectState.Limits = AnalysisLimits.GetStandardLibraryLimits();

            var modules = new List<IPythonProjectEntry>();
            foreach (var sourceUnit in sourceUnits) {
                try {
                    modules.Add(projectState.AddModule(
                        ModulePath.FromFullPath(sourceUnit.Path).ModuleName,
                        sourceUnit.Path,
                        null
                    ));
                } catch (ArgumentException) {
                    // Invalid module name, so skip the module
                }
            }
            long start1 = sw.ElapsedMilliseconds;
            Trace.TraceInformation("AddSourceUnit: {0} ms", start1 - start0);

            var nodes = new List<Microsoft.PythonTools.Parsing.Ast.PythonAst>();
            for (int i = 0; i < modules.Count; i++) {
                PythonAst ast = null;
                try {
                    var sourceUnit = sourceUnits[i];

                    ast = Parser.CreateParser(sourceUnit, version).ParseFile();
                } catch (Exception) {
                }
                nodes.Add(ast);
            }
            long start2 = sw.ElapsedMilliseconds;
            Trace.TraceInformation("Parse: {0} ms", start2 - start1);

            for (int i = 0; i < modules.Count; i++) {
                var ast = nodes[i];

                if (ast != null) {
                    modules[i].UpdateTree(ast, null);
                }
            }

            long start3 = sw.ElapsedMilliseconds;
            for (int i = 0; i < modules.Count; i++) {
                Trace.TraceInformation("Analyzing {1}: {0} ms", sw.ElapsedMilliseconds - start3, sourceUnits[i].Path);
                var ast = nodes[i];
                if (ast != null) {
                    modules[i].Analyze(cancel ?? CancellationToken.None, true);
                }
            }
            if (modules.Count > 0) {
                Trace.TraceInformation("Analyzing queue");
                modules[0].AnalysisGroup.AnalyzeQueuedEntries(cancel ?? CancellationToken.None);
            }

            long start4 = sw.ElapsedMilliseconds;
            Trace.TraceInformation("Analyze: {0} ms", start4 - start3);
            return projectState;
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:85,代码来源:AnalysisTest.Perf.cs

示例7: FallbackBuiltinPythonType

 public FallbackBuiltinPythonType(PythonLanguageVersion version, BuiltinTypeId typeId) {
     DeclaringModule = version.Is3x() ? FallbackBuiltinModule.Instance3x : FallbackBuiltinModule.Instance2x;
     Name = SharedDatabaseState.GetBuiltinTypeName(typeId, version.ToVersion());
     TypeId = typeId;
 }
开发者ID:jsschultz,项目名称:PTVS,代码行数:5,代码来源:KnownTypes.cs

示例8: GetJythonVersion

        private static PythonVersion GetJythonVersion(PythonLanguageVersion version) {
            var candidates = new List<DirectoryInfo>();
            var ver = version.ToVersion();
            var path1 = string.Format("jython{0}{1}*", ver.Major, ver.Minor);
            var path2 = string.Format("jython{0}.{1}*", ver.Major, ver.Minor);
            foreach (var drive in DriveInfo.GetDrives()) {
                if (drive.DriveType != DriveType.Fixed) {
                    continue;
                }

                try {
                    candidates.AddRange(drive.RootDirectory.EnumerateDirectories(path1));
                    candidates.AddRange(drive.RootDirectory.EnumerateDirectories(path2));
                } catch {
                }
            }

            foreach (var dir in candidates) {
                var interpreter = dir.EnumerateFiles("jython.bat").FirstOrDefault();
                if (interpreter == null) {
                    continue;
                }
                var libPath = dir.EnumerateDirectories("Lib").FirstOrDefault();
                if (libPath == null || !libPath.EnumerateFiles("site.py").Any()) {
                    continue;
                }
                return new PythonVersion(new InterpreterConfiguration(
                    CPythonInterpreterFactoryConstants.GetInterpreterId(
                        "Jython",
                        version.ToVersion().ToString()
                    ),
                    string.Format("Jython {0}", version.ToVersion()),
                    dir.FullName,
                    interpreter.FullName,
                    version: version.ToVersion()
                ));
            }
            return null;
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:39,代码来源:PythonPaths.cs

示例9: GetCPythonVersion

        private static PythonVersion GetCPythonVersion(PythonLanguageVersion version, InterpreterArchitecture arch) {
            var res = _foundInRegistry.FirstOrDefault(ii => 
                ii.Configuration.Id.StartsWith("Global|PythonCore|") &&
                ii.Configuration.Architecture == arch &&
                ii.Configuration.Version == version.ToVersion()
            );
            if (res != null) {
                return new PythonVersion(res.Configuration, cPython: true);
            }

            var ver = version.ToVersion();
            var tag = ver + (arch == InterpreterArchitecture.x86 ? "-32" : "");
            foreach (var path in new[] {
                string.Format("Python{0}{1}", ver.Major, ver.Minor),
                string.Format("Python{0}{1}_{2}", ver.Major, ver.Minor, arch.ToString("x")),
                string.Format("Python{0}{1}-{2}", ver.Major, ver.Minor, arch.ToString("#")),
                string.Format("Python{0}{1}_{2}", ver.Major, ver.Minor, arch.ToString("#")),
            }) {
                var prefixPath = Path.Combine(Environment.GetEnvironmentVariable("SystemDrive"), "\\", path);
                var exePath = Path.Combine(prefixPath, CPythonInterpreterFactoryConstants.ConsoleExecutable);
                var procArch = (arch == InterpreterArchitecture.x86) ? ProcessorArchitecture.X86 :
                    (arch == InterpreterArchitecture.x64) ? ProcessorArchitecture.Amd64 :
                    ProcessorArchitecture.None;

                if (procArch == Microsoft.PythonTools.Infrastructure.NativeMethods.GetBinaryType(path)) {
                    return new PythonVersion(new InterpreterConfiguration(
                        CPythonInterpreterFactoryConstants.GetInterpreterId("PythonCore", tag),
                        "Python {0} {1}".FormatInvariant(arch, ver),
                        prefixPath,
                        exePath,
                        pathVar: CPythonInterpreterFactoryConstants.PathEnvironmentVariableName,
                        arch: arch,
                        version: ver
                    ));
                }
            }
            return null;
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:38,代码来源:PythonPaths.cs

示例10: SaveLoad

        private SaveLoadResult SaveLoad(PythonLanguageVersion version, params AnalysisModule[] modules) {
            IPythonProjectEntry[] entries = new IPythonProjectEntry[modules.Length];

            var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
            var interp = fact.CreateInterpreter();

            var dbFolder = TestData.GetTempPath(randomSubPath: true);
            Directory.CreateDirectory(dbFolder);

            var state = new PythonAnalysis(fact, interp, SharedDatabaseState.BuiltinName2x);
            state.CreateProjectOnDisk = true;
            for (int i = 0; i < modules.Length; i++) {
                state.AddModule(modules[i].ModuleName, modules[i].Code, modules[i].Filename);
            }

            state.WaitForAnalysis();

            new SaveAnalysis().Save(state.Analyzer, dbFolder);

            File.Copy(
                Path.Combine(PythonTypeDatabase.BaselineDatabasePath, "__builtin__.idb"),
                Path.Combine(dbFolder, "__builtin__.idb"),
                true
            );

            var loadFactory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(
                version.ToVersion(),
                null,
                dbFolder
            );
            return new SaveLoadResult(CreateAnalyzer(loadFactory), state.CodeFolder);
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:32,代码来源:AnalysisSaveTest.cs

示例11: ProcessText

        public PythonAnalysis ProcessText(
            string text,
            PythonLanguageVersion version = PythonLanguageVersion.None,
            bool allowParseErrors = false
        ) {
            // TODO: Analyze against multiple versions when the version is None
            if (version == PythonLanguageVersion.None) {
                return ProcessTextV2(text, allowParseErrors);
            }

            var analysis = CreateAnalyzer(InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion()), allowParseErrors);
            analysis.AddModule("test-module", text);
            analysis.WaitForAnalysis();
            return analysis;
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:15,代码来源:BaseAnalysisTest.cs


注:本文中的PythonLanguageVersion.ToVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。