Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scala 3 support #252

Merged

Conversation

vhiairrassary
Copy link
Contributor

@vhiairrassary vhiairrassary commented Sep 12, 2021

Simply adding Scala 3 in the build matrix is not enough as CirceConfigSpec cannot compile since it is using automatic derivation (io.circe.generic.auto._), which is not yet fully supported for Scala 3 (same about semi-automatic derivation).

As a workaround, I duplicated the test file and manually implemented the decoders. Would you be ok with this solution? Or you prefer to wait for the complete support?

Diff between files

Generated with diff -u src/test/scala-2/io.circe.config/CirceConfigSpec.scala src/test/scala-3/io.circe.config/CirceConfigSpec.scala

--- src/test/scala-2/io.circe.config/CirceConfigSpec.scala	2021-09-12 15:23:01.000000000 +0200
+++ src/test/scala-3/io.circe.config/CirceConfigSpec.scala	2021-09-12 15:24:46.000000000 +0200
@@ -20,7 +20,6 @@
 import org.scalatest.flatspec.AnyFlatSpec
 import com.typesafe.config.{parser => _, _}
 import io.circe.{parser => _, _}
-import io.circe.generic.auto._

 import scala.concurrent.duration._
 import java.time.Period
@@ -180,4 +179,71 @@
     o = 0,
     p = Period.ofWeeks(4)
   )
+
+    given typeWithAdderDecoder [T: Adder](using adderDecoder: Decoder[T]): Decoder[TypeWithAdder[T]] = { hCursor =>
+    for {
+      typeWithAdder <- hCursor.downField("typeWithAdder").as[T]
+    } yield {
+      TypeWithAdder(typeWithAdder)
+    }
+  }
+
+  given Decoder[Nested] = { hCursor =>
+    for {
+      obj <- hCursor.downField("obj").as[Boolean]
+    } yield {
+      Nested(obj)
+    }
+  }
+
+  given Decoder[TestConfig] = { hCursor =>
+    for {
+      a <- hCursor.downField("a").as[Int]
+      b <- hCursor.downField("b").as[Boolean]
+      c <- hCursor.downField("c").as[String]
+      d <- hCursor.downField("d").as[Option[String]]
+      e <- hCursor.downField("e").as[Nested]
+      f <- hCursor.downField("f").as[List[Double]]
+      g <- hCursor.downField("g").as[List[List[String]]]
+      h <- hCursor.downField("h").as[List[Nested]]
+      i <- hCursor.downField("i").as[FiniteDuration]
+      j <- hCursor.downField("j").as[ConfigMemorySize]
+      k <- hCursor.downField("k").as[Config]
+      l <- hCursor.downField("l").as[ConfigValue]
+      m <- hCursor.downField("m").as[TypeWithAdder[Int]]
+      n <- hCursor.downField("n").as[Double]
+      o <- hCursor.downField("o").as[Double]
+      p <- hCursor.downField("p").as[Period]
+    } yield {
+      TestConfig(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
+    }
+  }
+
+  given Decoder[ServerSettings] = { hCursor =>
+    for {
+      host <- hCursor.downField("host").as[String]
+      port <- hCursor.downField("port").as[Int]
+      timeout <- hCursor.downField("timeout").as[FiniteDuration]
+      maxUpload <- hCursor.downField("maxUpload").as[ConfigMemorySize]
+    } yield {
+      ServerSettings(host, port, timeout, maxUpload)
+    }
+  }
+
+  given Decoder[HttpSettings] = { hCursor =>
+    for {
+      version <- hCursor.downField("version").as[Double]
+      server <- hCursor.downField("server").as[ServerSettings]
+    } yield {
+      HttpSettings(version, server)
+    }
+  }
+
+  given Decoder[AppSettings] = { hCursor =>
+    for {
+      http <- hCursor.downField("http").as[HttpSettings]
+    } yield {
+      new AppSettings(http)
+    }
+  }
 }

Green build: https://github.com/vhiairrassary/circe-config/actions/runs/1226685164 (you can see the remaining warnings and scoverage disabled).

Remaining work

  • Fix bad options (found with publishLocal):
[warn] bad option '-Ywarn-dead-code' was ignored
[warn] bad option '-Ywarn-numeric-widen' was ignored
[warn] bad option '-Ywarn-unused:imports' was ignored
[warn] -- Deprecation Warning: /code/circe-config/src/main/scala/io.circe.config/package.scala:76:50
[warn] 76 |      obj => ConfigValueFactory.fromMap(obj.toMap.mapValues(jsonToConfigValue).toMap.asJava)
[warn]    |                                        ^^^^^^^^^^^^^^^^^^^
[warn]    |method mapValues in trait MapOps is deprecated since 2.13.0: Use .view.mapValues(f). A future version will include a strict version of this method (for now, .view.mapValues(f).toMap).
[warn] -- Deprecation Warning: /code/circe-config/src/main/scala/io.circe.config/parser.scala:70:36
[warn] 70 |        Json.fromFields(obj.asScala.mapValues(convertValueUnsafe))
[warn]    |                        ^^^^^^^^^^^^^^^^^^^^^
[warn]    |method mapValues in trait MapOps is deprecated since 2.13.0: Use .view.mapValues(f). A future version will include a strict version of this method (for now, .view.mapValues(f).toMap).
[warn] 5 warnings found
[warn] 5 warnings found
[info] Main Scala API documentation to /code/circe-config/target/scala-3.0.2/api...
[warn] bad option '-implicits' was ignored
[warn] bad option '-doc-source-url' was ignored
[warn] bad option '-doc-external-doc:[...]
[warn] scaladoc will ignore following non-existent paths: https:/github.com/circe/circe-config/tree/master€{FILE_PATH}.scala
[warn] Setting -sourcepath is currently not supported.
[warn] 5 warnings found

@vhiairrassary vhiairrassary force-pushed the vhiairrassary/add-scala-3-support branch 2 times, most recently from de0811e to f200fb3 Compare September 12, 2021 14:13
@vhiairrassary
Copy link
Contributor Author

Sorry for ping @travisbrown @jonas, can we get your feedbacks on this PR (you can have a look at #253 as well). That's the last dependency preventing us to finish Scala 3 migration. Happy to help, and of course update the PRs based on your feedbacks.

@travisbrown
Copy link
Member

Looks good to me, thanks!

@vhiairrassary
Copy link
Contributor Author

@travisbrown may I help for this PR?

@vhiairrassary
Copy link
Contributor Author

👋 @jonas, you seem to be listed as the maintainer of this repository. What can I do to help for this PR? Don't hesitate if you want me to change anything, rebase, etc. We would love to unlock Scala 3 users.

@travisbrown
Copy link
Member

I'm happy to merge as-is and I can publish a release, but I'd like to get a sign-off from @jonas as the project owner.

@vhiairrassary
Copy link
Contributor Author

@jonas can we help on anything?

@vhiairrassary
Copy link
Contributor Author

@travisbrown sorry to disturb you but do you have any idea on how to handle this situation?

@vhiairrassary vhiairrassary force-pushed the vhiairrassary/add-scala-3-support branch from f200fb3 to c518f62 Compare November 1, 2021 09:14
@vhiairrassary
Copy link
Contributor Author

I just rebased the PR, bumped Scala to 3.1.0 and modified it to use type class derivation instead of handwritten decoders (except for TypeWithAdder[T]).

For people looking for a workaround while waiting for this PR to merged:

  • remove circe-config from your sbt configuration (but keep its dependencies);
  • publish locally using sbt ++3.1.0 publishLocal;
  • copy the generated JAR in the lib directory of your project.

@arashi01
Copy link

arashi01 commented Nov 8, 2021

@travisbrown Sorry to continue to be a pain, but any chance this could also be merged?

cc @jonas

@arashi01
Copy link

arashi01 commented Dec 7, 2021

@travisbrown @jonas Giving this a final try. I really don't want to have to fork and publish separately. Please advise if this project is no longer maintained so those of us who are using it can plan and act accordingly.

@kovacshuni
Copy link

@arashi01 It's time to publish.

@kovacshuni
Copy link

I published this on the public Sonatype, you can use now:

"com.hunorkovacs" %% "circe-config" % "0.9.0"

Imports still remain io.circe.

Sorry for not waiting for anyone, this has been on hold for a long time. I'm not the developer of this project, I don't want to take any credit for this, haven't changed much in the README, nothing much in build.sbt developers. Let's see where we will be heading from now on.
I'm looking forward to merging @vhiairrassary 's other branch with cats-effect-3.

@kovacshuni
Copy link

Published circe-config for cats-effect-3 and Scala 3.2.0

"com.hunorkovacs" %% "circe-config" % "0.10.0"

https://github.com/kovacshuni/circe-config/releases/tag/0.10.0
again, thanks @vhiairrassary

@fthomas
Copy link
Collaborator

fthomas commented Feb 7, 2023

Thanks for the PR, @vhiairrassary!

I merged the latest changes from master into your branch and fixed a few build issues. I plan to release 0.10.0 with Scala 3 support soon.

@fthomas fthomas linked an issue Feb 7, 2023 that may be closed by this pull request
@fthomas fthomas merged commit 734bb47 into circe:master Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish library for Scala 3
5 participants