PySubmarineInterpreter extends PythonInterpreter { @Override public InterpreterResult interpret(String st, InterpreterContext context) throws InterpreterException { setParagraphConfig(context); String algorithmPath = properties.getProperty( SubmarineConstants.SUBMARINE_ALGORITHM_HDFS_PATH, ""); if (algorithmPath.contains(SubmarineConstants.USERNAME_SYMBOL)) { algorithmPath = algorithmPath.replace(SubmarineConstants.USERNAME_SYMBOL, userName); properties.setProperty(SubmarineConstants.SUBMARINE_ALGORITHM_HDFS_PATH, algorithmPath); } String checkpointPath = properties.getProperty( SubmarineConstants.TF_CHECKPOINT_PATH, ""); if (checkpointPath.contains(SubmarineConstants.USERNAME_SYMBOL)) { checkpointPath = checkpointPath.replace(SubmarineConstants.USERNAME_SYMBOL, userName); properties.setProperty(SubmarineConstants.TF_CHECKPOINT_PATH, checkpointPath); } if (null == submarineInterpreter) { submarineInterpreter = getInterpreterInTheSameSessionByClassName(SubmarineInterpreter.class); if (null != submarineInterpreter) { submarineInterpreter.setPythonWorkDir(context.getNoteId(), getPythonWorkDir()); } } SubmarineJob submarineJob = submarineContext.addOrGetSubmarineJob(this.properties, context); if (null != submarineJob && null != submarineJob.getHdfsClient()) { try { String noteId = context.getNoteId(); List<ParagraphInfo> paragraphInfos = context.getIntpEventClient() .getParagraphList(userName, noteId); submarineJob.getHdfsClient().saveParagraphToFiles( noteId, paragraphInfos, getPythonWorkDir().getAbsolutePath(), properties); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } return super.interpret(st, context); } PySubmarineInterpreter(Properties property); @Override InterpreterResult interpret(String st, InterpreterContext context);  }
@Test public void testTensorflow() throws InterpreterException { String callTensorflowFunc = "import tensorflow as tf\n" + "print('Installed TensorFlow version:' + tf.__version__)"; InterpreterContext intpContext = getIntpContext(); InterpreterResult intpResult = pySubmarineIntp.interpret(callTensorflowFunc, intpContext); assertEquals(intpResult.code(), InterpreterResult.Code.SUCCESS); String tfVersionInfo = intpContext.out().getCurrentOutput().toString(); LOGGER.info(tfVersionInfo); boolean getVersion = tfVersionInfo.contains("Installed TensorFlow version:"); assertTrue(tfVersionInfo, getVersion); }