chamikaramj commented on code in PR #22991:
URL: https://github.com/apache/beam/pull/22991#discussion_r960903708
##########
sdks/java/extensions/python/src/test/java/org/apache/beam/sdk/extensions/python/PythonExternalTransformTest.java:
##########
@@ -60,6 +66,23 @@ public void trivialPythonTransform() {
// TODO: Run this on a multi-language supporting runner.
}
+ @Ignore("https://github.com/apache/beam/issues/21561")
+ @Test
+ @Category({ValidatesRunner.class, UsesPythonExpansionService.class})
+ public void pythonTransformWithDependencies() {
+ Pipeline p = Pipeline.create();
+ PCollection<String> output =
+ p.apply(Create.of("elephant", "mouse", "sheep"))
+ .apply(
+ PythonExternalTransform.<PCollection<String>,
PCollection<String>>from(
+ "apache_beam.Map")
+ .withArgs(PythonCallableSource.of("import
inflection\ninflection.pluralize"))
+ .withExtraPackages(ImmutableList.of("inflection"))
+ .withOutputCoder(StringUtf8Coder.of()));
+ PAssert.that(output).containsInAnyOrder("elephants", "mice", "sheep");
+ // TODO: Run this on a multi-language supporting runner.
Review Comment:
Probably we should add a RunInferenceIT that uses this (separate PR).
https://github.com/apache/beam/blob/master/sdks/java/extensions/python/src/test/java/org/apache/beam/sdk/extensions/python/transforms/RunInferenceTransformTest.java
##########
sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/PythonExternalTransform.java:
##########
@@ -418,13 +433,24 @@ public OutputT expand(InputT input) {
return apply(input, expansionService, payload);
} else {
int port = PythonService.findAvailablePort();
+ ImmutableList.Builder<String> args = ImmutableList.builder();
+ args.add("--port", "" + port, "--fully_qualified_name_glob", "*");
+ if (!extraPackages.isEmpty()) {
+ File requirementsFile = File.createTempFile("requirements", ".txt");
+ requirementsFile.deleteOnExit();
+ try (FileWriter fout =
+ new FileWriter(requirementsFile.getAbsolutePath(),
Charsets.UTF_8)) {
+ for (String pkg : extraPackages) {
+ fout.write(pkg);
+ fout.write('\n');
+ }
+ }
+ args.add("--requirements_file=" +
requirementsFile.getAbsolutePath());
Review Comment:
Where does this option get used ?
I thought we would have to manually register such dependencies in the
"expansion_service_main.py" using the "PyPIArtifactRegistry.register_artifact"
method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]