Skip to content

Commit

Permalink
Merge pull request #26 from cabalism/fix/pkg-counts-15
Browse files Browse the repository at this point in the history
Add package counts
  • Loading branch information
philderbeast authored Dec 5, 2023
2 parents 82ea394 + 4ed7a37 commit 60545b1
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 71 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
feature](https://github.com/haskell/cabal/issues/7833) is not yet implemented
for Cabal.
* The grammar of the comment describing source package dependencies and forks is
better, no longer saying 1 packages.
better, no longer saying 1 packages. Same goes for the comment describing
local packages.
* 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.
Expand Down
50 changes: 15 additions & 35 deletions text-templates/dhall2cabal.dhall
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
let TYPES = ../types.dhall

let COMMENTS = ./internal/comments.dhall

let cabal = ./cabal/package.dhall

let L = https://prelude.dhall-lang.org/List/package.dhall

let N = https://prelude.dhall-lang.org/Natural/package.dhall

let concatMapSep = https://prelude.dhall-lang.org/Text/concatMapSep

let counts = ./internal/comments/counts.dhall

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

in \(verbosity : TYPES.Verbosity) ->
\(stackage-location : TYPES.Stackage) ->
\(stackage-resolver : Text) ->
Expand Down Expand Up @@ -48,33 +48,13 @@ in \(verbosity : TYPES.Verbosity) ->
pkg-set

let pkgs-comment =
merge
{ 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
}
COMMENTS.pkg-counts
verbosity

let cabal = ./cabal/package.dhall
pkg-set
( \(comments : List Text) ->
"\n"
++ concatMapSep "\n" Text (\(s : Text) -> "-- ${s}") comments
)

let comment =
merge
Expand Down Expand Up @@ -105,7 +85,7 @@ in \(verbosity : TYPES.Verbosity) ->
"\n"
Text
(\(s : Text) -> "-- ${s}")
(counts dep-counts)
(COMMENTS.dep-counts dep-counts)
}
verbosity

Expand All @@ -132,25 +112,25 @@ in \(verbosity : TYPES.Verbosity) ->
++ ( if N.isZero dep-counts.deps-external
then ""
else ''
${comment intros.deps-external}
${comment COMMENTS.intros.deps-external}
${cabal.repo-items deps-external}''
)
++ ( if N.isZero dep-counts.deps-internal
then ""
else ''
${comment intros.deps-internal}
${comment COMMENTS.intros.deps-internal}
${cabal.repo-items deps-internal}''
)
++ ( if N.isZero dep-counts.forks-external
then ""
else ''
${comment intros.forks-external}
${comment COMMENTS.intros.forks-external}
${cabal.repo-items forks-external}''
)
++ ( if N.isZero dep-counts.forks-internal
then ""
else ''
${comment intros.forks-internal}
${comment COMMENTS.intros.forks-internal}
${cabal.repo-items forks-internal}''
)
++ "\n"
Expand Down
54 changes: 19 additions & 35 deletions text-templates/dhall2stack.dhall
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
let TYPES = ../types.dhall

let COMMENTS = ./internal/comments.dhall

let stack = ./stack/package.dhall

let L = https://prelude.dhall-lang.org/List/package.dhall

let N = https://prelude.dhall-lang.org/Natural/package.dhall

let concatMapSep = https://prelude.dhall-lang.org/Text/concatMapSep

let counts = ./internal/comments/counts.dhall

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

in \(verbosity : TYPES.Verbosity) ->
\(stackage-resolver : Text) ->
\(pkg-set : TYPES.PkgSet) ->
Expand Down Expand Up @@ -47,33 +47,13 @@ in \(verbosity : TYPES.Verbosity) ->
pkg-set

let pkgs-comment =
merge
{ 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
}
COMMENTS.pkg-counts
verbosity

let stack = ./stack/package.dhall
pkg-set
( \(comments : List Text) ->
"\n"
++ concatMapSep "\n" Text (\(s : Text) -> "# ${s}") comments
)

let nested-comment =
merge
Expand Down Expand Up @@ -105,7 +85,7 @@ in \(verbosity : TYPES.Verbosity) ->
"\n"
Text
(\(s : Text) -> "# ${s}")
(counts dep-counts)
(COMMENTS.dep-counts dep-counts)
++ "\n"
}
verbosity
Expand Down Expand Up @@ -136,25 +116,29 @@ in \(verbosity : TYPES.Verbosity) ->
++ ( if N.isZero dep-counts.deps-external
then ""
else ''
${nested-comment intros.deps-external}
${nested-comment
COMMENTS.intros.deps-external}
${stack.repo-items deps-external}''
)
++ ( if N.isZero dep-counts.deps-internal
then ""
else ''
${nested-comment intros.deps-internal}
${nested-comment
COMMENTS.intros.deps-internal}
${stack.repo-items deps-internal}''
)
++ ( if N.isZero dep-counts.forks-external
then ""
else ''
${nested-comment intros.forks-external}
${nested-comment
COMMENTS.intros.forks-external}
${stack.repo-items forks-external}''
)
++ ( if N.isZero dep-counts.forks-internal
then ""
else ''
${nested-comment intros.forks-internal}
${nested-comment
COMMENTS.intros.forks-internal}
${stack.repo-items forks-internal}''
)
++ ''
Expand Down
4 changes: 4 additions & 0 deletions text-templates/internal/comments.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ dep-counts = ./comments/dep-counts.dhall
, intros = ./comments/intros.dhall
, pkg-counts = ./comments/pkg-counts.dhall
}
56 changes: 56 additions & 0 deletions text-templates/internal/comments/pkg-counts.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
let TYPES = ../../../types.dhall

let L = https://prelude.dhall-lang.org/List/package.dhall

let N = https://prelude.dhall-lang.org/Natural/package.dhall

in \(verbosity : TYPES.Verbosity) ->
\(pkg-set : TYPES.PkgSet) ->
\(format-comments : List Text -> Text) ->
let pkgs =
merge
{ AllPkgs = \(pkgs : List Text) -> pkgs
, PkgUpgrade = \(pkgs : TYPES.PkgTodoList) -> pkgs.done
}
pkg-set

in merge
{ Quiet = ""
, Info =
let comments =
merge
{ AllPkgs =
\(pkgs : List Text) ->
let count-pkgs = L.length Text pkgs

in if N.isZero count-pkgs
then [ "We have no packages" ]
else let package-or-packages =
if N.equal 1 count-pkgs
then "package"
else "packages"

in [ "We have ${N.show
count-pkgs} ${package-or-packages}."
]
, PkgUpgrade =
\(pkgs : TYPES.PkgTodoList) ->
let count-done = L.length Text pkgs.done

let count-todo = L.length Text pkgs.todo

let package-or-packages =
if N.equal 1 count-done
then "package"
else "packages"

in [ "We have upgraded ${N.show
count-done} ${package-or-packages} and have ${N.show
count-todo} yet to do."
]
}
pkg-set

in format-comments comments
}
verbosity

0 comments on commit 60545b1

Please sign in to comment.