Search in sources :

Example 6 with ImportPath

use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.

the class BaseEvaluator method initImports.

private void initImports(Map<String, Object> params) {
    Collection<String> listOfImports = (Collection<String>) params.get(DefaultJVMVariables.IMPORTS);
    List<ImportPath> importPaths = new ArrayList<>();
    if (listOfImports != null) {
        for (String line : listOfImports) {
            if (!line.trim().isEmpty()) {
                importPaths.add(new ImportPath(line));
            }
        }
        if (this.imports != null) {
            importPaths.addAll(this.imports.getImportPaths());
        }
    }
    this.imports = new Imports(importPaths);
}
Also used : ImportPath(com.twosigma.beakerx.kernel.ImportPath) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Imports(com.twosigma.beakerx.kernel.Imports)

Example 7 with ImportPath

use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.

the class ReplWithClassLoaderFactory method getImportString.

@NotNull
public static String getImportString(List<ImportPath> importPaths) {
    StringBuilder javaSourceCode = new StringBuilder();
    for (ImportPath i : importPaths) {
        javaSourceCode.append("import ");
        javaSourceCode.append(adjustImport(i));
        javaSourceCode.append("\n");
    }
    return javaSourceCode.toString();
}
Also used : ImportPath(com.twosigma.beakerx.kernel.ImportPath) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ImportPath

use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.

the class ImportMagicCommandTest method allowExtraWhitespaces.

@Test
public void allowExtraWhitespaces() {
    String allCode = "%import       com.twosigma.beakerx.widget.IntSlider";
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    code.execute(kernel, 1);
    assertThat(kernel.getImports().getImportPaths()).contains(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
}
Also used : Message(com.twosigma.beakerx.message.Message) ImportPath(com.twosigma.beakerx.kernel.ImportPath) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 9 with ImportPath

use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.

the class ImportMagicCommandTest method removeImport.

@Test
public void removeImport() {
    // given
    String allCode = "%import com.twosigma.beakerx.widget.IntSlider\n";
    Code code = CodeFactory.create(allCode, new Message(), kernel);
    code.execute(kernel, 1);
    assertThat(kernel.getImports().getImportPaths()).contains(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
    // when
    String allRemoveCode = "%unimport com.twosigma.beakerx.widget.IntSlider\n";
    Code codeToRemove = CodeFactory.create(allRemoveCode, new Message(), kernel);
    codeToRemove.execute(kernel, 2);
    // then
    assertThat(kernel.getImports().getImportPaths()).doesNotContain(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
}
Also used : Message(com.twosigma.beakerx.message.Message) ImportPath(com.twosigma.beakerx.kernel.ImportPath) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 10 with ImportPath

use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.

the class AddStaticImportMagicCommand method execute.

@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
    String command = param.getCommand();
    String[] parts = MagicCommandUtils.splitPath(command);
    if (parts.length != 3) {
        return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, WRONG_FORMAT_MSG);
    }
    AddImportStatus status = this.kernel.addImport(new ImportPath(parts[1] + " " + parts[2]));
    if (AddImportStatus.ERROR.equals(status)) {
        return new MagicCommandOutput(ERROR, "Could not import static " + parts[2]);
    }
    return new MagicCommandOutput(MagicCommandOutput.Status.OK);
}
Also used : AddImportStatus(com.twosigma.beakerx.kernel.AddImportStatus) MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) ImportPath(com.twosigma.beakerx.kernel.ImportPath)

Aggregations

ImportPath (com.twosigma.beakerx.kernel.ImportPath)10 KernelTest (com.twosigma.beakerx.KernelTest)3 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)3 Code (com.twosigma.beakerx.kernel.Code)3 PlainCode (com.twosigma.beakerx.kernel.PlainCode)3 MagicCommandOutput (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput)3 Message (com.twosigma.beakerx.message.Message)3 Test (org.junit.Test)3 AddImportStatus (com.twosigma.beakerx.kernel.AddImportStatus)2 DynamicClassLoader (clojure.lang.DynamicClassLoader)1 Imports (com.twosigma.beakerx.kernel.Imports)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 NotNull (org.jetbrains.annotations.NotNull)1