static void Main(string[] args) { var responseFile = Path.GetFullPath(args.FirstOrDefault() ?? "AnalysisMemoryTester.rsp"); if (!File.Exists(responseFile)) { if (!string.IsNullOrEmpty(responseFile)) { Console.WriteLine("Could not open {0}", responseFile); } else { Console.WriteLine("No response file specified"); } PrintUsage(); return; } var commands = File.ReadAllLines(responseFile) .Select(line => line.Trim()) .ToList(); Environment.CurrentDirectory = Path.GetDirectoryName(responseFile); var interpreter = GetFirstCommand(commands, "python\\s+(\\d\\.\\d)\\s+(.+)", m => m.Value, v => v.Length > 4 && File.Exists(v.Substring(4).Trim())); var version = Version.Parse(interpreter.Substring(0, 3)); interpreter = interpreter.Substring(4).Trim(); Console.WriteLine($"Using Python from {interpreter}"); var config = new InterpreterConfiguration( "Python|" + interpreter, interpreter, Path.GetDirectoryName(interpreter), interpreter, interpreter, "PYTHONPATH", NativeMethods.GetBinaryType(interpreter) == System.Reflection.ProcessorArchitecture.Amd64 ? InterpreterArchitecture.x64 : InterpreterArchitecture.x86, version ); using (var factory = new Interpreter.Ast.AstPythonInterpreterFactory(config, new InterpreterFactoryCreationOptions())) using (var analyzer = PythonAnalyzer.CreateAsync(factory).WaitAndUnwrapExceptions()) { var modules = new Dictionary <string, IPythonProjectEntry>(); var state = new State(); foreach (var tuple in SplitCommands(commands)) { RunCommand( tuple.Item1, tuple.Item2, analyzer, modules, state ); } } }
static void Main(string[] args) { var responseFile = Path.GetFullPath(args.FirstOrDefault() ?? "AnalysisMemoryTester.rsp"); if (!File.Exists(responseFile)) { if (!string.IsNullOrEmpty(responseFile)) { Console.WriteLine("Could not open {0}", responseFile); } else { Console.WriteLine("No response file specified"); } PrintUsage(); return; } var commands = File.ReadAllLines(responseFile) .Select(line => line.Trim()) .ToList(); Environment.CurrentDirectory = Path.GetDirectoryName(responseFile); var interpreter = GetFirstCommand(commands, "python\\s+(\\d\\.\\d)\\s+(.+)", m => m.Groups[1].Value + " " + m.Groups[2].Value, v => v.Length > 4 && File.Exists(v.Substring(4).Trim())); var version = Version.Parse(interpreter.Substring(0, 3)); interpreter = interpreter.Substring(4).Trim(); Console.WriteLine($"Using Python from {interpreter}"); var logs = GetFirstCommand(commands, "logs\\s+(.+)", m => m.Groups[1].Value, v => PathUtils.IsValidPath(v.Trim())); if (!string.IsNullOrEmpty(logs)) { if (!Path.IsPathRooted(logs)) { logs = Path.GetFullPath(logs); } Directory.CreateDirectory(logs); AnalysisLog.Output = Path.Combine(logs, "Detailed.csv"); AnalysisLog.AsCSV = true; } var config = new InterpreterConfiguration( "Python|" + interpreter, interpreter, Path.GetDirectoryName(interpreter), interpreter, interpreter, "PYTHONPATH", NativeMethods.GetBinaryType(interpreter) == System.Reflection.ProcessorArchitecture.Amd64 ? InterpreterArchitecture.x64 : InterpreterArchitecture.x86, version ); var creationOpts = new InterpreterFactoryCreationOptions { UseExistingCache = false, WatchFileSystem = false, TraceLevel = TraceLevel.Verbose }; if (!string.IsNullOrEmpty(logs)) { creationOpts.DatabasePath = logs; } using (var factory = new Interpreter.Ast.AstPythonInterpreterFactory(config, creationOpts)) using (var analyzer = PythonAnalyzer.CreateAsync(factory).WaitAndUnwrapExceptions()) { var modules = new Dictionary <string, IPythonProjectEntry>(); var state = new State(); foreach (var tuple in SplitCommands(commands)) { RunCommand( tuple.Item1, tuple.Item2, analyzer, modules, state ); } } }