Skip to content

Commit

Permalink
Merge pull request #25 from cabalism/fix/verbosity-14
Browse files Browse the repository at this point in the history
Add verbosity
  • Loading branch information
philderbeast authored Dec 5, 2023
2 parents 25a1b64 + adff18f commit 82ea394
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* With `dhall2cabal` or `dhall2stack` generated projects, source dependencies
and their commentary are only included if there are dependencies in a
category; internal or external, dependency or fork.
* Show comments with `Verbosity.Info` or not with `Verbosity.Quiet`.

### 1.0.0
* First release
101 changes: 69 additions & 32 deletions text-templates/dhall2cabal.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ let counts = ./internal/comments/counts.dhall

let intros = ./internal/comments/intros.dhall

in \(stackage-location : TYPES.Stackage) ->
in \(verbosity : TYPES.Verbosity) ->
\(stackage-location : TYPES.Stackage) ->
\(stackage-resolver : Text) ->
\(pkg-set : TYPES.PkgSet) ->
\ ( pkg-config
Expand Down Expand Up @@ -48,20 +49,43 @@ in \(stackage-location : TYPES.Stackage) ->

let pkgs-comment =
merge
{ AllPkgs =
\(pkgs : List Text) ->
"-- We have ${countPkgs pkgs} packages."
, PkgUpgrade =
\(pkgs : TYPES.PkgTodoList) ->
"-- We have upgraded ${countPkgs
pkgs.done} packages and have ${countPkgs
pkgs.todo} yet to do."
{ Quiet = ""
, Info =
let comments =
merge
{ AllPkgs =
\(pkgs : List Text) ->
[ "We have ${countPkgs pkgs} packages." ]
, PkgUpgrade =
\(pkgs : TYPES.PkgTodoList) ->
[ "We have upgraded ${countPkgs
pkgs.done} packages and have ${countPkgs
pkgs.todo} yet to do."
]
}
pkg-set

in "\n"
++ concatMapSep
"\n"
Text
(\(s : Text) -> "-- ${s}")
comments
}
pkg-set
verbosity

let cabal = ./cabal/package.dhall

let comment = concatMapSep "\n" Text (\(s : Text) -> "-- ${s}")
let comment =
merge
{ Quiet = \(_ : List Text) -> ""
, Info =
\(xs : List Text) ->
"\n" ++ concatMapSep "\n" Text (\(s : Text) -> "-- ${s}") xs
}
verbosity

let null-source-deps = L.null TYPES.SourceRepoPkg source-deps

let dep-counts =
{ deps-external = count deps-external
Expand All @@ -70,54 +94,67 @@ in \(stackage-location : TYPES.Stackage) ->
, forks-internal = count forks-internal
}

let deps-count-comment = comment (counts dep-counts)
let deps-count-comment =
merge
{ Quiet = ""
, Info =
if null-source-deps
then ""
else "\n"
++ concatMapSep
"\n"
Text
(\(s : Text) -> "-- ${s}")
(counts dep-counts)
}
verbosity

let constraints-intro =
merge
{ Quiet = ""
, Info =
''

-- Version equality constraints.''
}
verbosity

in "${./import-stackage.dhall stackage-location stackage-resolver}"
++ ''

in ''
${./import-stackage.dhall stackage-location stackage-resolver}
${pkgs-comment}''
++ ''

${pkgs-comment}
${cabal.packages pkgs}''
++ ( if L.null TYPES.SourceRepoPkg source-deps
++ ( if null-source-deps
then ""
else ''

${deps-count-comment}''
else "${deps-count-comment}"
++ ( if N.isZero dep-counts.deps-external
then ""
else ''


${comment intros.deps-external}
${cabal.repo-items deps-external}''
)
++ ( if N.isZero dep-counts.deps-internal
then ""
else ''


${comment intros.deps-internal}
${cabal.repo-items deps-internal}''
)
++ ( if N.isZero dep-counts.forks-external
then ""
else ''


${comment intros.forks-external}
${cabal.repo-items forks-external}''
)
++ ( if N.isZero dep-counts.forks-internal
then ""
else ''


${comment intros.forks-internal}
${cabal.repo-items forks-internal}''
)
++ "\n"
)
++ ''


-- Version equality constraints.
${cabal.constraints pkg-config.constraints}
''
${constraints-intro}
${cabal.constraints pkg-config.constraints}''
108 changes: 76 additions & 32 deletions text-templates/dhall2stack.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ let counts = ./internal/comments/counts.dhall

let intros = ./internal/comments/intros.dhall

in \(stackage-resolver : Text) ->
in \(verbosity : TYPES.Verbosity) ->
\(stackage-resolver : Text) ->
\(pkg-set : TYPES.PkgSet) ->
\ ( pkg-config
: { constraints : List TYPES.PkgVer
Expand Down Expand Up @@ -47,73 +48,116 @@ in \(stackage-resolver : Text) ->

let pkgs-comment =
merge
{ AllPkgs =
\(pkgs : List Text) -> "# We have ${countPkgs pkgs} packages."
, PkgUpgrade =
\(pkgs : TYPES.PkgTodoList) ->
"# We have upgraded ${countPkgs
pkgs.done} packages and have ${countPkgs
pkgs.todo} yet to do."
{ Quiet = ""
, Info =
let comments =
merge
{ AllPkgs =
\(pkgs : List Text) ->
[ "We have ${countPkgs pkgs} packages." ]
, PkgUpgrade =
\(pkgs : TYPES.PkgTodoList) ->
[ "We have upgraded ${countPkgs
pkgs.done} packages and have ${countPkgs
pkgs.todo} yet to do."
]
}
pkg-set

in "\n"
++ concatMapSep
"\n"
Text
(\(s : Text) -> "# ${s}")
comments
}
pkg-set
verbosity

let stack = ./stack/package.dhall

let comment = concatMapSep "\n" Text (\(s : Text) -> "# ${s}")
let nested-comment = concatMapSep "\n" Text (\(s : Text) -> " # ${s}")
let nested-comment =
merge
{ Quiet = \(_ : List Text) -> ""
, Info =
\(xs : List Text) ->
"\n"
++ concatMapSep "\n" Text (\(s : Text) -> " # ${s}") xs
}
verbosity

let null-source-deps = L.null TYPES.SourceRepoPkg source-deps

let dep-counts =
{ deps-external = count deps-external
, deps-internal = count deps-internal
, forks-external = count forks-external
, forks-internal = count forks-internal
{ deps-external = count deps-external
, deps-internal = count deps-internal
, forks-external = count forks-external
, forks-internal = count forks-internal
}

let deps-count-comment =
"\n"
++ merge
{ Quiet = ""
, Info =
if null-source-deps
then ""
else concatMapSep
"\n"
Text
(\(s : Text) -> "# ${s}")
(counts dep-counts)
++ "\n"
}
verbosity

let constraints-intro =
merge
{ Quiet = [] : List Text
, Info =
[ "Package versions for published packages either not on Stackage or"
, "not matching the version on Stackage for the resolver we use."
, "These package-version extra dependencies are equivalent to cabal constraints."
]
}
verbosity

let deps-count-comment = comment (counts dep-counts)
in "resolver: ${stackage-resolver}"
++ ''

in ''
resolver: ${stackage-resolver}
${pkgs-comment}''
++ ''

${pkgs-comment}
${stack.packages pkgs}
${deps-count-comment}
''
++ ( if L.null TYPES.SourceRepoPkg source-deps
${stack.packages pkgs}''
++ "${deps-count-comment}"
++ ( if null-source-deps
&& L.null TYPES.PkgVer pkg-config.constraints
then "extra-deps: []"
else "extra-deps:\n"
else "extra-deps:"
++ ( if N.isZero dep-counts.deps-external
then ""
else ''

${nested-comment intros.deps-external}
${stack.repo-items deps-external}''
)
++ ( if N.isZero dep-counts.deps-internal
then ""
else ''

${nested-comment intros.deps-internal}
${stack.repo-items deps-internal}''
)
++ ( if N.isZero dep-counts.forks-external
then ""
else ''

${nested-comment intros.forks-external}
${stack.repo-items forks-external}''
)
++ ( if N.isZero dep-counts.forks-internal
then ""
else ''

${nested-comment intros.forks-internal}
${stack.repo-items forks-internal}''
)
++ ''

# Package versions for published packages either not on Stackage or
# not matching the version on Stackage for the resolver we use.
# These package-version extra dependencies are equivalent to cabal constraints.
${nested-comment constraints-intro}
${stack.constraints pkg-config.constraints}''
)
1 change: 1 addition & 0 deletions types.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
, Stackage = ./types/Stackage.dhall
, DepCounts = ./types/DepCounts.dhall
, DepIntros = ./types/DepIntros.dhall
, Verbosity = ./types/Verbosity.dhall
}
1 change: 1 addition & 0 deletions types/Verbosity.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
< Quiet | Info >

0 comments on commit 82ea394

Please sign in to comment.