@TaskAction public final void generate() { getProject().exec(execSpec -> { ImmutableList.Builder<String> commandArgsBuilder = ImmutableList.builder(); commandArgsBuilder.add( executablePath.get().getAbsolutePath(), "compile", inputDirectory.get().getAbsolutePath(), outputFile.getAbsolutePath()); List<String> args = commandArgsBuilder.build(); getLogger().info("Running compiler with args: {}", args); execSpec.commandLine(args.toArray()); }); } }
@Override public void accept(File file) { if (distutilsCfg != null) { final Path path = file.toPath(); try { Files.write(path.resolve( Paths.get("virtualenv_embedded", "distutils.cfg")), distutilsCfg.getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { throw new UncheckedIOException(e); } final ByteArrayOutputStream stream = new ByteArrayOutputStream(); exec.exec(execSpec -> { execSpec.commandLine(pythonDetails.getSystemPythonInterpreter(), path.resolve(Paths.get("bin", "rebuild-script.py")).toFile()); execSpec.setStandardOutput(stream); execSpec.setErrorOutput(stream); }); log.info("Customized distutils.cfg"); } } }
@Override public void accept(File file) { if (distutilsCfg != null) { final Path path = file.toPath(); try { Files.write(path.resolve( Paths.get("virtualenv_embedded", "distutils.cfg")), distutilsCfg.getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { throw new UncheckedIOException(e); } final ByteArrayOutputStream stream = new ByteArrayOutputStream(); exec.exec(execSpec -> { execSpec.commandLine(pythonDetails.getSystemPythonInterpreter(), path.resolve(Paths.get("bin", "rebuild-script.py")).toFile()); execSpec.setStandardOutput(stream); execSpec.setErrorOutput(stream); }); log.info("Customized distutils.cfg"); } } }
exec.commandLine(nmLoc, library); exec.setStandardOutput(nmOutput); });
@Override public void applyTo(final Project project) { // XXX: This needs to be adjusted to work with a build matrix one day. Until // that is ready, we always assume pure Python 2.7 on Linux. String version = project.getVersion().toString().replace("-", "_"); String name = project.getName().replace("-", "_"); final File wheelArtifact = new File(project.getProjectDir(), "/dist/" + name + "-" + version + "-py2-none-any.whl"); /* * Create a Python wheel distribution. */ project.getTasks().create(TASK_PACKAGE_WHEEL, task -> { task.dependsOn(project.getTasks().getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue())); task.getOutputs().file(wheelArtifact); task.doLast(it -> project.exec(execSpec -> { execSpec.environment(settings.pythonEnvironmentDistgradle); execSpec.commandLine(settings.getDetails().getVirtualEnvInterpreter(), "setup.py", "bdist_wheel"); })); }); LinkedHashMap<String, Object> wheelArtifactInfo = new LinkedHashMap<>(5); wheelArtifactInfo.put("name", name); wheelArtifactInfo.put("classifier", "py2-none-any"); wheelArtifactInfo.put("type", "whl"); wheelArtifactInfo.put("file", wheelArtifact); wheelArtifactInfo.put("builtBy", project.getTasks().getByName(TASK_PACKAGE_WHEEL)); if (!version.contains("SNAPSHOT")) { project.getArtifacts().add(StandardTextValues.CONFIGURATION_WHEEL.getValue(), wheelArtifactInfo); } }
@Override public void execute(ExecSpec execSpec) { execSpec.commandLine(pythonExtension.getDetails().getVirtualEnvInterpreter()); execSpec.args(pythonExtension.getDetails().getVirtualEnvironment().getPex()); System.out.println(outputFile.getAbsolutePath()); execSpec.args(Arrays.asList("--no-pypi", "--cache-dir", pexCache.getAbsolutePath(), "--output-file", outputFile.getAbsolutePath(), "--repo", wheelCache.getAbsolutePath(), "--python-shebang", pexShebang.getAbsolutePath())); if (entryPoint != null) { execSpec.args(Arrays.asList("--entry-point", entryPoint)); } execSpec.args(pexOptions); execSpec.args(pexRequirements(dependencies)); execSpec.setStandardOutput(outputStream); execSpec.setErrorOutput(outputStream); execSpec.setIgnoreExitValue(true); }
ExecResult execCommand(Map<String, String> mergedEnv, List<String> commandLine, OutputStream stream) { return externalExec.exec(execSpec -> { execSpec.environment(mergedEnv); execSpec.commandLine(commandLine); execSpec.setStandardOutput(stream); execSpec.setErrorOutput(stream); execSpec.setIgnoreExitValue(true); }); }
@Override public void applyTo(final Project project) { // XXX: This needs to be adjusted to work with a build matrix one day. Until // that is ready, we always assume pure Python 2.7 on Linux. String version = project.getVersion().toString().replace("-", "_"); String name = project.getName().replace("-", "_"); final File wheelArtifact = new File(project.getProjectDir(), "/dist/" + name + "-" + version + "-py2-none-any.whl"); /* * Create a Python wheel distribution. */ project.getTasks().create(TASK_PACKAGE_WHEEL, task -> { task.dependsOn(project.getTasks().getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue())); task.getOutputs().file(wheelArtifact); task.doLast(it -> project.exec(execSpec -> { execSpec.environment(settings.pythonEnvironmentDistgradle); execSpec.commandLine(settings.getDetails().getVirtualEnvInterpreter(), "setup.py", "bdist_wheel"); })); }); LinkedHashMap<String, Object> wheelArtifactInfo = new LinkedHashMap<>(5); wheelArtifactInfo.put("name", name); wheelArtifactInfo.put("classifier", "py2-none-any"); wheelArtifactInfo.put("type", "whl"); wheelArtifactInfo.put("file", wheelArtifact); wheelArtifactInfo.put("builtBy", project.getTasks().getByName(TASK_PACKAGE_WHEEL)); if (!version.contains("SNAPSHOT")) { project.getArtifacts().add(StandardTextValues.CONFIGURATION_WHEEL.getValue(), wheelArtifactInfo); } }
@Override public void execute(ExecSpec execSpec) { execSpec.commandLine(pythonExtension.getDetails().getVirtualEnvInterpreter()); execSpec.args(pythonExtension.getDetails().getVirtualEnvironment().getPex()); System.out.println(outputFile.getAbsolutePath()); execSpec.args(Arrays.asList("--no-pypi", "--cache-dir", pexCache.getAbsolutePath(), "--output-file", outputFile.getAbsolutePath(), "--repo", wheelCache.getAbsolutePath(), "--python-shebang", pexShebang.getAbsolutePath())); if (entryPoint != null) { execSpec.args(Arrays.asList("--entry-point", entryPoint)); } execSpec.args(pexOptions); execSpec.args(pexRequirements(dependencies)); execSpec.setStandardOutput(outputStream); execSpec.setErrorOutput(outputStream); execSpec.setIgnoreExitValue(true); }
/** * Entry point for the task. */ public void compileFiles() { getSource().getFiles().forEach(file -> { GeneratorOptions generatorOptions = getOptions(); getProject().exec(execSpec -> { ImmutableList.Builder<String> commandArgsBuilder = ImmutableList.builder(); File thisOutputDirectory = outputDirectoryFor(file); getProject().mkdir(thisOutputDirectory); commandArgsBuilder.add( getExecutablePath().getAbsolutePath(), "generate", file.getAbsolutePath(), thisOutputDirectory.getAbsolutePath()); List<String> additionalArgs = RenderGeneratorOptions.toArgs(generatorOptions, requiredOptions(file)); getLogger().info("Running generator with args: {}", additionalArgs); commandArgsBuilder.addAll(additionalArgs); execSpec.commandLine(commandArgsBuilder.build().toArray()); }); }); }
ExecResult execCommand(Map<String, String> mergedEnv, List<String> commandLine, OutputStream stream) { return externalExec.exec(execSpec -> { execSpec.environment(mergedEnv); execSpec.commandLine(commandLine); execSpec.setStandardOutput(stream); execSpec.setErrorOutput(stream); execSpec.setIgnoreExitValue(true); }); }
private static void doProbe(Project project, PythonDetails pythonDetails, EditablePythonAbiContainer editablePythonAbiContainer) throws IOException { InputStream wheelApiResource = ProbeVenvInfoAction.class.getClassLoader() .getResourceAsStream("templates/wheel-api.py"); byte[] buffer = new byte[wheelApiResource.available()]; wheelApiResource.read(buffer); File probeDir = new File(project.getBuildDir(), "probe-venv"); probeDir.mkdirs(); OutputStream outStream = new FileOutputStream(getPythonFileForSupportedWheels(probeDir)); outStream.write(buffer); File supportedAbiFormatsFile = getSupportedAbiFormatsFile(probeDir, pythonDetails); project.exec(execSpec -> { execSpec.commandLine(pythonDetails.getVirtualEnvInterpreter()); execSpec.args(getPythonFileForSupportedWheels(probeDir)); execSpec.args(supportedAbiFormatsFile.getAbsolutePath()); }); JsonArray array = Json.parse(new FileReader(supportedAbiFormatsFile)).asArray(); for (JsonValue jsonValue : array) { JsonObject entry = jsonValue.asObject(); String pythonTag = entry.get("pythonTag").asString(); String abiTag = entry.get("abiTag").asString(); String platformTag = entry.get("platformTag").asString(); AbiDetails triple = new AbiDetails(pythonDetails.getVirtualEnvInterpreter(), pythonTag, abiTag, platformTag); editablePythonAbiContainer.addSupportedAbi(triple); } }
private static void doProbe(Project project, PythonDetails pythonDetails, EditablePythonAbiContainer editablePythonAbiContainer) throws IOException { InputStream wheelApiResource = ProbeVenvInfoAction.class.getClassLoader() .getResourceAsStream("templates/wheel-api.py"); byte[] buffer = new byte[wheelApiResource.available()]; wheelApiResource.read(buffer); File probeDir = new File(project.getBuildDir(), "probe-venv"); probeDir.mkdirs(); OutputStream outStream = new FileOutputStream(getPythonFileForSupportedWheels(probeDir)); outStream.write(buffer); File supportedAbiFormatsFile = getSupportedAbiFormatsFile(probeDir, pythonDetails); project.exec(execSpec -> { execSpec.commandLine(pythonDetails.getVirtualEnvInterpreter()); execSpec.args(getPythonFileForSupportedWheels(probeDir)); execSpec.args(supportedAbiFormatsFile.getAbsolutePath()); }); JsonArray array = Json.parse(new FileReader(supportedAbiFormatsFile)).asArray(); for (JsonValue jsonValue : array) { JsonObject entry = jsonValue.asObject(); String pythonTag = entry.get("pythonTag").asString(); String abiTag = entry.get("abiTag").asString(); String platformTag = entry.get("platformTag").asString(); AbiDetails triple = new AbiDetails(pythonDetails.getVirtualEnvInterpreter(), pythonTag, abiTag, platformTag); editablePythonAbiContainer.addSupportedAbi(triple); } }
public Map<String, String> getDependencies() { final PythonExtension settings = ExtensionUtils.getPythonExtension(project); // Setup requirements, build, and test dependencies Set<String> developmentDependencies = configurationToSet(project, StandardTextValues.CONFIGURATION_SETUP_REQS.getValue()); developmentDependencies.addAll(configurationToSet(project, StandardTextValues.CONFIGURATION_BUILD_REQS.getValue())); developmentDependencies.addAll(configurationToSet(project, StandardTextValues.CONFIGURATION_TEST.getValue())); developmentDependencies.removeAll(configurationToSet(project, StandardTextValues.CONFIGURATION_PYTHON.getValue())); final ByteArrayOutputStream requirements = new ByteArrayOutputStream(); /* * NOTE: It is very important to provide "--all" in the list of arguments * to "pip freeze". Otherwise, setuptools, wheel, or pip would not be included * even if required by runtime configuration "python". */ project.exec(execSpec -> { execSpec.environment(settings.getEnvironment()); execSpec.commandLine( settings.getDetails().getVirtualEnvInterpreter(), settings.getDetails().getVirtualEnvironment().getPip(), "freeze", "--all", "--disable-pip-version-check" ); execSpec.setStandardOutput(requirements); }); Map<String, String> dependencies = PipFreezeOutputParser.getDependencies(developmentDependencies, requirements); // Always add project unconditionally. dependencies.put(project.getName(), project.getVersion().toString()); return dependencies; }
@Override public void execute(ExecSpec spec) { spec.setIgnoreExitValue(true); spec.commandLine(execCommand.getCommandLine()); spec.setStandardOutput(new ExternalProcessStream(execCommand.getLoggingPrefix(), System.out)); spec.setErrorOutput(new ExternalProcessStream(execCommand.getLoggingPrefix(), System.err)); execCommand.getSetupAction().execute(spec); LOG.lifecycle(" " + execCommand.getDescription() + ":\n " + StringUtil.join(execCommand.getCommandLine(), " ")); } });
@Override public void execute(ExecSpec spec) { spec.setIgnoreExitValue(true); spec.commandLine(execCommand.getCommandLine()); spec.setStandardOutput(new ExternalProcessStream(execCommand.getLoggingPrefix(), System.out)); spec.setErrorOutput(new ExternalProcessStream(execCommand.getLoggingPrefix(), System.err)); execCommand.getSetupAction().execute(spec); LOG.lifecycle(" " + execCommand.getDescription() + ":\n " + StringUtil.join(execCommand.getCommandLine(), " ")); } });
@TaskAction public void executePythonProcess() { if (!isVenvReady()) { prepairVenv(); } preExecution(); final TeeOutputContainer container = new TeeOutputContainer(stdOut, errOut); ExecResult result = getProject().exec(execSpec -> { execSpec.environment(getPythonExtension().pythonEnvironment); execSpec.commandLine(getPythonDetails().getVirtualEnvInterpreter()); // arguments are passed to the python interpreter execSpec.args(arguments); execSpec.setIgnoreExitValue(true); container.setOutputs(execSpec); configureExecution(execSpec); }); lastMessage = container.getCommandOutput(); if (!ignoreExitValue) { result.assertNormalExitValue(); } processResults(result); }
@TaskAction public void executePythonProcess() { if (!isVenvReady()) { prepairVenv(); } preExecution(); final TeeOutputContainer container = new TeeOutputContainer(stdOut, errOut); ExecResult result = getProject().exec(execSpec -> { execSpec.environment(getPythonExtension().pythonEnvironment); execSpec.commandLine(getPythonDetails().getVirtualEnvInterpreter()); // arguments are passed to the python interpreter execSpec.args(arguments); execSpec.setIgnoreExitValue(true); container.setOutputs(execSpec); configureExecution(execSpec); }); lastMessage = container.getCommandOutput(); if (!ignoreExitValue) { result.assertNormalExitValue(); } processResults(result); }
@TaskAction public void executePythonProcess() { preExecution(); final TeeOutputContainer container = new TeeOutputContainer(stdOut, errOut); ExecResult result = externalExec.exec(execSpec -> { execSpec.environment(getComponent().pythonEnvironment); execSpec.environment(getComponent().pythonEnvironmentDistgradle); execSpec.commandLine(getPythonDetails().getVirtualEnvInterpreter()); // arguments are passed to the python interpreter execSpec.args(arguments); // subArguments are arguments for previous arguments. eg: arguments to py.test like -k execSpec.args(subArguments); // additionalArguments are same as subArguments, but are expected from user's build script execSpec.args(additionalArguments); execSpec.setIgnoreExitValue(true); container.setOutputs(execSpec); configureExecution(execSpec); }); output = container.getCommandOutput(); if (!ignoreExitValue) { result.assertNormalExitValue(); } processResults(result); }
@TaskAction public void executePythonProcess() { preExecution(); final TeeOutputContainer container = new TeeOutputContainer(stdOut, errOut); ExecResult result = externalExec.exec(execSpec -> { execSpec.environment(getComponent().pythonEnvironment); execSpec.environment(getComponent().pythonEnvironmentDistgradle); execSpec.commandLine(getPythonDetails().getVirtualEnvInterpreter()); // arguments are passed to the python interpreter execSpec.args(arguments); // subArguments are arguments for previous arguments. eg: arguments to py.test like -k execSpec.args(subArguments); // additionalArguments are same as subArguments, but are expected from user's build script execSpec.args(additionalArguments); execSpec.setIgnoreExitValue(true); container.setOutputs(execSpec); configureExecution(execSpec); }); output = container.getCommandOutput(); if (!ignoreExitValue) { result.assertNormalExitValue(); } processResults(result); }