public CommandResult Execute(
            Script script,
            CalamariVariableDictionary variables,
            ICommandLineRunner commandLineRunner,
            Dictionary <string, string> environmentVars = null)
        {
            var executable       = PythonBootstrapper.FindPythonExecutable();
            var workingDirectory = Path.GetDirectoryName(script.File);

            var dependencyInstallerFile      = PythonBootstrapper.PrepareDependencyInstaller(workingDirectory);
            var dependencyInstallerArguments = PythonBootstrapper.FormatCommandArguments(dependencyInstallerFile, string.Empty);

            using (new TemporaryFile(dependencyInstallerFile))
            {
                var result = commandLineRunner.Execute(new CommandLineInvocation(executable, dependencyInstallerArguments,
                                                                                 workingDirectory,
                                                                                 environmentVars));

                if (result.ExitCode != 0)
                {
                    return(result);
                }
            }

            var configurationFile = PythonBootstrapper.PrepareConfigurationFile(workingDirectory, variables);
            var bootstrapFile     = PythonBootstrapper.PrepareBootstrapFile(script, workingDirectory, configurationFile);
            var arguments         = PythonBootstrapper.FormatCommandArguments(bootstrapFile, script.Parameters);

            using (new TemporaryFile(configurationFile))
                using (new TemporaryFile(bootstrapFile))
                {
                    return(commandLineRunner.Execute(new CommandLineInvocation(executable, arguments, workingDirectory,
                                                                               environmentVars)));
                }
        }
Exemple #2
0
        protected override IEnumerable <ScriptExecution> PrepareExecution(Script script, IVariables variables,
                                                                          Dictionary <string, string> environmentVars = null)
        {
            var executable       = PythonBootstrapper.FindPythonExecutable();
            var workingDirectory = Path.GetDirectoryName(script.File);

            var dependencyInstallerFile      = PythonBootstrapper.PrepareDependencyInstaller(workingDirectory);
            var dependencyInstallerArguments = PythonBootstrapper.FormatCommandArguments(dependencyInstallerFile, string.Empty);

            yield return(new ScriptExecution(
                             new CommandLineInvocation(executable, dependencyInstallerArguments)
            {
                WorkingDirectory = workingDirectory,
                EnvironmentVars = environmentVars,
                Isolate = true
            },
                             new[] { dependencyInstallerFile }));

            var configurationFile = PythonBootstrapper.PrepareConfigurationFile(workingDirectory, variables);

            var(bootstrapFile, otherTemporaryFiles) = PythonBootstrapper.PrepareBootstrapFile(script, workingDirectory, configurationFile, variables);
            var arguments = PythonBootstrapper.FormatCommandArguments(bootstrapFile, script.Parameters);

            yield return(new ScriptExecution(
                             new CommandLineInvocation(executable, arguments)
            {
                WorkingDirectory = workingDirectory,
                EnvironmentVars = environmentVars
            },
                             otherTemporaryFiles.Concat(new[] { bootstrapFile, configurationFile })));
        }