diff --git a/build.gradle.kts b/build.gradle.kts index 68b1aba6..edeae557 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { allprojects { group = "space.kscience" - version = "0.7.0" + version = "0.7.1" } subprojects { diff --git a/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/Plugin.kt b/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/Plugin.kt index 152f5a76..6c5648a6 100644 --- a/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/Plugin.kt +++ b/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/Plugin.kt @@ -3,7 +3,7 @@ package space.kscience.dataforge.context import space.kscience.dataforge.context.Plugin.Companion.TARGET import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.MetaRepr -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.misc.Named import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.parseAsName @@ -18,7 +18,7 @@ import space.kscience.dataforge.provider.Provider * * create - configure - attach - detach - destroy */ -@DfId(TARGET) +@DfType(TARGET) public interface Plugin : Named, ContextAware, Provider, MetaRepr { /** diff --git a/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/PluginFactory.kt b/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/PluginFactory.kt index 0273d327..9cc67168 100644 --- a/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/PluginFactory.kt +++ b/dataforge-context/src/commonMain/kotlin/space/kscience/dataforge/context/PluginFactory.kt @@ -1,9 +1,9 @@ package space.kscience.dataforge.context import space.kscience.dataforge.meta.Meta -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType -@DfId(PluginFactory.TYPE) +@DfType(PluginFactory.TYPE) public interface PluginFactory : Factory { public val tag: PluginTag diff --git a/dataforge-context/src/jvmMain/kotlin/space/kscience/dataforge/provider/dfType.kt b/dataforge-context/src/jvmMain/kotlin/space/kscience/dataforge/provider/dfType.kt index ab34ea50..04e681da 100644 --- a/dataforge-context/src/jvmMain/kotlin/space/kscience/dataforge/provider/dfType.kt +++ b/dataforge-context/src/jvmMain/kotlin/space/kscience/dataforge/provider/dfType.kt @@ -4,7 +4,7 @@ import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.PluginBuilder import space.kscience.dataforge.context.gather import space.kscience.dataforge.misc.DFExperimental -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.misc.Named import space.kscience.dataforge.names.Name import kotlin.reflect.KClass @@ -13,10 +13,10 @@ import kotlin.reflect.full.findAnnotation @DFExperimental public val KClass<*>.dfId: String - get() = findAnnotation()?.id ?: simpleName ?: "" + get() = findAnnotation()?.id ?: simpleName ?: "" /** - * Provide an object with given name inferring target from its type using [DfId] annotation + * Provide an object with given name inferring target from its type using [DfType] annotation */ @DFExperimental public inline fun Provider.provideByType(name: String): T? { diff --git a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/MapAction.kt b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/MapAction.kt index 883b3928..7b2c94f5 100644 --- a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/MapAction.kt +++ b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/MapAction.kt @@ -98,8 +98,7 @@ internal class MapAction( * A one-to-one mapping action */ @DFExperimental -@Suppress("FunctionName") -public inline fun Action.Companion.map( +public inline fun Action.Companion.mapping( noinline builder: MapActionBuilder.() -> Unit, ): Action = MapAction(typeOf(), builder) diff --git a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/ReduceAction.kt b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/ReduceAction.kt index fe823bd7..a74cfad9 100644 --- a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/ReduceAction.kt +++ b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/ReduceAction.kt @@ -112,6 +112,6 @@ internal class ReduceAction( * A one-to-one mapping action */ @DFExperimental -public inline fun Action.Companion.reduce( +public inline fun Action.Companion.reducing( noinline builder: ReduceGroupBuilder.() -> Unit, ): Action = ReduceAction(typeOf(), builder) diff --git a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/SplitAction.kt b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/SplitAction.kt index 24745929..0ecde319 100644 --- a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/SplitAction.kt +++ b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/SplitAction.kt @@ -87,6 +87,6 @@ internal class SplitAction( * Action that splits each incoming element into a number of fragments defined in builder */ @DFExperimental -public inline fun Action.Companion.split( +public inline fun Action.Companion.splitting( noinline builder: SplitBuilder.() -> Unit, ): Action = SplitAction(typeOf(), builder) \ No newline at end of file diff --git a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/Data.kt b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/Data.kt index 984582e5..4d883795 100644 --- a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/Data.kt +++ b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/Data.kt @@ -5,7 +5,7 @@ import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.MetaRepr import space.kscience.dataforge.meta.isEmpty import space.kscience.dataforge.misc.DFInternal -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlin.reflect.KType @@ -14,7 +14,7 @@ import kotlin.reflect.typeOf /** * A data element characterized by its meta */ -@DfId(Data.TYPE) +@DfType(Data.TYPE) public interface Data : Goal, MetaRepr { /** * Type marker for the data. The type is known before the calculation takes place so it could be checked. diff --git a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/DataTree.kt b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/DataTree.kt index bafcbea2..b9273c07 100644 --- a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/DataTree.kt +++ b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/DataTree.kt @@ -2,7 +2,7 @@ package space.kscience.dataforge.data import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.misc.DFInternal -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.names.* import kotlin.collections.component1 import kotlin.collections.component2 @@ -31,7 +31,7 @@ public val DataTreeItem.type: KType /** * A tree-like [DataSet] grouped into the node. All data inside the node must inherit its type */ -@DfId(DataTree.TYPE) +@DfType(DataTree.TYPE) public interface DataTree : DataSet { /** diff --git a/dataforge-data/src/jvmMain/kotlin/space/kscience/dataforge/data/actionInContext.kt b/dataforge-data/src/jvmMain/kotlin/space/kscience/dataforge/data/actionInContext.kt deleted file mode 100644 index 33731a95..00000000 --- a/dataforge-data/src/jvmMain/kotlin/space/kscience/dataforge/data/actionInContext.kt +++ /dev/null @@ -1,2 +0,0 @@ -package space.kscience.dataforge.data - diff --git a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/EnvelopeFormat.kt b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/EnvelopeFormat.kt index 0df5ab27..0e998760 100644 --- a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/EnvelopeFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/EnvelopeFormat.kt @@ -4,7 +4,7 @@ import kotlinx.io.Source import space.kscience.dataforge.context.Context import space.kscience.dataforge.io.EnvelopeFormatFactory.Companion.ENVELOPE_FORMAT_TYPE import space.kscience.dataforge.meta.Meta -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName import kotlin.reflect.KType @@ -17,7 +17,7 @@ public interface EnvelopeFormat : IOFormat { public fun EnvelopeFormat.read(input: Source): Envelope = readFrom(input) -@DfId(ENVELOPE_FORMAT_TYPE) +@DfType(ENVELOPE_FORMAT_TYPE) public interface EnvelopeFormatFactory : IOFormatFactory, EnvelopeFormat { override val type: KType get() = typeOf() diff --git a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/IOFormat.kt b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/IOFormat.kt index ffcadf1a..390a8bf4 100644 --- a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/IOFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/IOFormat.kt @@ -7,7 +7,7 @@ import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.Factory import space.kscience.dataforge.io.IOFormatFactory.Companion.IO_FORMAT_TYPE import space.kscience.dataforge.meta.Meta -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.misc.Named import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName @@ -72,7 +72,7 @@ public fun Sink.writeWith(format: IOWriter, obj: T): Unit = format.writeTo(this, obj) -@DfId(IO_FORMAT_TYPE) +@DfType(IO_FORMAT_TYPE) public interface IOFormatFactory : Factory>, Named { /** * Explicit type for dynamic type checks diff --git a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/MetaFormat.kt b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/MetaFormat.kt index cadf87ca..f864dd2f 100644 --- a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/MetaFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/MetaFormat.kt @@ -9,7 +9,7 @@ import space.kscience.dataforge.context.Global import space.kscience.dataforge.io.MetaFormatFactory.Companion.META_FORMAT_TYPE import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.descriptors.MetaDescriptor -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName import space.kscience.dataforge.names.plus @@ -38,7 +38,7 @@ public interface MetaFormat : IOFormat { public fun readMeta(source: Source, descriptor: MetaDescriptor? = null): Meta } -@DfId(META_FORMAT_TYPE) +@DfType(META_FORMAT_TYPE) public interface MetaFormatFactory : IOFormatFactory, MetaFormat { public val shortName: String diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Meta.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Meta.kt index 420625ca..979c8782 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Meta.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Meta.kt @@ -2,7 +2,7 @@ package space.kscience.dataforge.meta import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.misc.unsafeCast import space.kscience.dataforge.names.* import kotlin.jvm.JvmName @@ -31,7 +31,7 @@ public fun interface MetaProvider : ValueProvider { * TODO add documentation * Same name siblings are supported via elements with the same [Name] but different indices. */ -@DfId(Meta.TYPE) +@DfType(Meta.TYPE) @Serializable(MetaSerializer::class) public interface Meta : MetaRepr, MetaProvider { public val value: Value? @@ -248,7 +248,7 @@ public inline fun > Meta?.enum(): E? = this?.value?.let { } } -public val Meta.stringList: List? get() = value?.list?.map { it.string } +public val Meta?.stringList: List? get() = this?.value?.list?.map { it.string } /** * Create a provider that uses given provider for default values if those are not found in this provider diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/descriptors/MetaDescriptorBuilder.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/descriptors/MetaDescriptorBuilder.kt index ae6c171a..95949d03 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/descriptors/MetaDescriptorBuilder.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/descriptors/MetaDescriptorBuilder.kt @@ -9,7 +9,11 @@ import space.kscience.dataforge.names.length import kotlin.collections.set public class MetaDescriptorBuilder @PublishedApi internal constructor() { - public var info: String? = null + public var description: String? = null + + @Deprecated("Replace by description", ReplaceWith("description")) + public var info: String? by ::description + public var children: MutableMap = linkedMapOf() public var multiple: Boolean = false public var valueRestriction: ValueRestriction = ValueRestriction.NONE @@ -87,7 +91,7 @@ public class MetaDescriptorBuilder @PublishedApi internal constructor() { @PublishedApi internal fun build(): MetaDescriptor = MetaDescriptor( - description = info, + description = description, children = children.mapValues { it.value.build() }, multiple = multiple, valueRestriction = valueRestriction, @@ -165,7 +169,7 @@ public inline fun > MetaDescriptorBuilder.enum( } private fun MetaDescriptor.toBuilder(): MetaDescriptorBuilder = MetaDescriptorBuilder().apply { - info = this@toBuilder.description + description = this@toBuilder.description children = this@toBuilder.children.mapValuesTo(LinkedHashMap()) { it.value.toBuilder() } multiple = this@toBuilder.multiple valueRestriction = this@toBuilder.valueRestriction diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/misc/DfId.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/misc/DfType.kt similarity index 56% rename from dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/misc/DfId.kt rename to dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/misc/DfType.kt index 5d485e23..11f548ae 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/misc/DfId.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/misc/DfType.kt @@ -5,4 +5,7 @@ package space.kscience.dataforge.misc */ @MustBeDocumented @Target(AnnotationTarget.CLASS) -public annotation class DfId(val id: String) +public annotation class DfType(val id: String) + +@Deprecated("Replace with DfType", replaceWith = ReplaceWith("DfType")) +public typealias DfId = DfType diff --git a/dataforge-meta/src/commonTest/kotlin/space/kscience/dataforge/meta/descriptors/DescriptorTest.kt b/dataforge-meta/src/commonTest/kotlin/space/kscience/dataforge/meta/descriptors/DescriptorTest.kt index e8c321fc..1a08ce34 100644 --- a/dataforge-meta/src/commonTest/kotlin/space/kscience/dataforge/meta/descriptors/DescriptorTest.kt +++ b/dataforge-meta/src/commonTest/kotlin/space/kscience/dataforge/meta/descriptors/DescriptorTest.kt @@ -11,14 +11,14 @@ class DescriptorTest { val descriptor = MetaDescriptor { node("aNode") { - info = "A root demo node" + description = "A root demo node" value("b", ValueType.NUMBER) { - info = "b number value" + description = "b number value" } node("otherNode") { value("otherValue", ValueType.BOOLEAN) { default(false) - info = "default value" + description = "default value" } } } diff --git a/dataforge-workspace/src/commonMain/kotlin/space/kscience/dataforge/workspace/Task.kt b/dataforge-workspace/src/commonMain/kotlin/space/kscience/dataforge/workspace/Task.kt index a1ef7be2..329d9c5a 100644 --- a/dataforge-workspace/src/commonMain/kotlin/space/kscience/dataforge/workspace/Task.kt +++ b/dataforge-workspace/src/commonMain/kotlin/space/kscience/dataforge/workspace/Task.kt @@ -9,7 +9,7 @@ import space.kscience.dataforge.meta.MetaRepr import space.kscience.dataforge.meta.Specification import space.kscience.dataforge.meta.descriptors.Described import space.kscience.dataforge.meta.descriptors.MetaDescriptor -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.names.Name import space.kscience.dataforge.workspace.Task.Companion.TYPE import kotlin.reflect.KType @@ -19,7 +19,7 @@ import kotlin.reflect.typeOf * A configurable task that could be executed on a workspace. The [TaskResult] represents a lazy result of the task. * In general no computations should be made until the result is called. */ -@DfId(TYPE) +@DfType(TYPE) public interface Task : Described { /** diff --git a/dataforge-workspace/src/commonMain/kotlin/space/kscience/dataforge/workspace/Workspace.kt b/dataforge-workspace/src/commonMain/kotlin/space/kscience/dataforge/workspace/Workspace.kt index ee00f539..37b473db 100644 --- a/dataforge-workspace/src/commonMain/kotlin/space/kscience/dataforge/workspace/Workspace.kt +++ b/dataforge-workspace/src/commonMain/kotlin/space/kscience/dataforge/workspace/Workspace.kt @@ -6,7 +6,7 @@ import space.kscience.dataforge.data.DataSet import space.kscience.dataforge.data.asSequence import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.MutableMeta -import space.kscience.dataforge.misc.DfId +import space.kscience.dataforge.misc.DfType import space.kscience.dataforge.names.Name import space.kscience.dataforge.provider.Provider @@ -18,7 +18,7 @@ public interface DataSelector{ /** * An environment for pull-mode computation */ -@DfId(Workspace.TYPE) +@DfType(Workspace.TYPE) public interface Workspace : ContextAware, Provider { /** * The whole data node for current workspace diff --git a/dataforge-workspace/src/jvmMain/kotlin/space/kscience/dataforge/workspace/fileData.kt b/dataforge-workspace/src/jvmMain/kotlin/space/kscience/dataforge/workspace/fileData.kt index d9f678b3..ce1b5152 100644 --- a/dataforge-workspace/src/jvmMain/kotlin/space/kscience/dataforge/workspace/fileData.kt +++ b/dataforge-workspace/src/jvmMain/kotlin/space/kscience/dataforge/workspace/fileData.kt @@ -11,7 +11,6 @@ import space.kscience.dataforge.data.* import space.kscience.dataforge.io.* import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.copy -import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.string import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.misc.DFInternal @@ -27,10 +26,7 @@ import java.nio.file.WatchEvent import java.nio.file.attribute.BasicFileAttributes import java.nio.file.spi.FileSystemProvider import java.time.Instant -import kotlin.io.path.extension -import kotlin.io.path.name -import kotlin.io.path.nameWithoutExtension -import kotlin.io.path.readAttributes +import kotlin.io.path.* import kotlin.reflect.KType import kotlin.reflect.typeOf @@ -92,7 +88,7 @@ public fun IOPlugin.readDataFile( context(IOPlugin) @DFExperimental -private fun DataSetBuilder.directory( +public fun DataSetBuilder.directory( path: Path, ignoreExtensions: Set, formatResolver: FileFormatResolver, @@ -145,7 +141,7 @@ public inline fun IOPlugin.readDataDirectory( ): DataTree = readDataDirectory(typeOf(), path, ignoreExtensions, formatResolver) /** - * Read raw binary data tree from the directory. All files are read as-is (save for meta files). + * Read a raw binary data tree from the directory. All files are read as-is (save for meta files). */ @DFExperimental public fun IOPlugin.readRawDirectory( @@ -260,6 +256,29 @@ public suspend fun IOPlugin.writeDataDirectory( } } +/** + * Reads the specified resources and returns a [DataTree] containing the data. + * + * @param resources The names of the resources to read. + * @param classLoader The class loader to use for loading the resources. By default, it uses the current thread's context class loader. + * @return A DataTree containing the data read from the resources. + */ +@DFExperimental +private fun IOPlugin.readResources( + vararg resources: String, + classLoader: ClassLoader = Thread.currentThread().contextClassLoader, +): DataTree { +// require(resource.isNotBlank()) {"Can't mount root resource tree as data root"} + return DataTree { + resources.forEach { resource -> + val path = classLoader.getResource(resource)?.toURI()?.toPath() ?: error( + "Resource with name $resource is not resolved" + ) + node(resource, readRawDirectory(path)) + } + } +} + /** * Add file/directory-based data tree item *