Skip to content

Commit

Permalink
Merge branch 'master' into derivation-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jcazevedo committed Oct 21, 2018
2 parents bfc162a + 7b31553 commit 87653cb
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 46 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: scala

scala:
- 2.11.12
- 2.12.6
- 2.12.7
jdk:
- oraclejdk8
env:
Expand All @@ -25,7 +25,7 @@ after_success:
jobs:
include:
- env: JOB=microsite
scala: 2.12.6
scala: 2.12.7
addons:
apt:
packages:
Expand All @@ -39,10 +39,8 @@ jobs:
- gem install sass jekyll:3.2.1 html-proofer
script:
- sbt makeMicrosite
# we're ignoring www.47deg.com due to SSL errors; we should check this again later
- htmlproofer \
--allow_hash_href \
--url-ignore '/www.47deg.com/' \
--url-swap "https\://github\.com/pureconfig/pureconfig/tree/master:file\://$(pwd)" \
docs/target/site
after_success: ignore
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ lazy val commonSettings = Seq(
homepage := Some(url("https://github.com/pureconfig/pureconfig")),
licenses := Seq("Mozilla Public License, version 2.0" -> url("https://www.mozilla.org/MPL/2.0/")),

scalaVersion := "2.12.6",
crossScalaVersions := Seq("2.11.12", "2.12.6"),
scalaVersion := "2.12.7",
crossScalaVersions := Seq("2.11.12", "2.12.7"),

resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Expand Down
3 changes: 1 addition & 2 deletions docs/src/main/tut/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
layout: home
title: PureConfig
---

# {{page.title}}
# PureConfig

<img src="img/pureconfig-logo-1040x1200.png" width="130px" height="150px" align="right" alt="PureConfig">

Expand Down
4 changes: 2 additions & 2 deletions example/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name := "example"

version := "1.0"

scalaVersion := "2.12.6"
scalaVersion := "2.12.7"

libraryDependencies ++= Seq(
"com.github.pureconfig" %% "pureconfig" % "0.9.2")

crossScalaVersions := Seq("2.11.12", "2.12.6")
crossScalaVersions := Seq("2.11.12", "2.12.7")

scalacOptions ++= Seq(
"-deprecation",
Expand Down
2 changes: 1 addition & 1 deletion modules/akka/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "pureconfig-akka"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.5.12")
"com.typesafe.akka" %% "akka-actor" % "2.5.17")

developers := List(
Developer("derekmorr", "Derek Morr", "[email protected]", url("https://github.com/derekmorr")),
Expand Down
2 changes: 1 addition & 1 deletion modules/cats-effect/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "pureconfig-cats-effect"

libraryDependencies ++= Seq(
"org.typelevel" %% "cats-effect" % "0.10.1")
"org.typelevel" %% "cats-effect" % "1.0.0")

developers := List(
Developer("keirlawson", "Keir Lawson", "[email protected]", url("https://github.com/keirlawson")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package object catseffect {

private def configToF[F[_], A](getConfig: () => Either[ConfigReaderFailures, A])(implicit F: Sync[F], reader: Derivation[ConfigReader[A]], ct: ClassTag[A]): F[A] = {
val delayedLoad = F.delay {
getConfig().leftMap(ConfigReaderException[A])
getConfig().leftMap[Throwable](ConfigReaderException[A])
}
delayedLoad.flatMap(F.fromEither)
delayedLoad.rethrow
}

/**
Expand Down
15 changes: 11 additions & 4 deletions modules/fs2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@ To load a configuration file from a path using cats-effect's `IO`:
```scala
import pureconfig.generic.auto._
import pureconfig.module.fs2._
import cats.effect.IO
import cats.effect.{IO, ContextShift}
import fs2.io.file

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext

import java.util.concurrent.Executors

case class MyConfig(somefield: Int, anotherfield: String)

val chunkSize = 4096

val configStream = file.readAll[IO](somePath, chunkSize)
implicit val contextShift: ContextShift[IO] = IO.contextShift(global)
val blockingEc: ExecutionContext = ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())

val load: IO[MyConfig] = streamConfig[IO, MyConfig](configStream)
val configStream = file.readAll[IO](somePath, blockingEc, chunkSize)

val load: IO[MyConfig] = streamConfig[IO, MyConfig](configStream, blockingEc)
```

To test that this `IO` does indeed return a `MyConfig` instance:
Expand All @@ -52,11 +58,12 @@ load.unsafeRunSync().equals(MyConfig(1234, "some string"))
To create a byte stream from a configuration:

```scala
import cats.implicits._
import pureconfig.module.fs2._
import fs2.text
import cats.effect.IO

import cats.instances.string._

val someConfig = MyConfig(1234, "some string")

val configStream: fs2.Stream[IO, Byte] = saveConfigToStream(someConfig)
Expand Down
4 changes: 2 additions & 2 deletions modules/fs2/build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name := "pureconfig-fs2"

libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % "0.10.4",
"co.fs2" %% "fs2-io" % "0.10.4")
"co.fs2" %% "fs2-core" % "1.0.0",
"co.fs2" %% "fs2-io" % "1.0.0")

developers := List(
Developer("keirlawson", "Keir Lawson", "[email protected]", url("https://github.com/keirlawson")))
Expand Down
12 changes: 7 additions & 5 deletions modules/fs2/src/main/scala/pureconfig/module/fs2/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import scala.concurrent.ExecutionContext
import scala.language.higherKinds
import scala.reflect.ClassTag

import _root_.fs2.{ Stream, async, io, text }
import cats.effect.{ Effect, Sync }
import _root_.fs2.{ Stream, io, text }
import cats.effect.{ Concurrent, Sync, ContextShift }
import cats.implicits._
import com.typesafe.config.{ ConfigFactory, ConfigRenderOptions }
import pureconfig.{ ConfigReader, ConfigWriter, Derivation }
Expand Down Expand Up @@ -38,15 +38,17 @@ package object fs2 {
* `A` from the configuration stream, or fail with a ConfigReaderException which in turn contains
* details on why it isn't possible
*/
def streamConfig[F[_], A](configStream: Stream[F, Byte])(implicit F: Effect[F], reader: Derivation[ConfigReader[A]], ct: ClassTag[A], ec: ExecutionContext): F[A] = {
def streamConfig[F[_], A](configStream: Stream[F, Byte], blockingExecutionContext: ExecutionContext)(
implicit
F: Concurrent[F], reader: Derivation[ConfigReader[A]], ct: ClassTag[A], CS: ContextShift[F]): F[A] = {
pipedStreams.flatMap {
case (in, out) =>
val outputSink = io.writeOutputStream[F](out.pure[F])
val outputSink = io.writeOutputStream[F](out.pure[F], blockingExecutionContext)
val sunkStream = configStream.to(outputSink)

val parseConfig = parseStream(in)

async.fork(sunkStream.compile.drain) >> parseConfig
Concurrent[F].start(sunkStream.compile.drain) >> parseConfig
}
}

Expand Down
15 changes: 11 additions & 4 deletions modules/fs2/src/main/tut/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ Files.write(somePath, fileContents.getBytes(StandardCharsets.UTF_8))
```tut:silent
import pureconfig.generic.auto._
import pureconfig.module.fs2._
import cats.effect.IO
import cats.effect.{IO, ContextShift}
import fs2.io.file
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext
import java.util.concurrent.Executors
case class MyConfig(somefield: Int, anotherfield: String)
val chunkSize = 4096
val configStream = file.readAll[IO](somePath, chunkSize)
implicit val contextShift: ContextShift[IO] = IO.contextShift(global)
val blockingEc: ExecutionContext = ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())
val load: IO[MyConfig] = streamConfig[IO, MyConfig](configStream)
val configStream = file.readAll[IO](somePath, blockingEc, chunkSize)
val load: IO[MyConfig] = streamConfig[IO, MyConfig](configStream, blockingEc)
```

To test that this `IO` does indeed return a `MyConfig` instance:
Expand All @@ -54,11 +60,12 @@ load.unsafeRunSync().equals(MyConfig(1234, "some string"))
To create a byte stream from a configuration:

```tut:silent
import cats.implicits._
import pureconfig.module.fs2._
import fs2.text
import cats.effect.IO
import cats.instances.string._
val someConfig = MyConfig(1234, "some string")
val configStream: fs2.Stream[IO, Byte] = saveConfigToStream(someConfig)
Expand Down
18 changes: 10 additions & 8 deletions modules/fs2/src/test/scala/pureconfig/module/fs2Suite.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pureconfig.module

import cats.effect.IO
import _root_.fs2.{ Scheduler, Stream, text }
import cats.effect.{ IO, Timer, ContextShift }
import _root_.fs2.{ Stream, text }
import pureconfig.generic.auto._
import pureconfig.module.{ fs2 => testee }
import org.scalatest.{ FlatSpec, Matchers }
Expand All @@ -14,12 +14,14 @@ import scala.concurrent.ExecutionContext

class fs2Suite extends FlatSpec with Matchers {

implicit val executionContext = ExecutionContext.global
val blockingEc = ExecutionContext.global

implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)
implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.global)

private def delayEachLine(stream: Stream[IO, String], delay: FiniteDuration) = {
val sch = Scheduler[IO](1)
val byLine = stream.through(text.lines)
sch.flatMap(_.fixedDelay[IO](delay)).zipWith(byLine)((_, line) => line).intersperse("\n")
Stream.fixedDelay[IO](delay).zipWith(byLine)((_, line) => line).intersperse("\n")
}

case class SomeCaseClass(somefield: Int, anotherfield: String)
Expand All @@ -29,15 +31,15 @@ class fs2Suite extends FlatSpec with Matchers {
val someConfig = "somefield=1234\nanotherfield=some string"
val configBytes = Stream.emit(someConfig).through(text.utf8Encode)

val myConfig = testee.streamConfig[IO, SomeCaseClass](configBytes)
val myConfig = testee.streamConfig[IO, SomeCaseClass](configBytes, blockingEc)

myConfig.unsafeRunSync() shouldBe SomeCaseClass(1234, "some string")
}

it should "error when stream is blank" in {
val blankStream = Stream.empty.covaryAll[IO, Byte]

val configLoad = testee.streamConfig[IO, SomeCaseClass](blankStream)
val configLoad = testee.streamConfig[IO, SomeCaseClass](blankStream, blockingEc)

configLoad.attempt.unsafeRunSync().left.value shouldBe a[ConfigReaderException[_]]

Expand All @@ -49,7 +51,7 @@ class fs2Suite extends FlatSpec with Matchers {
val configStream = Stream.emit(someConfig)
val configBytes = delayEachLine(configStream, 200.milliseconds).through(text.utf8Encode)

val myConfig = testee.streamConfig[IO, SomeCaseClass](configBytes)
val myConfig = testee.streamConfig[IO, SomeCaseClass](configBytes, blockingEc)

myConfig.unsafeRunSync() shouldBe SomeCaseClass(1234, "some string")
}
Expand Down
2 changes: 1 addition & 1 deletion modules/hadoop/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "pureconfig-hadoop"

libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-common" % "3.1.0" % "provided,tut")
"org.apache.hadoop" % "hadoop-common" % "3.1.1" % "provided,tut")

developers := List(
Developer("lmnet", "Yuriy Badalyantc", "[email protected]", url("https://github.com/lmnet")))
Expand Down
4 changes: 2 additions & 2 deletions modules/joda/build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name := "pureconfig-joda"

libraryDependencies ++= Seq(
"joda-time" % "joda-time" % "2.9.9",
"org.joda" % "joda-convert" % "2.0.1")
"joda-time" % "joda-time" % "2.10",
"org.joda" % "joda-convert" % "2.1.1")

developers := List(
Developer("melrief", "Mario Pastorelli", "[email protected]", url("https://github.com/melrief")),
Expand Down
2 changes: 1 addition & 1 deletion modules/scala-xml/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "pureconfig-scala-xml"

libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-xml" % "1.0.6")
"org.scala-lang.modules" %% "scala-xml" % "1.1.1")

developers := List(
Developer("derekmorr", "Derek Morr", "[email protected]", url("https://github.com/derekmorr")))
Expand Down
2 changes: 1 addition & 1 deletion modules/yaml/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "pureconfig-yaml"

libraryDependencies ++= Seq(
"org.yaml" % "snakeyaml" % "1.17")
"org.yaml" % "snakeyaml" % "1.23")

developers := List(
Developer("ruippeixotog", "Rui Gonçalves", "[email protected]", url("https://github.com/ruippeixotog")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ package object yaml {
using(Files.newBufferedReader(path)) { ioReader =>
// we are using `SafeConstructor` in order to avoid creating custom Java instances, leaking the PureConfig
// abstraction over SnakeYAML
val yamlObj = new Yaml(new SafeConstructor()).load(ioReader)
val yamlObj = new Yaml(new SafeConstructor()).load[AnyRef](ioReader)

yamlObjToConfigValue(yamlObj).right.flatMap { cv =>
reader.value.from(ConfigCursor(cv, Nil))
Expand All @@ -117,7 +117,7 @@ package object yaml {
handleYamlErrors(None) {
// we are using `SafeConstructor` in order to avoid creating custom Java instances, leaking the PureConfig
// abstraction over SnakeYAML
val yamlObj = new Yaml(new SafeConstructor()).load(content)
val yamlObj = new Yaml(new SafeConstructor()).load[AnyRef](content)

yamlObjToConfigValue(yamlObj).right.flatMap { cv =>
reader.value.from(ConfigCursor(cv, Nil))
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.2.1
sbt.version=1.2.4
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.7.22")
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.7.24")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.9")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.4")
Expand Down

0 comments on commit 87653cb

Please sign in to comment.