Esempio n. 1
0
        private async Task <PythonAnalyzer> CreateAnalyzer(PythonInitializationOptions.Interpreter interpreter)
        {
            var factory = ActivateObject <IPythonInterpreterFactory>(interpreter.assembly, interpreter.typeName, interpreter.properties)
                          ?? new AstPythonInterpreterFactory(interpreter.properties);

            var interp = factory.CreateInterpreter();

            if (interp == null)
            {
                throw new InvalidOperationException("Failed to create interpreter");
            }

            LogMessage(MessageType.Info, $"Created {interp.GetType().FullName} instance from {factory.GetType().FullName}");

            return(await PythonAnalyzer.CreateAsync(factory, interp));
        }
Esempio n. 2
0
        private async Task <PythonAnalyzer> CreateAnalyzer(PythonInitializationOptions.Interpreter interpreter)
        {
            IPythonInterpreterFactory factory = null;

            if (!string.IsNullOrEmpty(interpreter.assembly) && !string.IsNullOrEmpty(interpreter.typeName))
            {
                try {
                    var assembly = File.Exists(interpreter.assembly) ? AssemblyName.GetAssemblyName(interpreter.assembly) : new AssemblyName(interpreter.assembly);
                    var type     = Assembly.Load(assembly).GetType(interpreter.typeName, true);

                    factory = (IPythonInterpreterFactory)Activator.CreateInstance(
                        type,
                        BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
                        null,
                        new object[] { interpreter.properties },
                        CultureInfo.CurrentCulture
                        );
                } catch (Exception ex) {
                    LogMessage(MessageType.Warning, ex.ToString());
                }
            }
            else
            {
                factory = new AstPythonInterpreterFactory(interpreter.properties);
            }

            if (factory == null)
            {
                Version v;
                if (!Version.TryParse(interpreter.version ?? "0.0", out v))
                {
                    v = new Version();
                }
                factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(v);
            }

            var interp = factory.CreateInterpreter();

            if (interp == null)
            {
                throw new InvalidOperationException("Failed to create interpreter");
            }

            LogMessage(MessageType.Info, $"Created {interp.GetType().FullName} instance from {factory.GetType().FullName}");

            return(await PythonAnalyzer.CreateAsync(factory, interp));
        }
Esempio n. 3
0
        private async Task <PythonAnalyzer> CreateAnalyzer(PythonInitializationOptions.Interpreter interpreter, CancellationToken token)
        {
            var factory = ActivateObject <IPythonInterpreterFactory>(interpreter.assembly, interpreter.typeName, interpreter.properties)
                          ?? new AstPythonInterpreterFactory(interpreter.properties);

            var interp = factory.CreateInterpreter();

            if (interp == null)
            {
                throw new InvalidOperationException("Failed to create interpreter");
            }

            LogMessage(MessageType.Info, $"Created {interp.GetType().FullName} instance from {factory.GetType().FullName}");

            var analyzer = await PythonAnalyzer.CreateAsync(factory, interp, token);

#if DEBUG
            // Make Deque aware of the only thread that should be modifying its state
            analyzer.Queue.SynchronizationContext = _queue.SynchronizationContext;
#endif
            return(analyzer);
        }