Esempio n. 1
0
        public CommandStartInfo GetStartInfo(IPythonProject2 project)
        {
            var outputs = BuildTarget(project, _target);
            var config  = PythonProjectLaunchProperties.Create(project);

            var item = outputs.Values
                       .SelectMany(result => result.Items)
                       .FirstOrDefault(i =>
                                       !string.IsNullOrEmpty(i.ItemSpec) &&
                                       !string.IsNullOrEmpty(i.GetMetadata(BuildTasks.CreatePythonCommandItem.TargetTypeKey))
                                       );

            if (item == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.ErrorBuildingCustomCommand, _target));
            }

            var startInfo = new CommandStartInfo {
                Filename             = item.ItemSpec,
                Arguments            = item.GetMetadata(BuildTasks.CreatePythonCommandItem.ArgumentsKey),
                WorkingDirectory     = item.GetMetadata(BuildTasks.CreatePythonCommandItem.WorkingDirectoryKey),
                EnvironmentVariables = PythonProjectLaunchProperties.ParseEnvironment(item.GetMetadata(BuildTasks.CreatePythonCommandItem.EnvironmentKey)),
                TargetType           = item.GetMetadata(BuildTasks.CreatePythonCommandItem.TargetTypeKey),
                ExecuteIn            = item.GetMetadata(BuildTasks.CreatePythonCommandItem.ExecuteInKey),
                RequiredPackages     = item.GetMetadata(BuildTasks.CreatePythonCommandItem.RequiredPackagesKey).Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
            };

            try {
                startInfo.WorkingDirectory = CommonUtils.GetAbsoluteFilePath(project.ProjectHome, startInfo.WorkingDirectory);
            } catch (ArgumentException) {
            }

            string errorRegex = item.GetMetadata(BuildTasks.CreatePythonCommandItem.ErrorRegexKey);

            if (!string.IsNullOrEmpty(errorRegex))
            {
                startInfo.ErrorRegex = new Regex(errorRegex);
            }

            string warningRegex = item.GetMetadata(BuildTasks.CreatePythonCommandItem.WarningRegexKey);

            if (!string.IsNullOrEmpty(warningRegex))
            {
                startInfo.WarningRegex = new Regex(warningRegex);
            }

            startInfo.EnvironmentVariables["PYTHONUNBUFFERED"] = "1";
            startInfo.AddPropertiesAfter(PythonProjectLaunchProperties.Create(project));

            Debug.Assert(!string.IsNullOrEmpty(startInfo.WorkingDirectory));
            Debug.Assert(Path.IsPathRooted(startInfo.WorkingDirectory));

            return(startInfo);
        }
Esempio n. 2
0
        public int LaunchFile(string file, bool debug, IProjectLaunchProperties props)
        {
            if (debug)
            {
                StartWithDebugger(file, PythonProjectLaunchProperties.Create(_project, _serviceProvider, props));
            }
            else
            {
                StartWithoutDebugger(file, PythonProjectLaunchProperties.Create(_project, _serviceProvider, props));
            }

            return(VSConstants.S_OK);
        }