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

Scala 3 [draft] #182

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.12, 2.13.4]
scala: [3.0.0-RC1]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.12]
scala: [3.0.0-RC1]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -97,22 +97,12 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.12.12)
- name: Download target directories (3.0.0-RC1)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.12.12-${{ matrix.java }}
name: target-${{ matrix.os }}-3.0.0-RC1-${{ matrix.java }}

- name: Inflate target directories (2.12.12)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.4)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.13.4-${{ matrix.java }}

- name: Inflate target directories (2.13.4)
- name: Inflate target directories (3.0.0-RC1)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
18 changes: 4 additions & 14 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ short or generic names if possible.

* Mention in the example section and in the release notes in README.md

### Release Process

Commit but don't push all changes.

```
> sbt

sbt> release
## Tests

//manual check of console output looks correct

sbt> sonatypeRelease

> git push
The tests dont have good descriptive labels as at Dec 2020. I've long believed that the best label for a well written test is the source code itself. The plan is to use [Sourcecode]() to generate labels based on the test code, however Sourcecode isn't published for Scala3+ScalaJS yet. Try again in a month or two.rr

### Release Process

```
Releases now occur via Github Actions CI. The server uses Ben Hutchison's Sonatype credentials to publish to maven. Push a tag as per https://github.com/olafurpg/sbt-ci-release#git
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ includes convenience extension methods for Scala standard library classes, inclu

The library arose from this [Cats issue](https://github.com/typelevel/cats/issues/791) and is a [Typelevel member](http://typelevel.org/projects/).

Mouse is published for Scala 2.12 and 2.13. For Scala.jvm:
Mouse 1.x is published for Scala 3.x and is the main branch. Mouse 0.26 is published for Scala 2.12 and 2.13, and will be updated for bugfixes but not new features in future.

For Scala.jvm:

`"org.typelevel" %% "mouse" % version`

Expand Down Expand Up @@ -101,6 +103,11 @@ mapped: Map[Int,Int] = Map(2 -> 2, 6 -> 4)

#### Release Notes

Version `1.0.0-M1` (Jan 20) is a rewrite to Scala 3.x syntax. It is source-compatible with earlier versions but binary-incompatible. Mouse aims to add a minimal feature set over the standard library and Cats; its ideal is to "disappear over time". Accordingly, this version deprecates a number of methods, either because good solutions are available upstream now, or to align names better with emerging standard library conventions.

The 1.x series migrates from Scalatest and Scalacheck to Munit, in pursuit of simplicitly and low maintenance. Note in this release, there's a change to how the library's extensions are made available. The syntax `import mouse.all._` remains, but it is no longer a package object inheriting from a stack of traits. Rather `all` is a package and we use Scala 3's `export` to export extension methods via this package. For users, there should be no change required beyond recompilation.


Version `0.26` (Dec 20) adds `applyIf` for Boolean and builds against Cats 2.3.0.

Version `0.25` (Apr 20) adds Scalajs 1.x support.
Expand Down
103 changes: 32 additions & 71 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,83 +1,44 @@
import ReleaseTransformations._
import sbt._
import sbtcrossproject.CrossPlugin.autoImport.crossProject

ThisBuild / githubWorkflowPublishTargetBranches := Seq()

ThisBuild / crossScalaVersions := Seq("2.12.12", "2.13.4")

lazy val commonSettings = Def.settings(
scalaVersion := "2.13.1",
crossScalaVersions := (ThisBuild / crossScalaVersions).value
)

lazy val root = project.in(file(".")).aggregate(js, jvm).
settings(
name := "mouse",
commonSettings,
publish / skip := true,
sonatypeProfileName := "org.typelevel",
releaseCrossBuild := true
)

lazy val cross = crossProject(JSPlatform, JVMPlatform).in(file(".")).
inThisBuild(Seq(
name := "mouse",
version := "1.0.0-M1",
scalaVersion := "3.0.0-RC1",
crossScalaVersions := Seq("3.0.0-RC1"),
organization := "org.typelevel",
sonatypeProfileName := "org.typelevel",
testFrameworks += new TestFramework("munit.Framework"),
Test / publishArtifact := false,
))

lazy val root = crossProject(JSPlatform, JVMPlatform).withoutSuffixFor(JVMPlatform).in(file(".")).
settings(
name := "mouse",
organization := "org.typelevel",
commonSettings,
sonatypeProfileName := "org.typelevel",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.4.2",
"org.scalatest" %%% "scalatest" % "3.2.3" % Test,
"org.scalatestplus" %%% "scalacheck-1-15" % "3.2.3.0" % Test,
compilerPlugin("org.typelevel" %% "kind-projector" % "0.11.3" cross CrossVersion.full)
"org.scalameta" %% "munit" % "0.7.22" % Test,
),
scalacOptions ++= Seq("-feature", "-deprecation", "-language:higherKinds"),

licenses += ("MIT license", url("http://opensource.org/licenses/MIT")),
homepage := Some(url("https://github.com/typelevel/mouse")),
developers := List(Developer("benhutchison", "Ben Hutchison", "[email protected]", url = url("https://github.com/benhutchison"))),
scmInfo := Some(ScmInfo(url("https://github.com/typelevel/mouse"), "scm:git:https://github.com/typelevel/mouse.git")),
scalacOptions ++= Seq("-feature", "-deprecation", "-language:implicitConversions", "-language:higherKinds"),
scalacOptions ++= {
scalaVersion.value match {
case v if v.startsWith("2.13") => Nil
case _ => Seq("-Ypartial-unification")
}
},
Test / publishArtifact := false,
pomIncludeRepository := { _ => false },
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
publishArtifacts,
setNextVersion,
commitNextVersion,
)
)

ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches :=
Seq(RefPredicate.StartsWith(Ref.Tag("v")))

ThisBuild / githubWorkflowPublishPreamble +=
WorkflowStep.Use(UseRef.Public("olafurpg", "setup-gpg", "v3"))

ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
)
)

lazy val jvm = cross.jvm
lazy val js = cross.js
inThisBuild(Seq(
githubWorkflowTargetTags ++= Seq("v*"),
githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v"))),

githubWorkflowPublishPreamble += WorkflowStep.Use(UseRef.Public("olafurpg", "setup-gpg", "v3")),

githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
))
))
3 changes: 0 additions & 3 deletions js/src/main/scala/mouse/js.scala

This file was deleted.

13 changes: 0 additions & 13 deletions js/src/main/scala/mouse/package.scala

This file was deleted.

3 changes: 3 additions & 0 deletions jvm/src/main/scala/mouse/all/allJvm.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package mouse.all

export mouse.stringJvm._
4 changes: 0 additions & 4 deletions jvm/src/main/scala/mouse/jvm.scala

This file was deleted.

13 changes: 0 additions & 13 deletions jvm/src/main/scala/mouse/package.scala

This file was deleted.

22 changes: 22 additions & 0 deletions jvm/src/main/scala/mouse/string.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package mouse

import java.net.{MalformedURLException, URI, URISyntaxException, URL}

import cats.data.Validated
import cats.syntax.either._

object stringJvm:
extension (s: String)

@inline def parseURL: Either[MalformedURLException, URL] = Either.catchOnly[MalformedURLException](new URL(s))

@inline def parseURLValidated: Validated[MalformedURLException, URL] = parseURL.toValidated

@inline def parseURLOption: Option[URL] = parseURL.toOption

@inline def parseURI: Either[URISyntaxException, URI] = Either.catchOnly[URISyntaxException](new URI(s))

@inline def parseURIValidated: Validated[URISyntaxException, URI] = parseURI.toValidated

@inline def parseURIOption: Option[URI] = parseURI.toOption

26 changes: 0 additions & 26 deletions jvm/src/main/scala/mouse/stringJvm.scala

This file was deleted.

42 changes: 9 additions & 33 deletions jvm/src/test/scala/mouse/StringJvmTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,14 @@ import java.net.{MalformedURLException, URI, URISyntaxException, URL}

import cats.Eq
import cats.syntax.all._
import mouse.string._
import mouse.stringJvm._

class StringJvmTests extends MouseSuite {
class StringJvmTests extends MouseSuite:

given Eq[URL] = Eq.fromUniversalEquals
given Eq[URI] = Eq.fromUniversalEquals

test("parseFloat") {
"123.1".parseFloat should ===(123.1f.asRight[NumberFormatException])
}

test("parseURL") {
implicit val urlEq: Eq[URL] = Eq.fromUniversalEquals
implicit val malformedURLExceptionEq: Eq[MalformedURLException] =
new Eq[MalformedURLException] {
override def eqv(x: MalformedURLException, y: MalformedURLException): Boolean =
x.getMessage == y.getMessage
}

"http://example.com".parseURL should ===(new URL("http://example.com").asRight[MalformedURLException])

"blah".parseURL should ===(new MalformedURLException("no protocol: blah").asLeft)
}

test("parseURI") {
implicit val urlEq: Eq[URI] = Eq.fromUniversalEquals
implicit val malformedURIExceptionEq: Eq[URISyntaxException] =
new Eq[URISyntaxException] {
override def eqv(x: URISyntaxException, y: URISyntaxException): Boolean =
x.getMessage == y.getMessage
}

"http://example.com".parseURI should ===(new URI("http://example.com").asRight[URISyntaxException])

"invalid uri".parseURI should ===(new URISyntaxException("invalid uri", "Illegal character in path at index 7").asLeft)
}

}
testEquals("http://example.com".parseURL, URL("http://example.com").asRight[MalformedURLException])
testEquals("blah".parseURL, new MalformedURLException("no protocol: blah").asLeft)
testEquals("http://example.com".parseURI, new URI("http://example.com").asRight[URISyntaxException])
testEquals("invalid uri".parseURI, new URISyntaxException("invalid uri", "Illegal character in path at index 7").asLeft)
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.5")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.11")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.10.1")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.5")
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")
11 changes: 2 additions & 9 deletions shared/src/main/scala/mouse/MouseFunctions.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package mouse

trait MouseFunctions {
@deprecated("Use `: Unit` type ascription instead, see also https://github.com/scala/scala/pull/7563", "1.0.0")
def ignore(a: Any): Unit = ()

/**
* Evaluate but ignore the provided argument. This function makes value discarding an explicit operation,
* helpful when the `-Ywarn-discard-values` compiler flag is enable to explicitly satisfy warnings.
*
* @param a - the value to be evaluated and ignored.
*/
def ignore(a: Any): Unit = ()

}
14 changes: 0 additions & 14 deletions shared/src/main/scala/mouse/all.scala

This file was deleted.

Loading