sunjincheng121 commented on a change in pull request #8671:
[FLINK-12787][python] Allow to specify directory in option -pyfs
URL: https://github.com/apache/flink/pull/8671#discussion_r291944068
##########
File path:
flink-python/src/test/java/org/apache/flink/python/client/PythonEnvUtilsTest.java
##########
@@ -31,52 +31,74 @@
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.UUID;
/**
* Tests for the {@link PythonEnvUtils}.
*/
public class PythonEnvUtilsTest {
- private Path sourceTmpDirPath;
- private Path targetTmpDirPath;
- private FileSystem sourceFs;
- private FileSystem targetFs;
+ private Path tmpDirPath;
+ private FileSystem tmpDirFs;
@Before
public void prepareTestEnvironment() {
- String sourceTmpDir = System.getProperty("java.io.tmpdir") +
- File.separator + "source_" + UUID.randomUUID();
- String targetTmpDir = System.getProperty("java.io.tmpdir") +
- File.separator + "target_" + UUID.randomUUID();
+ String tmpDir = System.getProperty("java.io.tmpdir") +
+ File.separator + "pyflink" + File.separator +
UUID.randomUUID();
- sourceTmpDirPath = new Path(sourceTmpDir);
- targetTmpDirPath = new Path(targetTmpDir);
+ tmpDirPath = new Path(tmpDir);
try {
- sourceFs = sourceTmpDirPath.getFileSystem();
- if (sourceFs.exists(sourceTmpDirPath)) {
- sourceFs.delete(sourceTmpDirPath, true);
+ tmpDirFs = tmpDirPath.getFileSystem();
+ if (tmpDirFs.exists(tmpDirPath)) {
+ tmpDirFs.delete(tmpDirPath, true);
}
- sourceFs.mkdirs(sourceTmpDirPath);
- targetFs = targetTmpDirPath.getFileSystem();
- if (targetFs.exists(targetTmpDirPath)) {
- targetFs.delete(targetTmpDirPath, true);
- }
- targetFs.mkdirs(targetTmpDirPath);
+ tmpDirFs.mkdirs(tmpDirPath);
} catch (IOException e) {
throw new RuntimeException("initial PythonUtil test
environment failed");
}
}
+ @Test
+ public void testPreparePythonEnvironment() throws IOException {
+ // xxx/a.zip, xxx/subdir/b.py, xxx/subdir/c.zip
+ File a = new File(tmpDirPath.toString() + File.separator +
"a.zip");
+ a.createNewFile();
+ File subdir = new File(tmpDirPath.toString() + File.separator +
"subdir");
+ subdir.mkdir();
+ File b = new File(tmpDirPath.toString() + File.separator +
"subdir" + File.separator + "b.py");
+ b.createNewFile();
+ File c = new File(tmpDirPath.toString() + File.separator +
"subdir" + File.separator + "c.zip");
+ c.createNewFile();
+
+ List<Path> pyFilesList = new ArrayList<>();
+ pyFilesList.add(tmpDirPath);
+
+ PythonEnvUtils.PythonEnvironment env =
PythonEnvUtils.preparePythonEnvironment(pyFilesList);
+ Set<String> expectedPythonPaths = new HashSet<>();
+ expectedPythonPaths.add(env.workingDirectory);
+
+ String targetDir = env.workingDirectory + File.separator +
tmpDirPath.getName();
+ expectedPythonPaths.add(targetDir + File.separator +
a.getName());
+ expectedPythonPaths.add(targetDir + File.separator + "subdir" +
File.separator + b.getName());
Review comment:
`b.py` do not need in the python path.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services