Skip to content

Commit

Permalink
Merge branch 'master' into enable-coverage-for-scala-3
Browse files Browse the repository at this point in the history
  • Loading branch information
ruippeixotog committed Apr 18, 2023
2 parents 0851c2e + 682df3b commit 142706a
Show file tree
Hide file tree
Showing 32 changed files with 219 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
### 0.17.3 (Apr 15, 2023)

Maintenance update to update dependency versions.

### 0.17.2 (Nov 7, 2022)

- New features
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -33,7 +33,7 @@ To use PureConfig in an existing SBT project with Scala 2.12 or a later version,
`build.sbt`:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig" % "0.17.3"
```

For a full example of `build.sbt` you can have a look at this [build.sbt](https://github.com/pureconfig/pureconfig/blob/master/example/build.sbt).
Expand Down
2 changes: 1 addition & 1 deletion modules/akka-http/README.md
Expand Up @@ -9,7 +9,7 @@ for other classes are welcome :)
In addition to [core PureConfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-akka-http" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-akka-http" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/akka/README.md
Expand Up @@ -7,7 +7,7 @@ Adds support for selected [Akka](http://akka.io/) classes to PureConfig.
In addition to [core PureConfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-akka" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-akka" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/cats-effect/README.md
Expand Up @@ -7,7 +7,7 @@ Adds support for loading configuration using [cats-effect](https://github.com/ty
In addition to [core pureconfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cats-effect" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cats-effect" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/cats-effect/build.sbt
Expand Up @@ -6,7 +6,7 @@ name := "pureconfig-cats-effect"
crossScalaVersions := Seq(scala212, scala213, scala3)

libraryDependencies ++= Seq(
"org.typelevel" %% "cats-effect" % "3.4.8"
"org.typelevel" %% "cats-effect" % "3.4.9"
)

developers := List(Developer("keirlawson", "Keir Lawson", "keirlawson@gmail.com", url("https://github.com/keirlawson")))
2 changes: 1 addition & 1 deletion modules/cats-effect2/README.md
Expand Up @@ -8,7 +8,7 @@ This is a backport of `pureconfig-cats-effect` to the old 2.* series.
In addition to [core pureconfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cats-effect2" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cats-effect2" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/cats/README.md
Expand Up @@ -9,7 +9,7 @@ classes.
In addition to [core pureconfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cats" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cats" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/circe/README.md
Expand Up @@ -7,7 +7,7 @@ Adds support for [Circe](https://circe.github.io/circe/) `Json` to PureConfig.
In addition to [core pureconfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-circe" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-circe" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/cron4s/README.md
Expand Up @@ -8,7 +8,7 @@ Adds support for [Cron4s](https://github.com/alonsodomin/cron4s)'s CronExpr clas
In addition to [core PureConfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cron4s" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cron4s" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/enum/README.md
Expand Up @@ -11,7 +11,7 @@ Automatically create a converter to read [enum](https://github.com/julienrf/enum
In addition to [core PureConfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-enum" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-enum" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/enumeratum/README.md
Expand Up @@ -11,7 +11,7 @@ Automatically create a converters to read [Enumeratum](https://github.com/lloydm
In addition to [core PureConfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-enumeratum" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-enumeratum" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/fs2/README.md
Expand Up @@ -7,7 +7,7 @@ Adds support for loading and saving configurations from [fs2](https://github.com
In addition to [core pureconfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-fs2" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-fs2" % "0.17.3"
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion modules/hadoop/README.md
Expand Up @@ -7,7 +7,7 @@ Adds support for selected [Hadoop](http://hadoop.apache.org/) classes to PureCon
In addition to [core PureConfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-hadoop" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-hadoop" % "0.17.3"
```

Also, `pureconfig-hadoop` depends on `hadoop-common` with `provided` scope. This means that you should explicitly add a dependency on `hadoop-common` or any other Hadoop library which depends on `hadoop-common`. Usually it would be something like this:
Expand Down
36 changes: 29 additions & 7 deletions modules/http4s/README.md
@@ -1,20 +1,28 @@

# Http4s module for PureConfig

Adds support for [Http4s](http://http4s.org/)'s Uri class to PureConfig. PRs adding support
Adds support for [Http4s](http://http4s.org/)'s `Uri` class to PureConfig. PRs adding support
for other classes are welcome :)

Support is also provided for some of the components of a `Uri`:

* `Uri.Scheme`
* `Uri.Path`
* `Uri.Host`
* `Uri.Ipv4Address`
* `Uri.Ipv6Address`

## Add pureconfig-http4s to your project

In addition to [core PureConfig](https://github.com/pureconfig/pureconfig), you'll need:

```scala
libraryDependencies += "com.github.pureconfig" %% "pureconfig-http4s" % "0.17.2"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-http4s" % "0.17.3"
```

## Example

To load an `Uri` into a configuration, create a class to hold it:
To load a `Uri` or one of `Uri`'s components into a configuration, create a class to hold it:

```scala
import org.http4s.Uri
Expand All @@ -23,15 +31,29 @@ import pureconfig._
import pureconfig.generic.auto._
import pureconfig.module.http4s._

case class MyConfig(uri: Uri)
case class MyConfig(
uri: Uri,
scheme: Uri.Scheme,
host: Uri.Host,
path: Uri.Path,
ipAddress1: Uri.Ipv4Address,
ipAddress2: Uri.Ipv6Address
)
```

We can read a `MyConfig` with the following code:

```scala
val conf = parseString("""{ uri: "http://http4s.org/" }""")
// conf: com.typesafe.config.Config = Config(SimpleConfigObject({"uri":"http://http4s.org/"}))
val conf = parseString("""{
uri: "http://http4s.org/",
scheme: "https",
host: "www.foo.com",
path: "relative/path/to/resource.txt",
ip-address-1: "192.168.1.1",
ip-address-2: "2001:db8:85a3:8d3:1319:8a2e:370:7344"
}""")
// conf: com.typesafe.config.Config = Config(SimpleConfigObject({"host":"www.foo.com","ip-address-1":"192.168.1.1","ip-address-2":"2001:db8:85a3:8d3:1319:8a2e:370:7344","path":"relative/path/to/resource.txt","scheme":"https","uri":"http://http4s.org/"}))

ConfigSource.fromConfig(conf).load[MyConfig]
// res0: ConfigReader.Result[MyConfig] = Right(MyConfig(http://http4s.org/))
// res0: ConfigReader.Result[MyConfig] = Right(MyConfig(http://http4s.org/,Scheme(https),www.foo.com,relative/path/to/resource.txt,Ipv4Address(192.168.1.1),[2001:db8:85a3:8d3:1319:8a2e:370:7344]))
```
30 changes: 26 additions & 4 deletions modules/http4s/docs/README.md
@@ -1,9 +1,17 @@

# Http4s module for PureConfig

Adds support for [Http4s](http://http4s.org/)'s Uri class to PureConfig. PRs adding support
Adds support for [Http4s](http://http4s.org/)'s `Uri` class to PureConfig. PRs adding support
for other classes are welcome :)

Support is also provided for some of the components of a `Uri`:

* `Uri.Scheme`
* `Uri.Path`
* `Uri.Host`
* `Uri.Ipv4Address`
* `Uri.Ipv6Address`

## Add pureconfig-http4s to your project

In addition to [core PureConfig](https://github.com/pureconfig/pureconfig), you'll need:
Expand All @@ -14,7 +22,7 @@ libraryDependencies += "com.github.pureconfig" %% "pureconfig-http4s" % "@VERSIO

## Example

To load an `Uri` into a configuration, create a class to hold it:
To load a `Uri` or one of `Uri`'s components into a configuration, create a class to hold it:

```scala mdoc:silent
import org.http4s.Uri
Expand All @@ -23,13 +31,27 @@ import pureconfig._
import pureconfig.generic.auto._
import pureconfig.module.http4s._

case class MyConfig(uri: Uri)
case class MyConfig(
uri: Uri,
scheme: Uri.Scheme,
host: Uri.Host,
path: Uri.Path,
ipAddress1: Uri.Ipv4Address,
ipAddress2: Uri.Ipv6Address
)
```

We can read a `MyConfig` with the following code:

```scala mdoc:to-string
val conf = parseString("""{ uri: "http://http4s.org/" }""")
val conf = parseString("""{
uri: "http://http4s.org/",
scheme: "https",
host: "www.foo.com",
path: "relative/path/to/resource.txt",
ip-address-1: "192.168.1.1",
ip-address-2: "2001:db8:85a3:8d3:1319:8a2e:370:7344"
}""")

ConfigSource.fromConfig(conf).load[MyConfig]
```
@@ -1,16 +1,55 @@
package pureconfig.module

import org.http4s.Uri
import scala.reflect.ClassTag

import org.http4s.{ParseResult, Uri}

import pureconfig.error.CannotConvert
import pureconfig.{ConfigReader, ConfigWriter}

package object http4s {
private def mkConfigReader[A](f: String => ParseResult[A])(implicit ct: ClassTag[A]): ConfigReader[A] =
ConfigReader.fromString { str =>
val className = ct.runtimeClass.getSimpleName()
f(str).fold(
err => Left(CannotConvert(str, className, err.sanitized)),
value => Right(value)
)
}

implicit val uriReader: ConfigReader[Uri] =
ConfigReader.fromString(str =>
Uri.fromString(str).fold(err => Left(CannotConvert(str, "Uri", err.sanitized)), uri => Right(uri))
)
mkConfigReader[Uri](Uri.fromString)

implicit val uriWriter: ConfigWriter[Uri] =
ConfigWriter[String].contramap(_.renderString)

implicit val uriSchemeReader: ConfigReader[Uri.Scheme] =
mkConfigReader[Uri.Scheme](Uri.Scheme.fromString)

implicit val uriSchemeWriter: ConfigWriter[Uri.Scheme] =
ConfigWriter[String].contramap(_.value)

implicit val uriPathReader: ConfigReader[Uri.Path] =
ConfigReader.stringConfigReader.map(Uri.Path.unsafeFromString) // .fromString is deprecated

implicit val uriPathWriter: ConfigWriter[Uri.Path] =
ConfigWriter[String].contramap(_.renderString)

implicit val uriHostReader: ConfigReader[Uri.Host] =
mkConfigReader[Uri.Host](Uri.Host.fromString)

implicit val uriHostWriter: ConfigWriter[Uri.Host] =
ConfigWriter[String].contramap(_.renderString)

implicit val uriIpv4AddressReader: ConfigReader[Uri.Ipv4Address] =
mkConfigReader[Uri.Ipv4Address](Uri.Ipv4Address.fromString)

implicit val uriIpv4AddressWriter: ConfigWriter[Uri.Ipv4Address] =
ConfigWriter[String].contramap(_.renderString)

implicit val uriIpv6AddressReader: ConfigReader[Uri.Ipv6Address] =
mkConfigReader[Uri.Ipv6Address](Uri.Ipv6Address.fromString)

implicit val uriWriter: ConfigWriter[Uri] = ConfigWriter[String].contramap(_.renderString)
implicit val uriIpv6AddressWriter: ConfigWriter[Uri.Ipv6Address] =
ConfigWriter[String].contramap(_.value) // Uses .value so that we can round-trip as Ipv6Address
}

0 comments on commit 142706a

Please sign in to comment.