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

Updates #507

Merged
merged 6 commits into from
Jan 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
scala: ['2.12.15', '2.13.8', '3.1.0']
scala: ['2.12.18', '2.13.12', '3.3.1']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = 3.7.17
runner.dialect = "scala213source3"
78 changes: 25 additions & 53 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ val scala212 = "2.12.18"
val scala213 = "2.13.12"
val scala3 = "3.3.1"

val zioVersion = "1.0.16"
val zio2Version = "2.0.2"
val zio2Version = "2.0.21"

val scalacOptions212 = Seq("-Ypartial-unification", "-deprecation", "-target:jvm-1.8")
val scalacOptions213 = Seq("-deprecation", "-target:jvm-1.8")
def scalacOptions212(jdk: Int) = Seq("-Ypartial-unification", "-deprecation", "-Xsource:3", "-release", jdk.toString)
def scalacOptions213(jdk: Int) = Seq("-deprecation", "-Xsource:3", "-release", jdk.toString)
def scalacOptions3(jdk: Int) = Seq("-deprecation", "-Ykind-projector", "-release", jdk.toString)

import microsites.ConfigYml
import sbt.enablePlugins
import xerial.sbt.Sonatype._

import scala.xml.{Node => XmlNode, NodeSeq => XmlNodeSeq, _}
import scala.xml.transform.{RewriteRule, RuleTransformer}

dynverSonatypeSnapshots in ThisBuild := true
ThisBuild / dynverSonatypeSnapshots := true

def commonSettings(jdk: Int) = Seq(
organization := "io.github.vigoo",
Expand All @@ -30,15 +28,15 @@ def commonSettings(jdk: Int) = Seq(
)
}),
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-collection-compat" % "2.8.1"
"org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0"
),

coverageEnabled in(Test, compile) := true,
coverageEnabled in(Compile, compile) := false,
Test / compile / coverageEnabled := true,
Compile / compile / coverageEnabled := false,

scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => scalacOptions212
case Some((2, 13)) => scalacOptions213
case Some((2, 12)) => scalacOptions212(jdk)
case Some((2, 13)) => scalacOptions213(jdk)
case Some((3, _)) => scalacOptions3(jdk)
case _ => Nil
}),
Expand Down Expand Up @@ -74,47 +72,21 @@ lazy val prox = project.in(file("."))
.settings(
name := "prox",
organization := "io.github.vigoo",
skip in publish := true
publish / skip := true
)
.aggregate(proxCore, proxFS2, proxFS23, proxZStream, proxZStream2, proxJava9)
.aggregate(proxCore, proxFS23, proxZStream2, proxJava9)

lazy val proxCore = Project("prox-core", file("prox-core")).settings(commonSettings(8))

lazy val proxFS2 = Project("prox-fs2", file("prox-fs2")).settings(commonSettings(8)).settings(
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-effect" % "2.5.5",
"co.fs2" %% "fs2-core" % "2.5.11",
"co.fs2" %% "fs2-io" % "2.5.11",

"dev.zio" %% "zio" % zioVersion % "test",
"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test",
"dev.zio" %% "zio-interop-cats" % "2.5.1.0" % "test",
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
).dependsOn(proxCore)

lazy val proxFS23 = Project("prox-fs2-3", file("prox-fs2-3")).settings(commonSettings(8)).settings(
libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % "3.3.0",
"co.fs2" %% "fs2-io" % "3.3.0",
"co.fs2" %% "fs2-core" % "3.9.3",
"co.fs2" %% "fs2-io" % "3.9.3",

"dev.zio" %% "zio" % zioVersion % "test",
"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test",
"dev.zio" %% "zio-interop-cats" % "3.2.9.1" % "test",
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
).dependsOn(proxCore)

lazy val proxZStream = Project("prox-zstream", file("prox-zstream")).settings(commonSettings(8)).settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-streams" % zioVersion,
"dev.zio" %% "zio-prelude" % "1.0.0-RC8",

"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test",
"dev.zio" %% "zio" % zio2Version % "test",
"dev.zio" %% "zio-test" % zio2Version % "test",
"dev.zio" %% "zio-test-sbt" % zio2Version % "test",
"dev.zio" %% "zio-interop-cats" % "23.1.0.0" % "test",
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
).dependsOn(proxCore)
Expand All @@ -125,7 +97,7 @@ lazy val proxZStream2 = Project("prox-zstream-2", file("prox-zstream-2")).settin
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zio2Version,
"dev.zio" %% "zio-streams" % zio2Version,
"dev.zio" %% "zio-prelude" % "1.0.0-RC15",
"dev.zio" %% "zio-prelude" % "1.0.0-RC21",

"dev.zio" %% "zio-test" % zio2Version % "test",
"dev.zio" %% "zio-test-sbt" % zio2Version % "test",
Expand All @@ -142,17 +114,17 @@ lazy val docs = project
.settings(
addCompilerPlugin("org.typelevel" %% s"kind-projector" % "0.13.2" cross CrossVersion.full),
publishArtifact := false,
skip in publish := true,
publish / skip := true,
scalaVersion := scala213,
name := "prox",
description := "A Scala library for working with system processes",
git.remoteRepo := "git@github.com:vigoo/prox.git",
siteSubdirName in ScalaUnidoc := "api",
addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), siteSubdirName in ScalaUnidoc),
ScalaUnidoc / siteSubdirName := "api",
addMappingsToSiteDir(ScalaUnidoc / packageDoc / mappings, ScalaUnidoc / siteSubdirName),
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(
proxCore,
proxFS2,
proxZStream,
proxFS23,
proxZStream2,
proxJava9
),
micrositeUrl := "https://vigoo.github.io",
Expand Down Expand Up @@ -181,7 +153,7 @@ lazy val docs = project
micrositeAnalyticsToken := "UA-56320875-3",
micrositePushSiteWith := GitHub4s,
micrositeGithubToken := sys.env.get("GITHUB_TOKEN"),
includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf" | "*.txt" | "*.xml" | "*.svg",
makeSite / includeFilter := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf" | "*.txt" | "*.xml" | "*.svg",
// Temporary fix to avoid including mdoc in the published POM

// skip dependency elements with a scope
Expand All @@ -197,4 +169,4 @@ lazy val docs = project
}
}).transform(node).head
}
).dependsOn(proxCore, proxFS2/* todo , proxFS23 */, proxZStream, proxJava9)
).dependsOn(proxCore, proxFS23, proxZStream2, proxJava9)
5 changes: 1 addition & 4 deletions docs/docs/docs/fs2/custom-runners.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import cats.Traverse
import scala.concurrent.ExecutionContext
import io.github.vigoo.prox._

implicit val contextShift = IO.contextShift(ExecutionContext.global)
val (blocker, _) = Blocker[IO].allocated.unsafeRunSync()

val prox = ProxFS2[IO](blocker)
val prox = ProxFS2[IO]
import prox._
```

Expand Down
5 changes: 1 addition & 4 deletions docs/docs/docs/fs2/customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import cats.effect._
import scala.concurrent.ExecutionContext
import io.github.vigoo.prox._

implicit val contextShift = IO.contextShift(ExecutionContext.global)
val (blocker, _) = Blocker[IO].allocated.unsafeRunSync()

val prox = ProxFS2[IO](blocker)
val prox = ProxFS2[IO]
import prox._
```

Expand Down
5 changes: 1 addition & 4 deletions docs/docs/docs/fs2/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ the `Prox` module:
import cats.effect._
import scala.concurrent.ExecutionContext
import io.github.vigoo.prox._

implicit val contextShift = IO.contextShift(ExecutionContext.global)
val (blocker, _) = Blocker[IO].allocated.unsafeRunSync()
```

```scala mdoc
val prox = ProxFS2[IO](blocker)
val prox = ProxFS2[IO]
import prox._
```

Expand Down
9 changes: 3 additions & 6 deletions docs/docs/docs/fs2/processgroups.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import cats.effect._
import scala.concurrent.ExecutionContext
import io.github.vigoo.prox._

implicit val contextShift = IO.contextShift(ExecutionContext.global)
val (blocker, _) = Blocker[IO].allocated.unsafeRunSync()

val prox = ProxFS2[IO](blocker)
val prox = ProxFS2[IO]
import prox._
```

Expand Down Expand Up @@ -44,12 +41,12 @@ following not very useful example capitalizes each word coming through:
```scala mdoc:silent
val customPipe: fs2.Pipe[IO, Byte, Byte] =
(s: fs2.Stream[IO, Byte]) => s
.through(fs2.text.utf8Decode) // decode UTF-8
.through(fs2.text.utf8.decode) // decode UTF-8
.through(fs2.text.lines) // split to lines
.map(_.split(' ').toVector) // split lines to words
.map(v => v.map(_.capitalize).mkString(" "))
.intersperse("\n") // remerge lines
.through(fs2.text.utf8Encode) // encode as UTF-8
.through(fs2.text.utf8.encode) // encode as UTF-8

val group3 = Process("echo", List("hello world")).via(customPipe).to(Process("wc", List("-w")))
```
19 changes: 8 additions & 11 deletions docs/docs/docs/fs2/redirection.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import cats.effect._
import scala.concurrent.ExecutionContext
import io.github.vigoo.prox._

implicit val contextShift = IO.contextShift(ExecutionContext.global)
val (blocker, _) = Blocker[IO].allocated.unsafeRunSync()

val prox = ProxFS2[IO](blocker)
val prox = ProxFS2[IO]
import prox._
```

Expand All @@ -34,13 +31,13 @@ Let's see an example of this (redirection methods are described below on this pa
import cats.implicits._

val proc1 = Process("echo", List("Hello world"))
val proc2 = proc1 ># fs2.text.utf8Decode
val proc2 = proc1 ># fs2.text.utf8.decode
```

It is no longer possible to redirect the output of `proc2`:

```scala mdoc:fail
val proc3 = proc2 >? fs2.text.utf8Decode[IO].andThen(fs2.text.lines)
val proc3 = proc2 >? fs2.text.utf8.decode[IO].andThen(fs2.text.lines)
```

Many redirection methods have an _operator_ version but all of them have alphanumberic
Expand Down Expand Up @@ -136,17 +133,17 @@ process they came from:


```scala mdoc:silent
import fs2.concurrent.Queue
import cats.effect.std.Queue

for {
errors <- Queue.unbounded[IO, String]
parseLines = fs2.text.utf8Decode[IO].andThen(fs2.text.lines)
parseLines = fs2.text.utf8.decode[IO].andThen(fs2.text.lines)

p1 = Process("proc1")
p2 = Process("proc2")
group = (p1 | p2).customizedPerProcess.errorsToSink {
case p if p == p1 => parseLines.andThen(_.map(s => "P1: " + s)).andThen(_.through(errors.enqueue))
case p if p == p2 => parseLines.andThen(_.map(s => "P2: " + s)).andThen(_.through(errors.enqueue))
case p if p == p1 => parseLines.andThen(_.map(s => "P1: " + s)).andThen(_.evalMap(errors.offer))
case p if p == p2 => parseLines.andThen(_.map(s => "P2: " + s)).andThen(_.evalMap(errors.offer))
}
} yield ()
```
Expand All @@ -171,7 +168,7 @@ These type aliases can be used to define functions performing redirection on arb

```scala mdoc
def logErrors[P <: Process.UnboundEProcess[_]](proc: P) = {
val target = fs2.text.utf8Decode[IO].andThen(fs2.text.lines).andThen(_.evalMap(line => IO(println(line))))
val target = fs2.text.utf8.decode[IO].andThen(fs2.text.lines).andThen(_.evalMap(line => IO(println(line))))
proc !> target
}

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/docs/fs2/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ implicit val runner: ProcessRunner[JVMProcessInfo] = new JVMProcessRunner
val process = Process("echo", List("hello"))

val result1 = process.run()
val result2 = process.start().use { fiber =>
val result2 = process.start().flatMap { fiber =>
fiber.join
}

Expand Down
13 changes: 6 additions & 7 deletions docs/docs/docs/zstream/custom-runners.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ title: Custom runners

```scala mdoc:invisible
import zio._
import zio.blocking.Blocking
import zio.stream._
import io.github.vigoo.prox._
import io.github.vigoo.prox.zstream._
Expand Down Expand Up @@ -39,21 +38,21 @@ class DockerizedProcessRunner[Info](processRunner: ProcessRunner[Info],
image: DockerImage)
extends ProcessRunner[DockerProcessInfo[Info]] {

override def startProcess[O, E](process: Process[O, E]): ZIO[Blocking, ProxError, RunningProcess[O, E, DockerProcessInfo[Info]]] = {
override def startProcess[O, E](process: Process[O, E]): ZIO[Any, ProxError, RunningProcess[O, E, DockerProcessInfo[Info]]] = {
for {
container <- generateContainerName
runningProcess <- processRunner
.startProcess(wrapInDocker(process, container))
} yield runningProcess.mapInfo(info => DockerProcessInfo(container, info))
}

override def startProcessGroup[O, E](processGroup: ProcessGroup[O, E]): ZIO[Blocking, ProxError, RunningProcessGroup[O, E, DockerProcessInfo[Info]]] = {
override def startProcessGroup[O, E](processGroup: ProcessGroup[O, E]): ZIO[Any, ProxError, RunningProcessGroup[O, E, DockerProcessInfo[Info]]] = {
ZIO.foreach(processGroup.originalProcesses.toVector)(key => generateContainerName.map(c => key -> c)).flatMap { keyAndNames =>
val nameMap = keyAndNames.toMap
val names = keyAndNames.map(_._2)
val modifiedProcessGroup = processGroup.map(new ProcessGroup.Mapper[O, E] {
def mapFirst[P <: Process[ZStream[Blocking, ProxError, Byte], E]](process: P): P = wrapInDocker(process, names.head).asInstanceOf[P]
def mapInnerWithIdx[P <: Process.UnboundIProcess[ZStream[Blocking, ProxError, Byte], E]](process: P, idx: Int): P =
def mapFirst[P <: Process[ZStream[Any, ProxError, Byte], E]](process: P): P = wrapInDocker(process, names.head).asInstanceOf[P]
def mapInnerWithIdx[P <: Process.UnboundIProcess[ZStream[Any, ProxError, Byte], E]](process: P, idx: Int): P =
wrapInDocker(process, names(idx)).asInstanceOf[P]
def mapLast[P <: Process.UnboundIProcess[O, E]](process: P): P = wrapInDocker(process, names.last).asInstanceOf[P]
})
Expand All @@ -62,8 +61,8 @@ class DockerizedProcessRunner[Info](processRunner: ProcessRunner[Info],
}
}

private def generateContainerName: ZIO[Blocking, ProxError, DockerContainer] =
ZIO.effect(DockerContainer(UUID.randomUUID().toString)).mapError(UnknownProxError)
private def generateContainerName: ZIO[Any, ProxError, DockerContainer] =
ZIO.attempt(DockerContainer(UUID.randomUUID().toString)).mapError(UnknownProxError)

private def wrapInDocker[O, E](process: Process[O, E], container: DockerContainer): Process[O, E] = {
val envVars = process.environmentVariables.flatMap { case (key, value) => List("-e", s"$key=$value") }.toList
Expand Down
9 changes: 4 additions & 5 deletions docs/docs/docs/zstream/processgroups.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ title: Process groups
# Connecting processes together via pipes
```scala mdoc:invisible
import zio._
import zio.blocking.Blocking
import zio.stream._
import zio.prelude._
import io.github.vigoo.prox._
Expand Down Expand Up @@ -36,14 +35,14 @@ val group1 = Process("grep", List("ERROR")) | Process("sort")
val group2 = group1 | Process("uniq", List("-c"))
```

A custom pipe (when using `via`) can be anything of the type `ZStream[Blocking, ProxError, Byte] => ZStream[Blocking, ProxError, Byte])`.
A custom pipe (when using `via`) can be anything of the type `ZStream[any, ProxError, Byte] => ZStream[any, ProxError, Byte])`.
The following not very useful example capitalizes each word coming through:

```scala mdoc:silent
val customPipe: ProxPipe[Byte, Byte] =
(s: ZStream[Blocking, ProxError, Byte]) => s
.transduce(ZTransducer.utf8Decode) // decode UTF-8
.transduce(ZTransducer.splitLines) // split to lines
(s: ZStream[Any, ProxError, Byte]) => s
.via(ZPipeline.utf8Decode.mapError(UnknownProxError.apply)) // decode UTF-8
.via(ZPipeline.splitLines) // split to lines
.map(_.split(' ').toVector) // split lines to words
.map(v => v.map(_.capitalize).mkString(" "))
.intersperse("\n") // remerge lines
Expand Down
Loading
Loading