From 58488c6fec32f203dffb1d52f1499fe46cf40046 Mon Sep 17 00:00:00 2001 From: Hugo Pacheco Date: Wed, 12 Sep 2018 16:31:00 +0100 Subject: [PATCH 1/7] updated for ghc 8.4.2 --- Data/Graph/Analysis/Reporting/Pandoc.hs | 56 +++++++++++++++++-------- Graphalyze.cabal | 11 +++-- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/Data/Graph/Analysis/Reporting/Pandoc.hs b/Data/Graph/Analysis/Reporting/Pandoc.hs index bc32485..207773f 100644 --- a/Data/Graph/Analysis/Reporting/Pandoc.hs +++ b/Data/Graph/Analysis/Reporting/Pandoc.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + {- | Module : Data.Graph.Analysis.Reporting.Pandoc Description : Graphalyze Types and Classes @@ -39,6 +41,8 @@ import Data.List (intersperse) import Data.Maybe (fromJust, isNothing) import System.Directory (removeDirectoryRecursive) import System.FilePath ((<.>), ()) +import Data.Text (Text(..)) +import qualified Data.Text as T -- ----------------------------------------------------------------------------- @@ -46,8 +50,14 @@ import System.FilePath ((<.>), ()) The actual exported writers. -} +#if MIN_VERSION_pandoc (2,0,0) +writeHtmlStringGeneric = writeHtml5String +#else +writeHtmlStringGeneric = writeHtmlString +#endif + pandocHtml :: PandocDocument -pandocHtml = pd { writer = writeHtmlString +pandocHtml = pd { writer = writeHtmlStringGeneric , extension = "html" , templateName = "html" , extGraphProps = Just VProps { grSize = DefaultSize @@ -84,7 +94,11 @@ pandocMarkdown = pd { writer = writeMarkdown -- | Definition of a Pandoc Document. Size measurements are in inches, -- and a 6:4 ratio is used for width:length. data PandocDocument = PD { -- | The Pandoc document style +#if MIN_VERSION_pandoc (2,0,0) + writer :: WriterOptions -> Pandoc -> PandocPure Text +#else writer :: WriterOptions -> Pandoc -> String +#endif -- | The file extension used , extension :: FilePath -- | Which template to get. @@ -144,23 +158,29 @@ defaultProcess = PP { secLevel = 1 -- | Create the document. createPandoc :: PandocDocument -> Document -> IO (Maybe FilePath) -createPandoc p d = do created <- tryCreateDirectory dir - -- If the first one fails, so will this one. - _ <- tryCreateDirectory $ dir gdir - if not created - then failDoc - else do d' <- addLegend dir gdir (graphProps p) d - elems <- multiElems pp $ content d' - case elems of - Just es -> do let es' = htmlAuthDt : es - pnd = Pandoc meta es' - doc = convert pnd - wr <- tryWrite doc - case wr of - (Right _) -> success - (Left _) -> failDoc - Nothing -> failDoc - where +createPandoc p d = do + created <- tryCreateDirectory dir + -- If the first one fails, so will this one. + _ <- tryCreateDirectory $ dir gdir + if not created + then failDoc + else do + d' <- addLegend dir gdir (graphProps p) d + elems <- multiElems pp $ content d' + case elems of + Just es -> do + let es' = htmlAuthDt : es + pnd = Pandoc meta es' +#if MIN_VERSION_pandoc (2,0,0) + let doc = runPure $ convert pnd +#else + doc <- tryWrite $ convert pnd +#endif + case doc of + (Right _) -> success + (Left _) -> failDoc + Nothing -> failDoc + where dir = rootDirectory d gdir = graphDirectory d auth = author d diff --git a/Graphalyze.cabal b/Graphalyze.cabal index fe16cc8..5dd799d 100644 --- a/Graphalyze.cabal +++ b/Graphalyze.cabal @@ -1,5 +1,5 @@ Name: Graphalyze -Version: 0.15.0.0 +Version: 0.15.0.1 Synopsis: Graph-Theoretic Analysis library. Description: A library to use graph theory to analyse the relationships inherent in discrete data. @@ -13,8 +13,7 @@ Extra-Source-Files: TODO Cabal-Version: >= 1.6 Build-Type: Simple -Tested-With: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, - GHC == 7.10.2, GHC == 7.11.* +Tested-With: GHC == 8.4.2 Source-Repository head Type: git @@ -35,9 +34,9 @@ Library { process, random, bktrees >= 0.2 && <0.4, - fgl == 5.5.*, - graphviz >= 2999.15 && < 2999.20, - pandoc == 1.19.*, + fgl == 5.6.*, + graphviz >= 2999.20 && < 2999.21, + pandoc >= 2.0 && < 2.3, text if flag(old-locale) { From 8806877d5a498a937277bac1035cb270b8edd15d Mon Sep 17 00:00:00 2001 From: Hugo Pacheco Date: Fri, 4 Jan 2019 23:49:52 +0000 Subject: [PATCH 2/7] 8.6 --- Graphalyze.cabal | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Graphalyze.cabal b/Graphalyze.cabal index 5dd799d..9616416 100644 --- a/Graphalyze.cabal +++ b/Graphalyze.cabal @@ -33,10 +33,10 @@ Library { filepath, process, random, - bktrees >= 0.2 && <0.4, - fgl == 5.6.*, - graphviz >= 2999.20 && < 2999.21, - pandoc >= 2.0 && < 2.3, + bktrees >= 0.2, + fgl >= 5.6, + graphviz >= 2999.20 , + pandoc >= 2.0 , text if flag(old-locale) { From cd46235bc58820ed62bc8ee5a18f164569cafc7f Mon Sep 17 00:00:00 2001 From: Ignat Insarov Date: Sun, 29 May 2022 13:19:31 +0300 Subject: [PATCH 3/7] Prettify the Cabal manifest. --- Graphalyze.cabal | 124 +++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 64 deletions(-) diff --git a/Graphalyze.cabal b/Graphalyze.cabal index 9616416..55c112a 100644 --- a/Graphalyze.cabal +++ b/Graphalyze.cabal @@ -1,64 +1,60 @@ -Name: Graphalyze -Version: 0.15.0.1 -Synopsis: Graph-Theoretic Analysis library. -Description: A library to use graph theory to analyse the relationships - inherent in discrete data. -Category: Graphs, Algorithms -License: OtherLicense -License-File: LICENSE -Copyright: (c) Ivan Lazar Miljenovic -Author: Ivan Lazar Miljenovic -Maintainer: Ivan.Miljenovic@gmail.com -Extra-Source-Files: TODO -Cabal-Version: >= 1.6 -Build-Type: Simple - -Tested-With: GHC == 8.4.2 - -Source-Repository head - Type: git - Location: https://github.com/ivan-m/Graphalyze.git - -Flag old-locale { - Description: Use old-locale and time < 1.5 - Manual: False - Default: False -} - -Library { - Build-Depends: base == 4.*, - array, - containers, - directory, - filepath, - process, - random, - bktrees >= 0.2, - fgl >= 5.6, - graphviz >= 2999.20 , - pandoc >= 2.0 , - text - - if flag(old-locale) { - Build-Depends: time < 1.5, - old-locale - } else { - Build-Depends: time >= 1.5 && < 1.9 - } - - Exposed-Modules: Data.Graph.Analysis - Data.Graph.Analysis.Types - Data.Graph.Analysis.Utils - Data.Graph.Analysis.Visualisation - Data.Graph.Analysis.Algorithms - Data.Graph.Analysis.Algorithms.Common - Data.Graph.Analysis.Algorithms.Directed - Data.Graph.Analysis.Algorithms.Clustering - Data.Graph.Analysis.Reporting - Data.Graph.Analysis.Reporting.Pandoc - - Other-Modules: Data.Graph.Analysis.Internal, - Paths_Graphalyze - - Ghc-Options: -Wall -} +cabal-version: 2.2 +name: Graphalyze +version: 0.15.0.1 +author: Ivan Lazar Miljenovic +maintainer: Ivan.Miljenovic@gmail.com +synopsis: Graph-Theoretic Analysis library. +description: + A library to use graph theory to analyse the relationships + inherent in discrete data. +category: Graphs, Algorithms +license-file: LICENSE +tested-with: GHC == 8.4.2 +extra-source-files: TODO +build-type: Simple +copyright: (c) Ivan Lazar Miljenovic + +library + exposed-modules: + Data.Graph.Analysis + Data.Graph.Analysis.Algorithms + Data.Graph.Analysis.Algorithms.Clustering + Data.Graph.Analysis.Algorithms.Common + Data.Graph.Analysis.Algorithms.Directed + Data.Graph.Analysis.Reporting + Data.Graph.Analysis.Reporting.Pandoc + Data.Graph.Analysis.Types + Data.Graph.Analysis.Utils + Data.Graph.Analysis.Visualisation + build-depends: + , array + , base == 4.* + , bktrees >= 0.2 + , containers + , directory + , fgl >= 5.6 + , filepath + , graphviz >= 2999.20 + , pandoc >= 2.0 + , process + , random + , text + ghc-options: -Wall + other-modules: + Data.Graph.Analysis.Internal, + Paths_Graphalyze + + if flag ( old-locale ) + build-depends: old-locale, time < 1.5 + + else + build-depends: time >= 1.5 && < 1.9 + +source-repository head + type: git + location: https://github.com/ivan-m/Graphalyze.git + +flag old-locale + description: Use old-locale and time < 1.5 + manual: False + default: False From cd5797ba8651e03070b162939e4f1da97ee1edba Mon Sep 17 00:00:00 2001 From: Ignat Insarov Date: Sun, 29 May 2022 13:20:16 +0300 Subject: [PATCH 4/7] Remove any bounds on `time`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With these bounds Cabal cannot get me a build plan, and I am not going to put thought into it at this time. We can put some bounds on `time` later. --- Graphalyze.cabal | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Graphalyze.cabal b/Graphalyze.cabal index 55c112a..309581b 100644 --- a/Graphalyze.cabal +++ b/Graphalyze.cabal @@ -39,22 +39,12 @@ library , process , random , text + , time ghc-options: -Wall other-modules: Data.Graph.Analysis.Internal, Paths_Graphalyze - if flag ( old-locale ) - build-depends: old-locale, time < 1.5 - - else - build-depends: time >= 1.5 && < 1.9 - source-repository head type: git location: https://github.com/ivan-m/Graphalyze.git - -flag old-locale - description: Use old-locale and time < 1.5 - manual: False - default: False From 60c4260bac022897fed3b92060afdb14333ae89e Mon Sep 17 00:00:00 2001 From: Ignat Insarov Date: Sun, 29 May 2022 13:25:26 +0300 Subject: [PATCH 5/7] Make it build with the current `pandoc`. It seems `pandoc` has switched from `String` to `Text`, so we also switch from `String` to `Text`! --- Data/Graph/Analysis/Reporting/Pandoc.hs | 27 +++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Data/Graph/Analysis/Reporting/Pandoc.hs b/Data/Graph/Analysis/Reporting/Pandoc.hs index 207773f..d6f563e 100644 --- a/Data/Graph/Analysis/Reporting/Pandoc.hs +++ b/Data/Graph/Analysis/Reporting/Pandoc.hs @@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} {- | Module : Data.Graph.Analysis.Reporting.Pandoc @@ -41,8 +42,8 @@ import Data.List (intersperse) import Data.Maybe (fromJust, isNothing) import System.Directory (removeDirectoryRecursive) import System.FilePath ((<.>), ()) -import Data.Text (Text(..)) -import qualified Data.Text as T +import Data.Text (Text) +import qualified Data.Text as Text -- ----------------------------------------------------------------------------- @@ -97,12 +98,12 @@ data PandocDocument = PD { -- | The Pandoc document style #if MIN_VERSION_pandoc (2,0,0) writer :: WriterOptions -> Pandoc -> PandocPure Text #else - writer :: WriterOptions -> Pandoc -> String + writer :: WriterOptions -> Pandoc -> Text #endif -- | The file extension used , extension :: FilePath -- | Which template to get. - , templateName :: String + , templateName :: Text -- | Size of graphs to be produced. , graphProps :: VisProperties -- | Optional size of external linked graphs. @@ -183,8 +184,8 @@ createPandoc p d = do where dir = rootDirectory d gdir = graphDirectory d - auth = author d - dt = date d + auth = (Text.pack . author) d + dt = (Text.pack . date) d meta = makeMeta (title d) auth dt -- Html output doesn't show date and auth anywhere by default. htmlAuthDt = htmlInfo auth dt @@ -209,25 +210,25 @@ createPandoc p d = do -} -- | The meta information -makeMeta :: DocInline -> String -> String -> Meta +makeMeta :: DocInline -> Text -> Text -> Meta makeMeta tle a t = P.makeMeta (inlines tle) [[Str a]] [Str t] -- | Html output doesn't show the author and date; use this to print it. -htmlInfo :: String -> String -> Block +htmlInfo :: Text -> Text -> Block htmlInfo auth dt = RawBlock (Format "html") html where heading = "

Document Information

" - html = unlines [heading, htmlize auth, htmlize dt] - htmlize str = "

" ++ str ++ "

" + html = Text.unlines [heading, htmlize auth, htmlize dt] + htmlize str = "

" <> str <> "

" -- | Link conversion loc2target :: Location -> Target -loc2target (Web url) = (url,"") -loc2target (File file) = (file,"") +loc2target (Web url) = (Text.pack url,"") +loc2target (File file) = (Text.pack file,"") -- | Conversion of simple inline elements. inlines :: DocInline -> [Inline] -inlines (Text str) = [Str str] +inlines (Text str) = [Str (Text.pack str)] inlines BlankSpace = [Space] inlines (Grouping grp) = concat . intersperse [Space] $ map inlines grp inlines (Bold inl) = [Strong (inlines inl)] From 05ec2eb2db7a11d04f026eb29f8d13c30a889a29 Mon Sep 17 00:00:00 2001 From: Ignat Insarov Date: Sun, 29 May 2022 13:27:35 +0300 Subject: [PATCH 6/7] Major version bump, to be safe. --- Graphalyze.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Graphalyze.cabal b/Graphalyze.cabal index 309581b..218af8c 100644 --- a/Graphalyze.cabal +++ b/Graphalyze.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: Graphalyze -version: 0.15.0.1 +version: 0.16.0.0 author: Ivan Lazar Miljenovic maintainer: Ivan.Miljenovic@gmail.com synopsis: Graph-Theoretic Analysis library. From ba15ee96c45f3d5797817b4f6df1e9a4b87a39bb Mon Sep 17 00:00:00 2001 From: Ignat Insarov Date: Sun, 29 May 2022 14:46:40 +0300 Subject: [PATCH 7/7] Exile CPP and actually write the report. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a fault in a code path protected by a CPP pragma conditional on the version of `pandoc` that caused the report to not be written at all. I am fixing this error and removing all CPP along the way. --- Data/Graph/Analysis/Reporting/Pandoc.hs | 33 +++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/Data/Graph/Analysis/Reporting/Pandoc.hs b/Data/Graph/Analysis/Reporting/Pandoc.hs index d6f563e..b76bb31 100644 --- a/Data/Graph/Analysis/Reporting/Pandoc.hs +++ b/Data/Graph/Analysis/Reporting/Pandoc.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {- | @@ -44,6 +43,7 @@ import System.Directory (removeDirectoryRecursive) import System.FilePath ((<.>), ()) import Data.Text (Text) import qualified Data.Text as Text +import qualified Data.Text.IO as Text -- ----------------------------------------------------------------------------- @@ -51,14 +51,8 @@ import qualified Data.Text as Text The actual exported writers. -} -#if MIN_VERSION_pandoc (2,0,0) -writeHtmlStringGeneric = writeHtml5String -#else -writeHtmlStringGeneric = writeHtmlString -#endif - pandocHtml :: PandocDocument -pandocHtml = pd { writer = writeHtmlStringGeneric +pandocHtml = pd { writer = writeHtml5String , extension = "html" , templateName = "html" , extGraphProps = Just VProps { grSize = DefaultSize @@ -95,11 +89,7 @@ pandocMarkdown = pd { writer = writeMarkdown -- | Definition of a Pandoc Document. Size measurements are in inches, -- and a 6:4 ratio is used for width:length. data PandocDocument = PD { -- | The Pandoc document style -#if MIN_VERSION_pandoc (2,0,0) writer :: WriterOptions -> Pandoc -> PandocPure Text -#else - writer :: WriterOptions -> Pandoc -> Text -#endif -- | The file extension used , extension :: FilePath -- | Which template to get. @@ -172,14 +162,13 @@ createPandoc p d = do Just es -> do let es' = htmlAuthDt : es pnd = Pandoc meta es' -#if MIN_VERSION_pandoc (2,0,0) - let doc = runPure $ convert pnd -#else - doc <- tryWrite $ convert pnd -#endif - case doc of - (Right _) -> success - (Left _) -> failDoc + case runPure $ convert pnd of + Left _ -> failDoc + Right text -> do + doc <- tryWrite text + case doc of + (Right _) -> success + (Left _) -> failDoc Nothing -> failDoc where dir = rootDirectory d @@ -198,8 +187,8 @@ createPandoc p d = do } convert = writer p writerOptions file = dir fileFront d <.> extension p - tryWrite :: String -> IO (Either SomeException ()) - tryWrite = try . writeFile file + tryWrite :: Text -> IO (Either SomeException ()) + tryWrite = try . Text.writeFile file success = return (Just file) failDoc = removeDirectoryRecursive dir >> return Nothing