private string GetInterpreterExecutableInternal(out bool isWindows) { if (!Boolean.TryParse(_project.GetProperty(CommonConstants.IsWindowsApplication) ?? Boolean.FalseString, out isWindows)) { isWindows = false; } string result; result = (_project.GetProperty(PythonConstants.InterpreterPathSetting) ?? string.Empty).Trim(); if (!String.IsNullOrEmpty(result)) { result = CommonUtils.GetAbsoluteFilePath(_project.ProjectDirectory, result); if (!File.Exists(result)) { throw new FileNotFoundException(String.Format("Interpreter specified in the project does not exist: '{0}'", result), result); } return(result); } var interpreter = _project.GetInterpreterFactory(); var interpreterService = _serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>(); if (interpreterService == null || interpreterService.NoInterpretersValue == interpreter) { throw new NoInterpretersException(); } return(!isWindows ? interpreter.Configuration.InterpreterPath : interpreter.Configuration.WindowsInterpreterPath); }
private IEnumerable <string> GetProjectDebuggerOptions() { var factory = _project.GetInterpreterFactory(); yield return(string.Format("{0}={1}", AD7Engine.VersionSetting, factory.Configuration.Version)); yield return(string.Format("{0}={1}", AD7Engine.InterpreterOptions, _project.GetProperty(PythonConstants.InterpreterArgumentsSetting) ?? string.Empty )); var url = GetFullUrl(); if (!String.IsNullOrWhiteSpace(url)) { yield return(string.Format("{0}={1}", AD7Engine.WebBrowserUrl, HttpUtility.UrlEncode(url))); } // Check project type GUID and enable the Django-specific features // of the debugger if required. var projectGuids = _project.GetUnevaluatedProperty("ProjectTypeGuids") ?? ""; // HACK: Literal GUID string to avoid introducing Django-specific public API // We don't want to expose a constant from PythonTools.dll. // TODO: Add generic breakpoint extension point // to avoid having to pass this property for Django and any future // extensions. if (projectGuids.IndexOf("5F0BE9CA-D677-4A4D-8806-6076C0FAAD37", StringComparison.OrdinalIgnoreCase) >= 0) { yield return(AD7Engine.EnableDjangoDebugging + "=True"); } }
private string GetInterpreterPath(bool isWindows) { string result; result = (_project.GetProperty(PythonConstants.InterpreterPathSetting) ?? string.Empty).Trim(); if (!String.IsNullOrEmpty(result)) { result = CommonUtils.GetAbsoluteFilePath(_project.ProjectDirectory, result); if (!File.Exists(result)) { throw new FileNotFoundException(SR.GetString(SR.DebugLaunchInterpreterMissing_Path, result)); } return(result); } IPythonInterpreterFactory factory; var ipp3 = _project as IPythonProject3; if (ipp3 != null) { factory = ipp3.GetInterpreterFactoryOrThrow(); } else { factory = _project.GetInterpreterFactory(); if (factory == null) { throw new NoInterpretersException(); } var interpreterService = _serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>(); if (interpreterService == null || factory == interpreterService.NoInterpretersValue) { throw new NoInterpretersException(); } } return(isWindows ? factory.Configuration.WindowsInterpreterPath : factory.Configuration.InterpreterPath); }
/// <summary> /// Sets up debugger information. /// </summary> private void SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile) { dbgInfo.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; bool isWindows; dbgInfo.bstrExe = GetInterpreterExecutableInternal(out isWindows); dbgInfo.bstrCurDir = _project.GetWorkingDirectory(); dbgInfo.bstrArg = CreateCommandLineDebug(startupFile); dbgInfo.bstrRemoteMachine = null; dbgInfo.fSendStdoutToOutputWindow = 0; StringDictionary env = new StringDictionary(); dbgInfo.bstrOptions = AD7Engine.VersionSetting + "=" + _project.GetInterpreterFactory().GetLanguageVersion().ToString(); if (!isWindows && PythonToolsPackage.Instance.OptionsPage.WaitOnExit) { dbgInfo.bstrOptions += ";" + AD7Engine.WaitOnAbnormalExitSetting + "=True"; } SetupEnvironment(env); if (env.Count > 0) { // add any inherited env vars var variables = Environment.GetEnvironmentVariables(); foreach (var key in variables.Keys) { string strKey = (string)key; if (!env.ContainsKey(strKey)) { env.Add(strKey, (string)variables[key]); } } //Environemnt variables should be passed as a //null-terminated block of null-terminated strings. //Each string is in the following form:name=value\0 StringBuilder buf = new StringBuilder(); foreach (DictionaryEntry entry in env) { buf.AppendFormat("{0}={1}\0", entry.Key, entry.Value); } buf.Append("\0"); dbgInfo.bstrEnv = buf.ToString(); } // Set the Python debugger dbgInfo.clsidCustom = new Guid(AD7Engine.DebugEngineId); dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd; }
private string GetInterpreterPath(IPythonProject project, bool isWindows) { var factory = project.GetInterpreterFactory(); if (factory == null) { throw new NoInterpretersException(); } var interpreterService = _serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>(); if (interpreterService == null || factory == interpreterService.NoInterpretersValue) { throw new NoInterpretersException(); } return(isWindows ? factory.Configuration.WindowsInterpreterPath : factory.Configuration.InterpreterPath); }
public static IPythonProjectLaunchProperties Create( IPythonProject project, IServiceProvider site, IProjectLaunchProperties properties ) { var res = properties as IPythonProjectLaunchProperties; if (res != null) { return res; } res = project as IPythonProjectLaunchProperties; if (res != null) { // This should be the common case, as we implement // IPythonProjectLaunchProperties on our project. return res; } // Backwards compatibility shim to handle project implementations // that omit IPythonProjectLaunchProperties. string arguments, workingDir; Dictionary<string, string> environment, environmentWithPaths; properties = properties ?? (project as IProjectLaunchProperties); if (properties != null) { arguments = properties.GetArguments(); workingDir = properties.GetWorkingDirectory(); environment = new Dictionary<string, string>(properties.GetEnvironment(false)); environmentWithPaths = new Dictionary<string, string>(properties.GetEnvironment(true)); } else { arguments = project.GetProperty(CommonConstants.CommandLineArguments); workingDir = project.GetWorkingDirectory(); environment = ParseEnvironment(project.GetProperty(PythonConstants.EnvironmentSetting)); environmentWithPaths = new Dictionary<string, string>(environment); AddSearchPaths(environmentWithPaths, project, site); } string strValue; bool boolValue; bool? isWindowsApplication = null; strValue = project.GetProperty(PythonConstants.IsWindowsApplicationSetting); if (bool.TryParse(strValue, out boolValue)) { isWindowsApplication = boolValue; } IPythonInterpreterFactory interpreter; var ipp3 = project as IPythonProject3; if (ipp3 != null) { interpreter = ipp3.GetInterpreterFactoryOrThrow(); } else { interpreter = project.GetInterpreterFactory(); var service = site.GetComponentModel().GetService<IInterpreterOptionsService>(); if (service == null || interpreter == service.NoInterpretersValue) { throw new NoInterpretersException(); } } var interpreterPath = (isWindowsApplication ?? false) ? interpreter.Configuration.WindowsInterpreterPath : interpreter.Configuration.InterpreterPath; var interpreterArguments = project.GetProperty(PythonConstants.InterpreterArgumentsSetting); bool? isNativeDebugging = null; strValue = project.GetProperty(PythonConstants.EnableNativeCodeDebugging); if (bool.TryParse(strValue, out boolValue)) { isNativeDebugging = boolValue; } return new PythonProjectLaunchProperties( arguments, workingDir, environment, environmentWithPaths, interpreterPath, interpreterArguments, isWindowsApplication, isNativeDebugging ); }
public static IPythonProjectLaunchProperties Create( IPythonProject project, IServiceProvider site, IProjectLaunchProperties properties ) { var res = properties as IPythonProjectLaunchProperties; if (res != null) { return(res); } res = project as IPythonProjectLaunchProperties; if (res != null) { // This should be the common case, as we implement // IPythonProjectLaunchProperties on our project. return(res); } // Backwards compatibility shim to handle project implementations // that omit IPythonProjectLaunchProperties. string arguments, workingDir; Dictionary <string, string> environment, environmentWithPaths; properties = properties ?? (project as IProjectLaunchProperties); if (properties != null) { arguments = properties.GetArguments(); workingDir = properties.GetWorkingDirectory(); environment = new Dictionary <string, string>(properties.GetEnvironment(false)); environmentWithPaths = new Dictionary <string, string>(properties.GetEnvironment(true)); } else { arguments = project.GetProperty(CommonConstants.CommandLineArguments); workingDir = project.GetWorkingDirectory(); environment = ParseEnvironment(project.GetProperty(PythonConstants.EnvironmentSetting)); environmentWithPaths = new Dictionary <string, string>(environment); AddSearchPaths(environmentWithPaths, project, site); } string strValue; bool boolValue; bool? isWindowsApplication = null; strValue = project.GetProperty(PythonConstants.IsWindowsApplicationSetting); if (bool.TryParse(strValue, out boolValue)) { isWindowsApplication = boolValue; } IPythonInterpreterFactory interpreter; var ipp3 = project as IPythonProject3; if (ipp3 != null) { interpreter = ipp3.GetInterpreterFactoryOrThrow(); } else { interpreter = project.GetInterpreterFactory(); var service = site.GetComponentModel().GetService <IInterpreterOptionsService>(); if (service == null || interpreter == service.NoInterpretersValue) { throw new NoInterpretersException(); } } var interpreterPath = (isWindowsApplication ?? false) ? interpreter.Configuration.WindowsInterpreterPath : interpreter.Configuration.InterpreterPath; var interpreterArguments = project.GetProperty(PythonConstants.InterpreterArgumentsSetting); bool?isNativeDebugging = null; strValue = project.GetProperty(PythonConstants.EnableNativeCodeDebugging); if (bool.TryParse(strValue, out boolValue)) { isNativeDebugging = boolValue; } return(new PythonProjectLaunchProperties( arguments, workingDir, environment, environmentWithPaths, interpreterPath, interpreterArguments, isWindowsApplication, isNativeDebugging )); }
/// <summary> /// Sets up debugger information. /// </summary> private unsafe void SetupDebugInfo( ref VsDebugTargetInfo dbgInfo, string startupFile, IPythonProjectLaunchProperties props ) { bool enableNativeCodeDebugging = false; dbgInfo.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; dbgInfo.bstrExe = props.GetInterpreterPath(); dbgInfo.bstrCurDir = props.GetWorkingDirectory(); dbgInfo.bstrArg = CreateCommandLineDebug(startupFile, props); dbgInfo.bstrRemoteMachine = null; dbgInfo.fSendStdoutToOutputWindow = 0; if (!enableNativeCodeDebugging) { string interpArgs = _project.GetProperty(PythonConstants.InterpreterArgumentsSetting); dbgInfo.bstrOptions = AD7Engine.VersionSetting + "=" + _project.GetInterpreterFactory().GetLanguageVersion().ToString(); if (!(props.GetIsWindowsApplication() ?? false)) { if (_pyService.DebuggerOptions.WaitOnAbnormalExit) { dbgInfo.bstrOptions += ";" + AD7Engine.WaitOnAbnormalExitSetting + "=True"; } if (_pyService.DebuggerOptions.WaitOnNormalExit) { dbgInfo.bstrOptions += ";" + AD7Engine.WaitOnNormalExitSetting + "=True"; } } if (_pyService.DebuggerOptions.TeeStandardOutput) { dbgInfo.bstrOptions += ";" + AD7Engine.RedirectOutputSetting + "=True"; } if (_pyService.DebuggerOptions.BreakOnSystemExitZero) { dbgInfo.bstrOptions += ";" + AD7Engine.BreakSystemExitZero + "=True"; } if (_pyService.DebuggerOptions.DebugStdLib) { dbgInfo.bstrOptions += ";" + AD7Engine.DebugStdLib + "=True"; } if (!String.IsNullOrWhiteSpace(interpArgs)) { dbgInfo.bstrOptions += ";" + AD7Engine.InterpreterOptions + "=" + interpArgs.Replace(";", ";;"); } var djangoDebugging = _project.GetProperty("DjangoDebugging"); bool enableDjango; if (!String.IsNullOrWhiteSpace(djangoDebugging) && Boolean.TryParse(djangoDebugging, out enableDjango)) { dbgInfo.bstrOptions += ";" + AD7Engine.EnableDjangoDebugging + "=True"; } } var env = new Dictionary <string, string>(props.GetEnvironment(true)); PythonProjectLaunchProperties.MergeEnvironmentBelow(env, null, true); if (env.Any()) { //Environment variables should be passed as a //null-terminated block of null-terminated strings. //Each string is in the following form:name=value\0 var buf = new StringBuilder(); foreach (var kv in env) { buf.AppendFormat("{0}={1}\0", kv.Key, kv.Value); } buf.Append("\0"); dbgInfo.bstrEnv = buf.ToString(); } if (props.GetIsNativeDebuggingEnabled() ?? false) { dbgInfo.dwClsidCount = 2; dbgInfo.pClsidList = Marshal.AllocCoTaskMem(sizeof(Guid) * 2); var engineGuids = (Guid *)dbgInfo.pClsidList; engineGuids[0] = dbgInfo.clsidCustom = DkmEngineId.NativeEng; engineGuids[1] = AD7Engine.DebugEngineGuid; } else { // Set the Python debugger dbgInfo.clsidCustom = new Guid(AD7Engine.DebugEngineId); dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd; } }