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

Upgrade sbt #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Scala CI

on:
push:
branches: [ 'main' ]
branches: [ 'master' ]
pull_request:
branches: [ '**' ]

Expand Down
18 changes: 18 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version = "3.7.17"

runner.dialect = scala213source3
align.preset = more
align.openParenCallSite = true
align.openParenDefnSite = true
style = defaultWithAlign
maxColumn = 115
indent.extendSite = 4
indent.withSiteRelativeToExtends = 2
docstrings = "ScalaDoc"
docstrings.style = Asterisk
docstrings.removeEmpty = true
continuationIndent.callSite = 2
continuationIndent.defnSite = 4
includeCurlyBraceInSelectChains = false
project.git = true
project.excludeFilters = ["target/"]
32 changes: 18 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import sbt.Keys._

Global / onChangedBuildSource := ReloadOnSourceChanges

lazy val buildSettings = Seq(
organization := "io.kontainers",
scalaVersion := "2.13.10",
organization := "io.kontainers",
scalaVersion := "2.13.12",
crossScalaVersions := Seq("2.12.15", scalaVersion.value)
)

lazy val publishSettings = Seq(
publishMavenStyle := true,
Test/ publishArtifact := false,
publishMavenStyle := true,
Test / publishArtifact := false,
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
publishTo := Some(
if (isSnapshot.value)
Opts.resolver.sonatypeSnapshots
Opts.resolver.sbtSnapshots
else
Opts.resolver.sonatypeStaging),
pomIncludeRepository := { x => false },
pomExtra := (
Opts.resolver.sonatypeStaging
),
pomIncludeRepository := { x => false },
pomExtra := (
<url>https://github.com/kontainers/PureCSV</url>
<licenses>
<license>
Expand All @@ -42,15 +45,16 @@ lazy val publishSettings = Seq(
)
)

lazy val pureCSV = project.in(file(".")).
settings(buildSettings).
settings(publishSettings).
settings(
lazy val pureCSV = project
.in(file("."))
.settings(buildSettings)
.settings(publishSettings)
.settings(
name := "purecsv",
scalacOptions ++= Seq("-feature", "-deprecation"),
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.10",
"com.chuusai" %% "shapeless" % "2.3.10",
"com.github.tototoshi" %% "scala-csv" % "1.3.10",
"org.scalatest" %% "scalatest" % "3.2.14" % Test
"org.scalatest" %% "scalatest" % "3.2.17" % Test
)
)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.2
sbt.version=1.9.7
20 changes: 10 additions & 10 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* sbt-updates
*
* for easier dependency updates monitoring
* @see https://github.com/rtimush/sbt-updates
*/
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")

addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")

addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
* sbt-updates
*
* for easier dependency updates monitoring
* @see
* https://github.com/rtimush/sbt-updates
*/
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
4 changes: 2 additions & 2 deletions src/main/scala/purecsv/config/Headers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ sealed trait Headers

object Headers {
object ReadAndIgnore extends Headers
object None extends Headers
object ParseHeaders extends Headers
object None extends Headers
object ParseHeaders extends Headers
}
2 changes: 1 addition & 1 deletion src/main/scala/purecsv/config/Trimming.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ object Trimming {
object TrimAll extends Trimming {
override def trim(s: String): String = s.trim
}
}
}
34 changes: 22 additions & 12 deletions src/main/scala/purecsv/csviterable/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import java.io.{File, PrintWriter}
import purecsv.unsafe.RecordSplitter.defaultFieldSeparatorStr
import purecsv.unsafe.converter.Converter


package object csviterable {


implicit class CSVRecord[A,R <: Converter[A,Seq[String]]](a: A)(implicit rfc: R) {
implicit class CSVRecord[A, R <: Converter[A, Seq[String]]](a: A)(implicit rfc: R) {
def toCSV(sep: String = defaultFieldSeparatorStr): String =
rfc.to(a).mkString(sep)
}
Expand All @@ -32,11 +30,14 @@ package object csviterable {
* Helper class that adds methods for converting and writing an Iterable of [[A]] into CSV format.
*
* @param iter
* @param rfc The implicit class that allows converting [[A]] to a [[Seq]]
* @tparam A The type that can be converted to a CSV record
* @tparam R The type of the converter [[A]] <-> [[Seq]]
* @param rfc
* The implicit class that allows converting [[A]] to a [[Seq]]
* @tparam A
* The type that can be converted to a CSV record
* @tparam R
* The type of the converter [[A]] <-> [[Seq]]
*/
implicit class CSVIterable[A,R <: Converter[A,Seq[String]]](iter: Iterable[A])(implicit rfc: R) {
implicit class CSVIterable[A, R <: Converter[A, Seq[String]]](iter: Iterable[A])(implicit rfc: R) {

/** Convert all the values in [[iter]] into CSV lines */
def toCSVLines(sep: String = defaultFieldSeparatorStr): Iterable[String] =
Expand All @@ -48,17 +49,23 @@ package object csviterable {
/**
* Convert [[iter]] to CSV lines and then write them into the [[PrintWriter]]
*
* @param writer Where to write the CSV lines
* @param sep The CSV separator
* @param header An optional header. If it is set, then it is printed as first line
* @param writer
* Where to write the CSV lines
* @param sep
* The CSV separator
* @param header
* An optional header. If it is set, then it is printed as first line
*/
def writeCSVTo(writer: PrintWriter, sep: String, header: Option[Seq[String]]): Unit = {
header.foreach(h => writer.println(h.mkString(sep)))
toCSVLines(sep).foreach(writer.println)
}

/** @see [[writeCSVTo]] */
def writeCSVToFile(file: File, sep: String = defaultFieldSeparatorStr, header: Option[Seq[String]] = None): Unit = {
def writeCSVToFile(file: File,
sep: String = defaultFieldSeparatorStr,
header: Option[Seq[String]] = None
): Unit = {
val writer = new PrintWriter(file, "utf-8")
try {
this.writeCSVTo(writer, sep, header)
Expand All @@ -68,7 +75,10 @@ package object csviterable {
}

/** @see [[writeCSVToFile(File,String,Option[Seq[String]]):Unit*]] */
def writeCSVToFileName(fileName: String, sep: String = defaultFieldSeparatorStr, header: Option[Seq[String]] = None): Unit = {
def writeCSVToFileName(fileName: String,
sep: String = defaultFieldSeparatorStr,
header: Option[Seq[String]] = None
): Unit = {
writeCSVToFile(new File(fileName), sep, header)
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/scala/purecsv/safe/converter/Converter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ package purecsv.safe.converter

import scala.util.{Failure, Success, Try}


/**
* A version of [[purecsv.unsafe.converter.Converter]] with a special from method
* for safe conversions. The method [[Converter!from()]] is defined starting from
* [[Converter!tryFrom()]] but it throw [[IllegalArgumentException]] when
* the result is [[Failure]]
* A version of [[purecsv.unsafe.converter.Converter]] with a special from method for safe conversions. The method
* [[Converter!from()]] is defined starting from [[Converter!tryFrom()]] but it throw [[IllegalArgumentException]]
* when the result is [[Failure]]
*/
trait Converter[A,B] extends purecsv.unsafe.converter.Converter[A,B] {
trait Converter[A, B] extends purecsv.unsafe.converter.Converter[A, B] {

/**
* @param b The starting value from which we try the conversion to [[A]]
* @return A value of type [[A]] wrapped in [[Success]] if the conversion is successful else [[Failure]] with the
* error
* @param b
* The starting value from which we try the conversion to [[A]]
* @return
* A value of type [[A]] wrapped in [[Success]] if the conversion is successful else [[Failure]] with the error
*/
def tryFrom(b: B): Try[A]
final override def from(b: B): A = tryFrom(b) match {
Expand All @@ -37,7 +37,7 @@ trait Converter[A,B] extends purecsv.unsafe.converter.Converter[A,B] {
}

/** Converter from/to String */
trait StringConverter[A] extends Converter[A,String]
trait StringConverter[A] extends Converter[A, String]

object StringConverter {
def apply[A](implicit conv: StringConverter[A]): StringConverter[A] = conv
Expand All @@ -46,13 +46,13 @@ object StringConverter {
object StringConverterUtils {
def mkStringConverter[A](fromF: String => Try[A], toF: A => String) = new StringConverter[A] {
def tryFrom(s: String): Try[A] = fromF(s)
def to(a: A): String = toF(a)
def to(a: A): String = toF(a)
}
}

/** Converter from/to raw fields, represented as sequence of strings */
trait RawFieldsConverter[A] extends Converter[A,Seq[String]]
trait RawFieldsConverter[A] extends Converter[A, Seq[String]]

object RawFieldsConverter {
def apply[A](implicit conv: RawFieldsConverter[A]): RawFieldsConverter[A] = conv
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import shapeless.{::, Generic, HList, HNil}

import scala.util.{Failure, Success, Try}


package object rawfields {

import purecsv.safe.converter.RawFieldsConverter
Expand All @@ -31,30 +30,32 @@ package object rawfields {
implicit val deriveHNil: RawFieldsConverter[HNil] = new RawFieldsConverter[HNil] {
override def tryFrom(s: Seq[String]): Try[HNil] = s match {
case Nil => Success(HNil)
case _ => illegalConversion(s.mkString("[",", ","]"), "HNil")
case _ => illegalConversion(s.mkString("[", ", ", "]"), "HNil")
}
override def to(a: HNil): Seq[String] = Seq.empty
}

implicit def deriveHCons[V, T <: HList]
(implicit sc: StringConverter[V],
fto: RawFieldsConverter[T])
: RawFieldsConverter[V :: T] = new RawFieldsConverter[V :: T] {
implicit def deriveHCons[V, T <: HList](implicit
sc: StringConverter[V],
fto: RawFieldsConverter[T]
): RawFieldsConverter[V :: T] = new RawFieldsConverter[V :: T] {
override def tryFrom(s: Seq[String]): Try[V :: T] = s match {
case Nil => illegalConversion("", classOf[V :: T].toString)
case _ => for {
head <- sc.tryFrom(s.head)
tail <- fto.tryFrom(s.tail)
} yield head :: tail
case _ =>
for {
head <- sc.tryFrom(s.head)
tail <- fto.tryFrom(s.tail)
} yield head :: tail
}

override def to(a: ::[V, T]): Seq[String] = sc.to(a.head) +: fto.to(a.tail)
}

implicit def deriveClass[A, R](implicit gen: Generic.Aux[A, R],
conv: RawFieldsConverter[R])
: RawFieldsConverter[A] = new RawFieldsConverter[A] {
implicit def deriveClass[A, R](implicit
gen: Generic.Aux[A, R],
conv: RawFieldsConverter[R]
): RawFieldsConverter[A] = new RawFieldsConverter[A] {
override def tryFrom(s: Seq[String]): Try[A] = conv.tryFrom(s).map(gen.from)
override def to(a: A): Seq[String] = conv.to(gen.to(a))
override def to(a: A): Seq[String] = conv.to(gen.to(a))
}
}
36 changes: 18 additions & 18 deletions src/main/scala/purecsv/safe/converter/defaults/string/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ import purecsv.unsafe.converter.StringConverterUtils

import scala.util.{Success, Try}


package object string {
import purecsv.safe.converter.StringConverter
import purecsv.safe.converter.StringConverterUtils.mkStringConverter
import purecsv.unsafe.converter.defaults.string.{strToBool, strToChar}

implicit val boolc: StringConverter[Boolean] = mkStringConverter(s => Try(strToBool(s)),_.toString)
implicit val bytec: StringConverter[Byte] = mkStringConverter(s => Try(s.toByte),_.toString)
implicit val charc: StringConverter[Char] = mkStringConverter(s => Try(strToChar(s)),_.toString)
implicit val doublec: StringConverter[Double] = mkStringConverter(s => Try(s.toDouble),_.toString)
implicit val floatc: StringConverter[Float] = mkStringConverter(s => Try(s.toFloat),_.toString)
implicit val intc: StringConverter[Int] = mkStringConverter(s => Try(s.toInt),_.toString)
implicit val longc: StringConverter[Long] = mkStringConverter(s => Try(s.toLong),_.toString)
implicit val shortc: StringConverter[Short] = mkStringConverter(s => Try(s.toShort),_.toString)
implicit val uuidc: StringConverter[UUID] = mkStringConverter(s => Try(UUID.fromString(s)),_.toString)
implicit val stringc: StringConverter[String] = new StringConverter[String] {
implicit val boolc: StringConverter[Boolean] = mkStringConverter(s => Try(strToBool(s)), _.toString)
implicit val bytec: StringConverter[Byte] = mkStringConverter(s => Try(s.toByte), _.toString)
implicit val charc: StringConverter[Char] = mkStringConverter(s => Try(strToChar(s)), _.toString)
implicit val doublec: StringConverter[Double] = mkStringConverter(s => Try(s.toDouble), _.toString)
implicit val floatc: StringConverter[Float] = mkStringConverter(s => Try(s.toFloat), _.toString)
implicit val intc: StringConverter[Int] = mkStringConverter(s => Try(s.toInt), _.toString)
implicit val longc: StringConverter[Long] = mkStringConverter(s => Try(s.toLong), _.toString)
implicit val shortc: StringConverter[Short] = mkStringConverter(s => Try(s.toShort), _.toString)
implicit val uuidc: StringConverter[UUID] = mkStringConverter(s => Try(UUID.fromString(s)), _.toString)
implicit val stringc: StringConverter[String] = new StringConverter[String] {
override def tryFrom(s: String): Try[String] = Success(s)
override def to(s: String): String = StringConverterUtils.quoteTextIfNecessary(s)
override def to(s: String): String = StringConverterUtils.quoteTextIfNecessary(s)
}

implicit def optionc[A](implicit ac: StringConverter[A]): StringConverter[Option[A]] = new StringConverter[Option[A]] {
override def tryFrom(s: String): Try[Option[A]] = s match {
case "" => Success(None)
case s => ac.tryFrom(s).map(Some(_))
implicit def optionc[A](implicit ac: StringConverter[A]): StringConverter[Option[A]] =
new StringConverter[Option[A]] {
override def tryFrom(s: String): Try[Option[A]] = s match {
case "" => Success(None)
case s => ac.tryFrom(s).map(Some(_))
}
override def to(v: Option[A]): String = v.map(ac.to).getOrElse("")
}
override def to(v: Option[A]): String = v.map(ac.to).getOrElse("")
}
}
Loading
Loading