Skip to content

Commit

Permalink
Upgrade scalafmt and enable trailing commas (#8437)
Browse files Browse the repository at this point in the history
This PR updates scalafmt and enables trailingCommas =
multiple. Unfortunately, scalafmt broke the version field which means
we cannot fully preserve the rest of the config. I’ve made some
attempts to stay reasonably close to the original config but couldn’t
find an exact equivalent in a lot of cases. I don’t feel strongly
about any of the settings so happy to change them to something else.

As announced, this will be merged on Saturday to avoid too many conflicts.

changelog_begin
changelog_end
  • Loading branch information
cocreature authored Jan 9, 2021
1 parent 329685a commit 22ce940
Show file tree
Hide file tree
Showing 1,213 changed files with 24,572 additions and 20,660 deletions.
5 changes: 2 additions & 3 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version = "1.5.1"

project.git = true

align = none # never align to make the fmt more diff friendly
align.preset = none # never align to make the fmt more diff friendly
maxColumn = 100
runner.fatalWarnings = true
trailingCommas = multiple
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ trait BazelRunfiles {

private val inBazelEnvironment =
Set("RUNFILES_DIR", "JAVA_RUNFILES", "RUNFILES_MANIFEST_FILE", "RUNFILES_MANIFEST_ONLY").exists(
sys.env.contains)
sys.env.contains
)

def rlocation(path: String): String =
if (inBazelEnvironment)
Expand Down
24 changes: 17 additions & 7 deletions compatibility/sandbox-migration/src/com/daml/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ object Application {
Command().withCreate(
CreateCommand(
Some(template.identifier),
Some(argument)
Some(argument),
)
)
),
ledgerId = client.ledgerId.unwrap,
applicationId = applicationId,
commandId = UUID.randomUUID.toString
commandId = UUID.randomUUID.toString,
)
for {
tree <- submitAndWait(commands)
Expand All @@ -128,7 +128,7 @@ object Application {
),
ledgerId = client.ledgerId.unwrap,
applicationId = applicationId,
commandId = UUID.randomUUID.toString
commandId = UUID.randomUUID.toString,
)
for {
tree <- submitAndWait(commands)
Expand All @@ -140,7 +140,8 @@ object Application {

def activeContracts(template: Template): Future[Seq[CreatedEvent]] = {
val filter = TransactionFilter(
List((name, Filters(Some(InclusiveFilters(Seq(template.identifier)))))).toMap)
List((name, Filters(Some(InclusiveFilters(Seq(template.identifier)))))).toMap
)
client.activeContractSetClient
.getActiveContracts(filter, verbose = true)
.runWith(Sink.seq)
Expand All @@ -152,14 +153,23 @@ object Application {
List(
(
name,
Filters(Some(InclusiveFilters(templates
.map(_.identifier)))))).toMap)
Filters(
Some(
InclusiveFilters(
templates
.map(_.identifier)
)
)
),
)
).toMap
)
client.transactionClient
.getTransactions(
LedgerOffset(LedgerOffset.Value.Boundary(LedgerOffset.LedgerBoundary.LEDGER_BEGIN)),
Some(LedgerOffset(LedgerOffset.Value.Boundary(LedgerOffset.LedgerBoundary.LEDGER_END))),
filter,
verbose = true
verbose = true,
)
.runWith(Sink.seq[Transaction])
}
Expand Down
3 changes: 2 additions & 1 deletion compatibility/sandbox-migration/src/com/daml/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ object Config {
new ProposeAccept(proposer, accepter, note)
case _ =>
throw new IllegalArgumentException(s"Illegal test name or parameters '$s'")
})
}
)

val parser: OptionParser[Config] = new scopt.OptionParser[Config]("migration-step") {
opt[Path]("dar")
Expand Down
18 changes: 11 additions & 7 deletions compatibility/sandbox-migration/src/com/daml/Divulgence.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.daml.ledger.client.LedgerClient
import com.daml.ledger.client.configuration.{
CommandClientConfiguration,
LedgerClientConfiguration,
LedgerIdRequirement
LedgerIdRequirement,
}
import spray.json.RootJsonFormat

Expand Down Expand Up @@ -100,13 +100,15 @@ final class Divulgence(

private val divulged: PartialFunction[CreatedEvent, Application.Contract] = {
case created: CreatedEvent
if created.createArguments.exists(_.fields.exists(r =>
r.label == "tag" && r.value.exists(_.getText.startsWith("divulging-")))) =>
if created.createArguments.exists(
_.fields
.exists(r => r.label == "tag" && r.value.exists(_.getText.startsWith("divulging-")))
) =>
Application.Contract(created.contractId)
}

override def execute(packageId: String, config: Config.Test)(
implicit ec: ExecutionContext,
override def execute(packageId: String, config: Config.Test)(implicit
ec: ExecutionContext,
esf: ExecutionSequencerFactory,
mat: Materializer,
): Future[Unit] =
Expand All @@ -118,13 +120,15 @@ final class Divulgence(
divulgence <- model.createAssetDivulgence(owner, divulgee)
oldAssets <- owner.activeContracts(model.Asset)
oldDivulgeeAssets <- Future.traverse(oldAssets.collect(divulged))(
model.fetchDivulgedAsset(_, divulgee))
model.fetchDivulgedAsset(_, divulgee)
)
asset <- model.createAsset(owner, s"divulging-$suffix")
_ <- model.divulge(asset, divulgence, owner)
_ <- model.createAsset(owner, s"private-$suffix")
newAssets <- owner.activeContracts(model.Asset)
newDivulgeeAssets <- Future.traverse(newAssets.collect(divulged))(
model.fetchDivulgedAsset(_, divulgee))
model.fetchDivulgedAsset(_, divulgee)
)
} yield {
saveAsJson(
config.outputFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.daml.ledger.client.LedgerClient
import com.daml.ledger.client.configuration.{
CommandClientConfiguration,
LedgerClientConfiguration,
LedgerIdRequirement
LedgerIdRequirement,
}
import com.daml.platform.participant.util.ValueConversions._
import JsonProtocol._
Expand Down Expand Up @@ -77,8 +77,8 @@ final class KeyTransfer(
None,
)

override def execute(packageId: String, config: Config.Test)(
implicit ec: ExecutionContext,
override def execute(packageId: String, config: Config.Test)(implicit
ec: ExecutionContext,
esf: ExecutionSequencerFactory,
mat: Materializer,
): Future[Unit] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import scala.util.control.NonFatal
object MigrationStep {

trait Test {
def execute(packageId: String, config: Config.Test)(
implicit ec: ExecutionContext,
def execute(packageId: String, config: Config.Test)(implicit
ec: ExecutionContext,
esf: ExecutionSequencerFactory,
mat: Materializer,
): Future[Unit]
Expand Down
31 changes: 15 additions & 16 deletions compatibility/sandbox-migration/src/com/daml/ProposeAccept.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.daml.ledger.client.LedgerClient
import com.daml.ledger.client.configuration.{
CommandClientConfiguration,
LedgerClientConfiguration,
LedgerIdRequirement
LedgerIdRequirement,
}
import com.daml.platform.participant.util.ValueConversions._
import spray.json.RootJsonFormat
Expand Down Expand Up @@ -87,8 +87,8 @@ final class ProposeAccept(
None,
)

override def execute(packageId: String, config: Config.Test)(
implicit ec: ExecutionContext,
override def execute(packageId: String, config: Config.Test)(implicit
ec: ExecutionContext,
esf: ExecutionSequencerFactory,
mat: Materializer,
): Future[Unit] =
Expand All @@ -108,18 +108,17 @@ final class ProposeAccept(
newProposals <- proposer.activeContracts(model.ProposeDeal)
newAccepted <- proposer.activeContracts(model.Deal)
newTransactions <- proposer.transactions(Seq(model.ProposeDeal, model.Deal))
} yield
saveAsJson(
config.outputFile,
ProposeAccept
.Result(
oldProposals.map(Application.ContractResult.fromCreateEvent),
newProposals.map(Application.ContractResult.fromCreateEvent),
oldAccepted.map(Application.ContractResult.fromCreateEvent),
newAccepted.map(Application.ContractResult.fromCreateEvent),
oldTransactions.map(Application.TransactionResult.fromTransaction),
newTransactions.map(Application.TransactionResult.fromTransaction),
),
)
} yield saveAsJson(
config.outputFile,
ProposeAccept
.Result(
oldProposals.map(Application.ContractResult.fromCreateEvent),
newProposals.map(Application.ContractResult.fromCreateEvent),
oldAccepted.map(Application.ContractResult.fromCreateEvent),
newAccepted.map(Application.ContractResult.fromCreateEvent),
oldTransactions.map(Application.TransactionResult.fromTransaction),
newTransactions.map(Application.TransactionResult.fromTransaction),
),
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ object ReplServiceMain extends App {
): Config = {
if (config.timeMode.exists(_ != timeMode)) {
throw new IllegalStateException(
"Static time mode (`-s`/`--static-time`) and wall-clock time mode (`-w`/`--wall-clock-time`) are mutually exclusive. The time mode must be unambiguous.")
"Static time mode (`-s`/`--static-time`) and wall-clock time mode (`-w`/`--wall-clock-time`) are mutually exclusive. The time mode must be unambiguous."
)
}
config.copy(timeMode = Some(timeMode))
}
Expand Down Expand Up @@ -80,13 +81,15 @@ object ReplServiceMain extends App {
}

TlsConfigurationCli.parse(this, colSpacer = " ")((f, c) =>
c copy (tlsConfig = f(c.tlsConfig)))
c copy (tlsConfig = f(c.tlsConfig))
)

opt[Int]("max-inbound-message-size")
.action((x, c) => c.copy(maxInboundMessageSize = x))
.optional()
.text(
s"Optional max inbound message size in bytes. Defaults to ${RunnerConfig.DefaultMaxInboundMessageSize}")
s"Optional max inbound message size in bytes. Defaults to ${RunnerConfig.DefaultMaxInboundMessageSize}"
)

opt[Unit]('w', "wall-clock-time")
.action { (_, c) =>
Expand All @@ -107,7 +110,8 @@ object ReplServiceMain extends App {
case (None, Some(_)) =>
failure("Must specified either both --ledger-host and --ledger-port or neither")
case _ => success
})
}
)
}
def parse(args: Array[String]): Option[Config] =
parser.parse(
Expand All @@ -121,7 +125,7 @@ object ReplServiceMain extends App {
maxInboundMessageSize = RunnerConfig.DefaultMaxInboundMessageSize,
timeMode = None,
applicationId = None,
)
),
)
}

Expand Down Expand Up @@ -150,7 +154,8 @@ object ReplServiceMain extends App {
val clients = Await.result(
Runner
.connect(participantParams, config.tlsConfig, config.maxInboundMessageSize),
30.seconds)
30.seconds,
)
val timeMode = config.timeMode.getOrElse(ScriptTimeMode.WallClock)

val server =
Expand Down Expand Up @@ -179,8 +184,8 @@ class ReplService(
timeMode: ScriptTimeMode,
ec: ExecutionContext,
esf: ExecutionSequencerFactory,
mat: Materializer)
extends ReplServiceGrpc.ReplServiceImplBase
mat: Materializer,
) extends ReplServiceGrpc.ReplServiceImplBase
with StrictLogging {
var signatures: Map[PackageId, PackageSignature] = Map.empty
var compiledDefinitions: Map[SDefinitionRef, SDefinition] = Map.empty
Expand All @@ -195,7 +200,8 @@ class ReplService(

override def loadPackage(
req: LoadPackageRequest,
respObs: StreamObserver[LoadPackageResponse]): Unit = {
respObs: StreamObserver[LoadPackageResponse],
): Unit = {
val (pkgId, pkg) = Decode.decodeArchiveFromInputStream(req.getPackage.newInput)
val newSignatures = signatures.updated(pkgId, AstUtil.toSignature(pkg))
val newCompiledDefinitions = compiledDefinitions ++
Expand All @@ -208,7 +214,8 @@ class ReplService(

override def runScript(
req: RunScriptRequest,
respObs: StreamObserver[RunScriptResponse]): Unit = {
respObs: StreamObserver[RunScriptResponse],
): Unit = {
val lfVer = LanguageVersion(LanguageVersion.Major.V1, LanguageVersion.Minor(req.getMinor))
val dop: Decode.OfPackage[_] = Decode.decoders
.lift(lfVer)
Expand All @@ -228,7 +235,9 @@ class ReplService(

var scriptExpr: SExpr = SEVal(
LfDefRef(
Identifier(homePackageId, QualifiedName(mod.name, DottedName.assertFromString("expr")))))
Identifier(homePackageId, QualifiedName(mod.name, DottedName.assertFromString("expr")))
)
)
if (!results.isEmpty) {
scriptExpr = SEApp(scriptExpr, results.map(SEValue(_)).toArray)
}
Expand All @@ -246,24 +255,27 @@ class ReplService(
.runWithClients(clients)
._2
.map { v =>
(v, req.getFormat match {
case RunScriptRequest.Format.TEXT_ONLY =>
v match {
case SValue.SText(t) => t
case _ => ""
}
case RunScriptRequest.Format.JSON =>
try {
LfValueCodec.apiValueToJsValue(v.toValue).compactPrint
} catch {
case e @ SError.SErrorCrash(_) => {
logger.error(s"Cannot convert non-serializable value to JSON")
throw e
(
v,
req.getFormat match {
case RunScriptRequest.Format.TEXT_ONLY =>
v match {
case SValue.SText(t) => t
case _ => ""
}
}
case RunScriptRequest.Format.UNRECOGNIZED =>
throw new RuntimeException("Unrecognized response format")
})
case RunScriptRequest.Format.JSON =>
try {
LfValueCodec.apiValueToJsValue(v.toValue).compactPrint
} catch {
case e @ SError.SErrorCrash(_) => {
logger.error(s"Cannot convert non-serializable value to JSON")
throw e
}
}
case RunScriptRequest.Format.UNRECOGNIZED =>
throw new RuntimeException("Unrecognized response format")
},
)
}
.onComplete {
case Failure(e: SError.SError) =>
Expand All @@ -282,7 +294,8 @@ class ReplService(

override def clearResults(
req: ClearResultsRequest,
respObs: StreamObserver[ClearResultsResponse]): Unit = {
respObs: StreamObserver[ClearResultsResponse],
): Unit = {
results = Seq()
respObs.onNext(ClearResultsResponse.newBuilder.build)
respObs.onCompleted
Expand Down
Loading

0 comments on commit 22ce940

Please sign in to comment.