Skip to content

Commit

Permalink
Merge pull request #82 from SciProgCentre/dev
Browse files Browse the repository at this point in the history
0.9.0
  • Loading branch information
SPC-code authored Jun 10, 2024
2 parents 8116489 + c62dc2c commit d80846d
Show file tree
Hide file tree
Showing 90 changed files with 1,724 additions and 1,128 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,41 @@

### Security

## 0.9.0 - 2024-06-04

### Added

- Custom CoroutineContext during `Context` creation.

### Changed

- Kotlin 2.0
- `MetaSpec` renamed to `MetaReader`. MetaSpec is now reserved for builder-based generation of meta descriptors.
- Add self-type for Meta. Remove unsafe cast method for meta instances.

### Removed

- Automatic descriptors for schema. It is not possible to implement them without heavy reflection.

## 0.8.2 - 2024-04-27

### Added

- Name index comparator
- Specialized ByteArrayValue

### Changed

- DataSink `branch` is replaced with `putAll` to avoid confusion with DataTree methods
- Meta delegate now uses a specific class that has a descriptor

### Fixed

- `listOfScheme` and `listOfConvertable` delegates provides correct items order.
- Scheme meta setter works with proper sub-branch.
- NameToken.parse improper work with indices.
- Proper data handling for cache.

## 0.8.0 - 2024-02-03

### Added
Expand Down
11 changes: 6 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import space.kscience.gradle.useApache2Licence
import space.kscience.gradle.useSPCTeam

plugins {
id("space.kscience.gradle.project")
alias(spclibs.plugins.kscience.project)
alias(spclibs.plugins.kotlinx.kover)
}

allprojects {
group = "space.kscience"
version = "0.8.0"
version = "0.9.0"
}

subprojects {
apply(plugin = "maven-publish")

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xcontext-receivers"
compilerOptions {
freeCompilerArgs.add("-Xcontext-receivers")
}
}
}
Expand All @@ -30,7 +31,7 @@ ksciencePublish {
useApache2Licence()
useSPCTeam()
}
repository("spc","https://maven.sciprog.center/kscience")
repository("spc", "https://maven.sciprog.center/kscience")
sonatype("https://oss.sonatype.org")
}

Expand Down
4 changes: 2 additions & 2 deletions dataforge-context/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Context and provider definitions

## Artifact:

The Maven coordinates of this project are `space.kscience:dataforge-context:0.8.0`.
The Maven coordinates of this project are `space.kscience:dataforge-context:0.9.0-dev-1`.

**Gradle Kotlin DSL:**
```kotlin
Expand All @@ -16,6 +16,6 @@ repositories {
}

dependencies {
implementation("space.kscience:dataforge-context:0.8.0")
implementation("space.kscience:dataforge-context:0.9.0-dev-1")
}
```
25 changes: 6 additions & 19 deletions dataforge-context/api/dataforge-context.api
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public abstract interface class space/kscience/dataforge/context/ContextAware {

public final class space/kscience/dataforge/context/ContextBuilder {
public final fun build ()Lspace/kscience/dataforge/context/Context;
public final fun coroutineContext (Lkotlin/coroutines/CoroutineContext;)V
public final fun getName ()Lspace/kscience/dataforge/names/Name;
public final fun plugin (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public final fun plugin (Lspace/kscience/dataforge/context/Plugin;)V
Expand All @@ -69,9 +70,6 @@ public final class space/kscience/dataforge/context/ContextBuilder {
public final fun properties (Lkotlin/jvm/functions/Function1;)V
}

public final class space/kscience/dataforge/context/ContextBuilderKt {
}

public final class space/kscience/dataforge/context/DefaultLogManager : space/kscience/dataforge/context/AbstractPlugin, space/kscience/dataforge/context/LogManager {
public static final field Companion Lspace/kscience/dataforge/context/DefaultLogManager$Companion;
public fun <init> ()V
Expand Down Expand Up @@ -212,14 +210,14 @@ public final class space/kscience/dataforge/context/PluginTag : space/kscience/d
public fun toString ()Ljava/lang/String;
}

public final class space/kscience/dataforge/context/PluginTag$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public synthetic class space/kscience/dataforge/context/PluginTag$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lspace/kscience/dataforge/context/PluginTag$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lspace/kscience/dataforge/context/PluginTag;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lspace/kscience/dataforge/context/PluginTag;
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/context/PluginTag;)V
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lspace/kscience/dataforge/context/PluginTag;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

Expand Down Expand Up @@ -264,17 +262,6 @@ public abstract interface annotation class space/kscience/dataforge/descriptors/
public abstract interface annotation class space/kscience/dataforge/descriptors/Multiple : java/lang/annotation/Annotation {
}

public final class space/kscience/dataforge/descriptors/ReflectiveDescriptorsKt {
public static final fun forClass (Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor$Companion;Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;
public static synthetic fun forClass$default (Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor$Companion;Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;
}

public final class space/kscience/dataforge/properties/MetaAsFlowKt {
}

public final class space/kscience/dataforge/provider/DfTypeKt {
}

public final class space/kscience/dataforge/provider/Path : java/lang/Iterable, kotlin/jvm/internal/markers/KMappedMarker {
public static final field Companion Lspace/kscience/dataforge/provider/Path$Companion;
public static final field PATH_SEGMENT_SEPARATOR Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import space.kscience.dataforge.misc.ThreadSafe
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.provider.Provider
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

/**
* The local environment for anything being done in DataForge framework. Contexts are organized into tree structure with [Global] at the top.
Expand All @@ -26,6 +27,7 @@ public open class Context internal constructor(
public val parent: Context?,
plugins: Set<Plugin>, // set of unattached plugins
meta: Meta,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
) : Named, MetaRepr, Provider, CoroutineScope {

/**
Expand Down Expand Up @@ -65,7 +67,7 @@ public open class Context internal constructor(

override val coroutineContext: CoroutineContext by lazy {
(parent ?: Global).coroutineContext.let { parenContext ->
parenContext + SupervisorJob(parenContext[Job])
parenContext + coroutineContext + SupervisorJob(parenContext[Job])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import space.kscience.dataforge.names.plus
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

/**
* A convenience builder for context
Expand Down Expand Up @@ -59,8 +61,15 @@ public class ContextBuilder internal constructor(
plugin(DeFactoPluginFactory(plugin))
}

private var coroutineContext: CoroutineContext = EmptyCoroutineContext

public fun coroutineContext(coroutineContext: CoroutineContext) {
this.coroutineContext = coroutineContext
}


public fun build(): Context {
val contextName = name ?: NameToken("@auto",hashCode().toUInt().toString(16)).asName()
val contextName = name ?: NameToken("@auto", hashCode().toUInt().toString(16)).asName()
val plugins = HashMap<PluginTag, Plugin>()

fun addPlugin(factory: PluginFactory<*>, meta: Meta) {
Expand All @@ -86,7 +95,7 @@ public class ContextBuilder internal constructor(
addPlugin(factory, meta)
}

return Context(contextName, parent, plugins.values.toSet(), meta.seal())
return Context(contextName, parent, plugins.values.toSet(), meta.seal(), coroutineContext)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import space.kscience.dataforge.meta.*
import space.kscience.dataforge.misc.DFExperimental

@DFExperimental
public fun <T> ObservableMeta.asFlow(converter: MetaSpec<T>): Flow<T> = callbackFlow {
public fun <T> ObservableMeta.asFlow(converter: MetaReader<T>): Flow<T> = callbackFlow {
onChange(this){
trySend(converter.read(this))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import org.slf4j.LoggerFactory
import space.kscience.dataforge.meta.Scheme
import space.kscience.dataforge.meta.SchemeSpec
import space.kscience.dataforge.meta.ValueType
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.MetaDescriptorBuilder
import space.kscience.dataforge.meta.descriptors.node
import space.kscience.dataforge.misc.DFExperimental
import java.net.URL
import kotlin.reflect.KClass
import kotlin.reflect.full.isSubclassOf
import kotlin.reflect.full.memberProperties
import kotlin.reflect.typeOf

import kotlin.reflect.KAnnotatedElement
import kotlin.reflect.KProperty

/**
* Description text for meta property, node or whole object
Expand Down Expand Up @@ -58,19 +52,9 @@ private fun MetaDescriptorBuilder.loadDescriptorFromResource(resource: Descripto
}
}


public fun <T : Any> MetaDescriptor.Companion.forClass(
kClass: KClass<T>,
mod: MetaDescriptorBuilder.() -> Unit = {},
): MetaDescriptor = MetaDescriptor {
when {
kClass.isSubclassOf(Number::class) -> valueType(ValueType.NUMBER)
kClass == String::class -> ValueType.STRING
kClass == Boolean::class -> ValueType.BOOLEAN
kClass == DoubleArray::class -> ValueType.LIST
}

kClass.annotations.forEach {
@DFExperimental
public fun MetaDescriptorBuilder.forAnnotatedElement(element: KAnnotatedElement) {
element.annotations.forEach {
when (it) {
is Description -> description = it.value

Expand All @@ -79,46 +63,70 @@ public fun <T : Any> MetaDescriptor.Companion.forClass(
is DescriptorUrl -> loadDescriptorFromUrl(URL(it.url))
}
}
kClass.memberProperties.forEach { property ->

var flag = false

val descriptor = MetaDescriptor {
//use base type descriptor as a base
(property.returnType.classifier as? KClass<*>)?.let {
from(forClass(it))
}
property.annotations.forEach {
when (it) {
is Description -> {
description = it.value
flag = true
}
}

is Multiple -> {
multiple = true
flag = true
}
@DFExperimental
public fun MetaDescriptorBuilder.forProperty(property: KProperty<*>) {
property.annotations.forEach {
when (it) {
is Description -> description = it.value

is DescriptorResource -> {
loadDescriptorFromResource(it)
flag = true
}
is DescriptorResource -> loadDescriptorFromResource(it)

is DescriptorUrl -> {
loadDescriptorFromUrl(URL(it.url))
flag = true
}
}
}
}
if (flag) {
node(property.name, descriptor)
is DescriptorUrl -> loadDescriptorFromUrl(URL(it.url))
}
}
mod()
}

@Suppress("UNCHECKED_CAST")
public inline fun <reified T : Scheme> SchemeSpec<T>.autoDescriptor( noinline mod: MetaDescriptorBuilder.() -> Unit = {}): MetaDescriptor =
MetaDescriptor.forClass(typeOf<T>().classifier as KClass<T>, mod)
//
//@DFExperimental
//public fun <T : Scheme> MetaDescriptor.Companion.forScheme(
// spec: SchemeSpec<T>,
// mod: MetaDescriptorBuilder.() -> Unit = {},
//): MetaDescriptor = MetaDescriptor {
// val scheme = spec.empty()
// val kClass: KClass<T> = scheme::class as KClass<T>
// when {
// kClass.isSubclassOf(Number::class) -> valueType(ValueType.NUMBER)
// kClass == String::class -> ValueType.STRING
// kClass == Boolean::class -> ValueType.BOOLEAN
// kClass == DoubleArray::class -> ValueType.LIST
// kClass == ByteArray::class -> ValueType.LIST
// }
//
// forAnnotatedElement(kClass)
// kClass.memberProperties.forEach { property ->
// node(property.name) {
//
// (property.getDelegate(scheme) as? MetaDelegate<*>)?.descriptor?.let {
// from(it)
// }
//
// property.annotations.forEach {
// when (it) {
// is Description -> {
// description = it.value
// }
//
// is Multiple -> {
// multiple = true
// }
//
// is DescriptorResource -> {
// loadDescriptorFromResource(it)
// }
//
// is DescriptorUrl -> {
// loadDescriptorFromUrl(URL(it.url))
// }
// }
// }
// }
//
// }
// mod()
//}
//
//@DFExperimental
//public inline fun <reified T : Scheme> SchemeSpec<T>.autoDescriptor(
// noinline mod: MetaDescriptorBuilder.() -> Unit = {},
//): MetaDescriptor = MetaDescriptor.forScheme(this, mod)
Loading

0 comments on commit d80846d

Please sign in to comment.