Skip to content

Commit

Permalink
Merge pull request #74 from mipt-npm/dev
Browse files Browse the repository at this point in the history
0.5.2
  • Loading branch information
altavir authored Nov 30, 2021
2 parents acfe9c2 + c480cd8 commit 8c0bc05
Show file tree
Hide file tree
Showing 63 changed files with 481 additions and 250 deletions.
4 changes: 4 additions & 0 deletions .space.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
job("Build") {
gradlew("openjdk:11", "build")
}

49 changes: 33 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,32 @@
### Fixed

### Security

## [0.5.2]
### Added
- Yaml plugin
- Partial fix to #53


### Changed

### Deprecated

### Removed

### Fixed
- MutableMetaImpl attachment and checks
- Listeners in observable meta are replaced by lists
- JS number comparison bug.


### Security

## [0.5.0]
### Added
- Experimental `listOfSpec` delegate.


### Changed
- **API breaking** Config is deprecated, use `ObservableMeta` instead.
- **API breaking** Descriptor no has a member property `defaultValue` instead of `defaultItem()` extension. It caches default value state on the first call. It is done because computing default on each call is too expensive.
Expand All @@ -26,24 +48,26 @@
- **API breaking** `String.toName()` is replaced by `Name.parse()`
- **API breaking** Configurable`config` changed to `meta`


### Removed
- `Config`
- Public PluginManager mutability
- Tables and tables-exposed moved to the separate project `tables.kt`
- BinaryMetaFormat. Use CBOR encoding instead


### Fixed
- Proper json array index treatment.
- Proper json index for single-value array.

### Security
## [0.4.0]
### Added
- LogManager plugin
- dataforge-context API dependency on SLF4j
- Context `withEnv` and `fetch` methods to manipulate plugins without changing plugins after creation.
- Split `ItemDescriptor` into builder and read-only part


### Changed
- Kotlin-logging moved from common to JVM and JS. Replaced by console for native.
- Package changed to `space.kscience`
Expand All @@ -53,18 +77,19 @@
- Added blank builders for children context.
- Refactor loggers


### Deprecated
- Direct use of PluginManager


### Removed
- Common dependency on Kotlin-logging
- Kotlinx-io fork dependency. Replaced by Ktor-io.


### Fixed
- Scheme properties properly handle children property change.

### Security

## [0.3.0]
### Added
- Yaml meta format based on yaml.kt
Expand All @@ -73,6 +98,7 @@
- `copy` method to descriptors
- Multiplatform yaml meta


### Changed
- `ListValue` and `DoubleArrayValue` implement `Iterable`.
- Changed the logic of `Value::isList` to check for type instead of size
Expand All @@ -87,17 +113,7 @@
- \[Major breaking change\] Full refactor of DataTree/DataSource
- \[Major Breaking change\] Replace KClass with KType in data. Remove direct access to constructors with types.

### Deprecated

### Removed

### Fixed

### Security

## [0.2.0]
### Added

### Changed
- Context content resolution refactor
- Kotlin 1.4.10 (build tools 0.6.0)
Expand All @@ -107,16 +123,17 @@
- Removed io depdendency from `dataforge-output`. Replaced Output by Appendable.
- Configurable is no longer MutableItemProvider. All functionality moved to Scheme.


### Deprecated
- Context activation API
- TextRenderer


### Removed
- Functional server prototype
- `dataforge-output` module


### Fixed
- Global context CoroutineScope resolution
- Library mode compliance

### Security
- Library mode compliance
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ plugins {

allprojects {
group = "space.kscience"
version = "0.5.0"
version = "0.5.2"
repositories{
mavenCentral()
}
}

subprojects {
Expand All @@ -22,8 +25,5 @@ ksciencePublish {
}

apiValidation {
if(project.version.toString().contains("dev")) {
validationDisabled = true
}
nonPublicMarkers.add("space.kscience.dataforge.misc.DFExperimental")
}
7 changes: 2 additions & 5 deletions dataforge-context/api/dataforge-context.api
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public final class space/kscience/dataforge/context/ClassLoaderPluginKt {
public class space/kscience/dataforge/context/Context : kotlinx/coroutines/CoroutineScope, space/kscience/dataforge/meta/MetaRepr, space/kscience/dataforge/misc/Named, space/kscience/dataforge/provider/Provider {
public static final field Companion Lspace/kscience/dataforge/context/Context$Companion;
public static final field PROPERTY_TARGET Ljava/lang/String;
public final fun buildContext (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/context/Context;
public static synthetic fun buildContext$default (Lspace/kscience/dataforge/context/Context;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/context/Context;
public final fun buildContext (Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/context/Context;
public static synthetic fun buildContext$default (Lspace/kscience/dataforge/context/Context;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/context/Context;
public fun close ()V
public fun content (Ljava/lang/String;)Ljava/util/Map;
public final fun content (Ljava/lang/String;Z)Ljava/util/Map;
Expand All @@ -57,7 +57,6 @@ 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 getName ()Lspace/kscience/dataforge/names/Name;
public final fun name (Ljava/lang/String;)V
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
public final fun plugin (Lspace/kscience/dataforge/context/PluginFactory;Lkotlin/jvm/functions/Function1;)V
Expand All @@ -67,11 +66,9 @@ public final class space/kscience/dataforge/context/ContextBuilder {
public static synthetic fun plugin$default (Lspace/kscience/dataforge/context/ContextBuilder;Lspace/kscience/dataforge/context/PluginFactory;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static synthetic fun plugin$default (Lspace/kscience/dataforge/context/ContextBuilder;Lspace/kscience/dataforge/context/PluginTag;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun properties (Lkotlin/jvm/functions/Function1;)V
public final fun setName (Lspace/kscience/dataforge/names/Name;)V
}

public final class space/kscience/dataforge/context/ContextBuilderKt {
public static final fun withEnv (Lspace/kscience/dataforge/context/Context;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/context/Context;
}

public final class space/kscience/dataforge/context/DefaultLogManager : space/kscience/dataforge/context/AbstractPlugin, space/kscience/dataforge/context/LogManager {
Expand Down
4 changes: 2 additions & 2 deletions dataforge-context/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ kscience {

kotlin {
sourceSets {
val commonMain by getting{
val commonMain by getting {
dependencies {
api(project(":dataforge-meta"))
}
Expand All @@ -30,6 +30,6 @@ kotlin {
}
}

readme{
readme {
maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.dataforge.misc.Named
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.provider.Provider
Expand Down Expand Up @@ -71,16 +72,16 @@ public open class Context internal constructor(
private val childrenContexts = HashMap<Name, Context>()

/**
* Build and register a child context
* Get and validate existing context or build and register a new child context.
* @param name the relative (tail) name of the new context. If null, uses context hash code as a marker.
*/
@OptIn(DFExperimental::class)
@Synchronized
public fun buildContext(name: String? = null, block: ContextBuilder.() -> Unit = {}): Context {
val newContext = ContextBuilder(this)
.apply { name?.let { name(it) } }
.apply(block)
.build()
childrenContexts[newContext.name] = newContext
return newContext
public fun buildContext(name: Name? = null, block: ContextBuilder.() -> Unit = {}): Context {
val existing = name?.let { childrenContexts[name] }
return existing?.modify(block)?: ContextBuilder(this, name).apply(block).build().also {
childrenContexts[it.name] = it
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlin.collections.set
@DFBuilder
public class ContextBuilder internal constructor(
private val parent: Context,
public var name: Name? = null,
public val name: Name? = null,
meta: Meta = Meta.EMPTY,
) {
internal val factories = HashMap<PluginFactory<*>, Meta>()
Expand All @@ -30,10 +30,6 @@ public class ContextBuilder internal constructor(
meta.action()
}

public fun name(string: String) {
this.name = Name.parse(string)
}

@OptIn(DFExperimental::class)
private fun findPluginFactory(tag: PluginTag): PluginFactory<*> =
parent.gatherInSequence<PluginFactory<*>>(PluginFactory.TYPE).values
Expand Down Expand Up @@ -95,19 +91,21 @@ public class ContextBuilder internal constructor(
}

/**
* Check if current context contains all plugins required by the builder and return it it does or forks to a new context
* Check if current context contains all plugins required by the builder and return it does or forks to a new context
* if it does not.
*/
public fun Context.withEnv(block: ContextBuilder.() -> Unit): Context {
@DFExperimental
public fun Context.modify(block: ContextBuilder.() -> Unit): Context {

fun Context.contains(factory: PluginFactory<*>, meta: Meta): Boolean {
val loaded = plugins[factory.tag] ?: return false
return loaded.meta == meta
}

val builder = ContextBuilder(this, name + "env", properties).apply(block)
val builder = ContextBuilder(this, name + "mod", properties).apply(block)
val requiresFork = builder.factories.any { (factory, meta) ->
!contains(factory, meta)
} || ((properties as Meta) == builder.meta)

return if (requiresFork) builder.build() else this
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package space.kscience.dataforge.context
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.Job
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.Name.Companion.parse
import space.kscience.dataforge.names.asName
import kotlin.coroutines.CoroutineContext
import kotlin.native.concurrent.ThreadLocal

internal expect val globalLoggerFactory: PluginFactory<out LogManager>
internal expect fun getGlobalLoggerFactory(): PluginFactory<out LogManager>

/**
* A global root context. Closing [Global] terminates the framework.
Expand All @@ -20,4 +22,4 @@ private object GlobalContext : Context("GLOBAL".asName(), null, emptySet(), Meta
public val Global: Context get() = GlobalContext

public fun Context(name: String? = null, block: ContextBuilder.() -> Unit = {}): Context =
Global.buildContext(name, block)
Global.buildContext(name?.let(Name::parse), block)
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class DefaultLogManager : AbstractPlugin(), LogManager {
*/
public val Context.logger: LogManager
get() = plugins.find(inherit = true) { it is LogManager } as? LogManager
?: globalLoggerFactory(context = Global).apply { attach(Global) }
?: getGlobalLoggerFactory()(context = Global).apply { attach(Global) }

/**
* The named proxy logger for a context member
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package space.kscience.dataforge.context

import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.names.plus
import kotlin.reflect.KClass


Expand Down Expand Up @@ -84,7 +85,7 @@ public inline fun <reified T : Plugin> Context.fetch(factory: PluginFactory<T>,
val existing = plugins[factory]
return if (existing != null && existing.meta == meta) existing
else {
buildContext {
buildContext(name = this@fetch.name + factory.tag.name) {
plugin(factory, meta)
}.plugins[factory]!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class ContextTest {

@Test
fun testPluginManager() {
val context = Global.buildContext {
name("test")
val context = Context("test") {
plugin(DummyPlugin())
}
val members = context.gather<Name>("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public class ConsoleLogManager : AbstractPlugin(), LogManager {
}
}

internal actual val globalLoggerFactory: PluginFactory<out LogManager> = ConsoleLogManager
internal actual fun getGlobalLoggerFactory(): PluginFactory<out LogManager> = ConsoleLogManager
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ public class SlfLogManager : AbstractPlugin(), LogManager {
}
}

internal actual val globalLoggerFactory: PluginFactory<out LogManager> = SlfLogManager
internal actual fun getGlobalLoggerFactory(): PluginFactory<out LogManager> = SlfLogManager
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package space.kscience.dataforge.context


internal actual val globalLoggerFactory: PluginFactory<out LogManager> = DefaultLogManager
internal actual fun getGlobalLoggerFactory(): PluginFactory<out LogManager> = DefaultLogManager
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal class MapAction<in T : Any, out R : Any>(
return newData.named(newName)
}

val flow = dataSet.flow().map(::mapOne)
val flow = dataSet.flowData().map(::mapOne)

return ActiveDataTree(outputType) {
populate(flow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal class ReduceAction<T : Any, R : Any>(

override fun CoroutineScope.transform(set: DataSet<T>, meta: Meta, key: Name): Flow<NamedData<R>> = flow {
ReduceGroupBuilder<T, R>(inputType, this@transform, meta).apply(action).buildGroups(set).forEach { group ->
val dataFlow: Map<Name, Data<T>> = group.set.flow().fold(HashMap()) { acc, value ->
val dataFlow: Map<Name, Data<T>> = group.set.flowData().fold(HashMap()) { acc, value ->
acc.apply {
acc[value.name] = value.data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class SplitAction<T : Any, R : Any>(
}

return ActiveDataTree<R>(outputType) {
populate(dataSet.flow().flatMapConcat(transform = ::splitOne))
populate(dataSet.flowData().flatMapConcat(transform = ::splitOne))
scope?.launch {
dataSet.updates.collect { name ->
//clear old nodes
Expand Down
Loading

0 comments on commit 8c0bc05

Please sign in to comment.