All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlinx.jupyter.magics.UseMagicsHandler.kt Maven / Gradle / Ivy

Go to download

Implementation of REPL compiler and preprocessor for Jupyter dialect of Kotlin (IDE-compatible)

There is a newer version: 0.12.0-250
Show newest version
package org.jetbrains.kotlinx.jupyter.magics

import org.jetbrains.kotlinx.jupyter.exceptions.ReplPreprocessingException
import org.jetbrains.kotlinx.jupyter.libraries.DefaultInfoSwitch
import org.jetbrains.kotlinx.jupyter.libraries.LibrariesProcessor
import org.jetbrains.kotlinx.jupyter.libraries.ResolutionInfoSwitcher

open class UseMagicsHandler(
    private val librariesProcessor: LibrariesProcessor,
    private val libraryResolutionInfoSwitcher: ResolutionInfoSwitcher,
) : LibrariesAwareAbstractMagicsHandler() {
    override fun handleUse() {
        try {
            arg?.let { notNullArg ->
                newLibraries.addAll(librariesProcessor.processNewLibraries(notNullArg))
            } ?: throw ReplPreprocessingException("Need some arguments for 'use' command")
        } catch (e: Exception) {
            if (!tryIgnoreErrors) throw e
        }
    }

    override fun handleUseLatestDescriptors() {
        handleSingleOptionalFlag {
            libraryResolutionInfoSwitcher.switch = if (it == false) DefaultInfoSwitch.DIRECTORY
            else DefaultInfoSwitch.GIT_REFERENCE
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy