From a60f652242debe4d7940ac9ec2096f275a5458e3 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sat, 9 Nov 2024 22:44:46 +0100 Subject: [PATCH] Move SiteGenerator into executable only and rename library to Byg.* --- byg/{src => app}/Main.hs | 9 +++--- byg/{src => app}/SiteGenerator.hs | 6 ++-- byg/byg.cabal | 38 +++++++++++++----------- byg/default.nix | 2 +- byg/src/{ => Byg}/DependencyGenerator.hs | 8 ++--- byg/src/{ => Byg}/DependencyRunner.hs | 27 ++++++++--------- byg/src/Byg/Functions.hs | 17 +++++++++++ byg/src/{ => Byg}/Functions/Atom.hs | 6 ++-- byg/src/{ => Byg}/Functions/Date.hs | 6 ++-- byg/src/{ => Byg}/Functions/Image.hs | 8 ++--- byg/src/{ => Byg}/Functions/Pandoc.hs | 6 ++-- byg/src/{ => Byg}/Functions/Paths.hs | 8 ++--- byg/src/{ => Byg}/Functions/Template.hs | 6 ++-- byg/src/{ => Byg}/Functions/Text.hs | 8 ++--- byg/src/Byg/Types.hs | 13 ++++++++ byg/src/{ => Byg}/Types/Date.hs | 2 +- byg/src/{ => Byg}/Types/Dependency.hs | 6 ++-- byg/src/{ => Byg}/Types/Functions.hs | 5 ++-- byg/src/{ => Byg}/Types/Token.hs | 2 +- byg/src/{ => Byg}/Types/Value.hs | 2 +- byg/src/Functions.hs | 17 ----------- byg/src/Types.hs | 13 -------- 22 files changed, 109 insertions(+), 106 deletions(-) rename byg/{src => app}/Main.hs (76%) rename byg/{src => app}/SiteGenerator.hs (97%) rename byg/src/{ => Byg}/DependencyGenerator.hs (97%) rename byg/src/{ => Byg}/DependencyRunner.hs (95%) create mode 100644 byg/src/Byg/Functions.hs rename byg/src/{ => Byg}/Functions/Atom.hs (94%) rename byg/src/{ => Byg}/Functions/Date.hs (80%) rename byg/src/{ => Byg}/Functions/Image.hs (90%) rename byg/src/{ => Byg}/Functions/Pandoc.hs (91%) rename byg/src/{ => Byg}/Functions/Paths.hs (93%) rename byg/src/{ => Byg}/Functions/Template.hs (84%) rename byg/src/{ => Byg}/Functions/Text.hs (84%) create mode 100644 byg/src/Byg/Types.hs rename byg/src/{ => Byg}/Types/Date.hs (97%) rename byg/src/{ => Byg}/Types/Dependency.hs (97%) rename byg/src/{ => Byg}/Types/Functions.hs (86%) rename byg/src/{ => Byg}/Types/Token.hs (95%) rename byg/src/{ => Byg}/Types/Value.hs (97%) delete mode 100644 byg/src/Functions.hs delete mode 100644 byg/src/Types.hs diff --git a/byg/src/Main.hs b/byg/app/Main.hs similarity index 76% rename from byg/src/Main.hs rename to byg/app/Main.hs index 5d3ba15..34cc764 100644 --- a/byg/src/Main.hs +++ b/byg/app/Main.hs @@ -1,10 +1,11 @@ module Main where -import Types (Dependency) -import qualified DependencyRunner as DR -import qualified Types.Dependency as D +import Byg.Types (Dependency) +import qualified Byg.DependencyRunner as DR +import qualified Byg.Types.Dependency as D +import Byg.DependencyGenerator (evalDepGenM) + import SiteGenerator (generateSite) -import DependencyGenerator (evalDepGenM) import System.Environment (getArgs) import qualified Data.Text.IO as T diff --git a/byg/src/SiteGenerator.hs b/byg/app/SiteGenerator.hs similarity index 97% rename from byg/src/SiteGenerator.hs rename to byg/app/SiteGenerator.hs index 1ad616b..05983b7 100644 --- a/byg/src/SiteGenerator.hs +++ b/byg/app/SiteGenerator.hs @@ -1,8 +1,8 @@ module SiteGenerator (generateSite) where -import Types (Token(..), Date(..), formatDate, formatDateShort) -import DependencyGenerator -import Functions +import Byg.Types (Token(..), Date(..), formatDate, formatDateShort) +import Byg.DependencyGenerator +import Byg.Functions import Data.List (sort, elemIndex) import Data.Function ((&)) diff --git a/byg/byg.cabal b/byg/byg.cabal index 4975890..781d06d 100644 --- a/byg/byg.cabal +++ b/byg/byg.cabal @@ -20,23 +20,22 @@ library import: common hs-source-dirs: src exposed-modules: - Types.Token - Types.Value - Types.Functions - Types.Dependency - Types.Date - Types - DependencyGenerator - Functions.Image - Functions.Pandoc - Functions.Paths - Functions.Template - Functions.Text - Functions.Date - Functions.Atom - Functions - DependencyRunner - SiteGenerator + Byg.Types.Token + Byg.Types.Value + Byg.Types.Functions + Byg.Types.Dependency + Byg.Types.Date + Byg.Types + Byg.DependencyGenerator + Byg.Functions.Image + Byg.Functions.Pandoc + Byg.Functions.Paths + Byg.Functions.Template + Byg.Functions.Text + Byg.Functions.Date + Byg.Functions.Atom + Byg.Functions + Byg.DependencyRunner build-depends: base >=4.14 && <4.20 , mtl @@ -52,7 +51,10 @@ library executable byg import: common - main-is: src/Main.hs + hs-source-dirs: app + main-is: Main.hs + other-modules: + SiteGenerator build-depends: base >=4.14 && <4.20 , byg diff --git a/byg/default.nix b/byg/default.nix index 4917cbe..9f5650a 100644 --- a/byg/default.nix +++ b/byg/default.nix @@ -3,7 +3,7 @@ pkgs.haskell.lib.overrideCabal (haskell.callCabal2nix "byg" ./. { }) (_: { configureFlags = [ - # "--ghc-option=-Werror" + "--ghc-option=-Werror" "--ghc-option=-O2" ]; doHaddock = false; diff --git a/byg/src/DependencyGenerator.hs b/byg/src/Byg/DependencyGenerator.hs similarity index 97% rename from byg/src/DependencyGenerator.hs rename to byg/src/Byg/DependencyGenerator.hs index f2d45e1..2fd7fe6 100644 --- a/byg/src/DependencyGenerator.hs +++ b/byg/src/Byg/DependencyGenerator.hs @@ -1,6 +1,6 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE FunctionalDependencies #-} -module DependencyGenerator +module Byg.DependencyGenerator ( DepGenM , DepGenM' , TokenableTo(..) @@ -26,9 +26,9 @@ module DependencyGenerator , unzipDepGenM ) where -import Types.Token (Token(..)) -import Types.Functions (IsFunctionIO(..)) -import Types.Dependency (Action(..), F(..), Dependency, makeDependency) +import Byg.Types.Token (Token(..)) +import Byg.Types.Functions (IsFunctionIO(..)) +import Byg.Types.Dependency (Action(..), F(..), Dependency, makeDependency) import Type.Reflection (Typeable, TypeRep, typeRep) import Control.Monad.State (MonadState, State, runState, put, get) diff --git a/byg/src/DependencyRunner.hs b/byg/src/Byg/DependencyRunner.hs similarity index 95% rename from byg/src/DependencyRunner.hs rename to byg/src/Byg/DependencyRunner.hs index f783eaa..b74ecdf 100644 --- a/byg/src/DependencyRunner.hs +++ b/byg/src/Byg/DependencyRunner.hs @@ -1,5 +1,5 @@ {-# LANGUAGE MonoLocalBinds #-} -module DependencyRunner +module Byg.DependencyRunner ( DepRunM , runDeps , runDepRunMIO @@ -7,15 +7,14 @@ module DependencyRunner , extractSndTokenAsList ) where -import Types (evalFunctionIO, functionIOReads, functionIOWrites) -import Types.Value -import Types.Token -import Types.Dependency +import Byg.Types (evalFunctionIO, functionIOReads, functionIOWrites) +import Byg.Types.Value +import Byg.Types.Token +import Byg.Types.Dependency import Type.Reflection (Typeable) import Data.Map (Map) import qualified Data.Map as M -import Data.Maybe (catMaybes) import Control.Monad (void, forM, filterM) import Control.Monad.State (MonadState, MonadIO, StateT, evalStateT, get, modify, liftIO) import Control.Monad.Writer (MonadWriter, WriterT, runWriterT, tell) @@ -55,8 +54,8 @@ runDep (Dependency _ a action _ b) = else putTokenValue b $ NotEvaluated m where m :: LastUpdated -> DepRunM (Maybe (Value, LastUpdated)) m luFuture = do - m <- runAction action a luFuture - case m of + mr <- runAction action a luFuture + case mr of Just (result, luResult) -> do putTokenValue b $ Evaluated result luResult pure $ Just (result, luResult) @@ -80,10 +79,10 @@ getTokenValueByIndex luFuture i = do Nothing -> pure Nothing Just x -> evaluate luFuture x -minimumOrNever :: [LastUpdated] -> LastUpdated -minimumOrNever = \case - [] -> Never - times -> minimum times +-- minimumOrNever :: [LastUpdated] -> LastUpdated +-- minimumOrNever = \case +-- [] -> Never +-- times -> minimum times maximumOrNever :: [LastUpdated] -> LastUpdated maximumOrNever = \case @@ -250,8 +249,8 @@ runAction action tokenInput luFuture = case action of result <- forM input $ \x -> do putTokenValue innerInput $ Evaluated (toValue x) (max luInput lastUpdated) runDeps subDeps - m <- getTokenValue innerOutput luFuture - pure $ do (vOut, luOut) <- m + mr <- getTokenValue innerOutput luFuture + pure $ do (vOut, luOut) <- mr pure (fromValue vOut, luOut) pure $ do result' <- sequence result let (values, lus) = unzip result' diff --git a/byg/src/Byg/Functions.hs b/byg/src/Byg/Functions.hs new file mode 100644 index 0000000..6d499e5 --- /dev/null +++ b/byg/src/Byg/Functions.hs @@ -0,0 +1,17 @@ +module Byg.Functions + ( module Byg.Functions.Image + , module Byg.Functions.Pandoc + , module Byg.Functions.Paths + , module Byg.Functions.Template + , module Byg.Functions.Text + , module Byg.Functions.Date + , module Byg.Functions.Atom + ) where + +import Byg.Functions.Image +import Byg.Functions.Pandoc +import Byg.Functions.Paths +import Byg.Functions.Template +import Byg.Functions.Text +import Byg.Functions.Date +import Byg.Functions.Atom diff --git a/byg/src/Functions/Atom.hs b/byg/src/Byg/Functions/Atom.hs similarity index 94% rename from byg/src/Functions/Atom.hs rename to byg/src/Byg/Functions/Atom.hs index 04ae1bc..93662ab 100644 --- a/byg/src/Functions/Atom.hs +++ b/byg/src/Byg/Functions/Atom.hs @@ -1,12 +1,12 @@ {-# LANGUAGE RebindableSyntax #-} -module Functions.Atom +module Byg.Functions.Atom ( generateAtom ) where import Prelude -import Types (Token, Date(..), formatDateShort) -import DependencyGenerator (DepGenM, TokenableTo(..), onTupleToken) +import Byg.Types (Token, Date(..), formatDateShort) +import Byg.DependencyGenerator (DepGenM, TokenableTo(..), onTupleToken) import Data.Text (Text) import qualified Data.Text as T diff --git a/byg/src/Functions/Date.hs b/byg/src/Byg/Functions/Date.hs similarity index 80% rename from byg/src/Functions/Date.hs rename to byg/src/Byg/Functions/Date.hs index 9b71da5..09ebc2e 100644 --- a/byg/src/Functions/Date.hs +++ b/byg/src/Byg/Functions/Date.hs @@ -1,9 +1,9 @@ -module Functions.Date +module Byg.Functions.Date ( extractDate ) where -import Types (Token, Date(..)) -import DependencyGenerator (DepGenM, TokenableTo(..), onToken) +import Byg.Types (Token, Date(..)) +import Byg.DependencyGenerator (DepGenM, TokenableTo(..), onToken) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NE diff --git a/byg/src/Functions/Image.hs b/byg/src/Byg/Functions/Image.hs similarity index 90% rename from byg/src/Functions/Image.hs rename to byg/src/Byg/Functions/Image.hs index 6f6a017..f63b483 100644 --- a/byg/src/Functions/Image.hs +++ b/byg/src/Byg/Functions/Image.hs @@ -1,4 +1,4 @@ -module Functions.Image +module Byg.Functions.Image ( Image(..) , ImageConversionSettings(..) , openImage @@ -6,10 +6,10 @@ module Functions.Image , convertImage ) where -import Types (IsFunctionIO(..), Token(..)) -import DependencyGenerator (DepGenM, TokenableTo(..), onTupleToken, toTupleToken, +import Byg.Types (IsFunctionIO(..), Token(..)) +import Byg.DependencyGenerator (DepGenM, TokenableTo(..), onTupleToken, toTupleToken, runFunctionIO, runFunctionIO_) -import DependencyRunner (extractSndTokenAsList) +import Byg.DependencyRunner (extractSndTokenAsList) import qualified Codec.Picture as CP import qualified Codec.Picture.STBIR as CPS diff --git a/byg/src/Functions/Pandoc.hs b/byg/src/Byg/Functions/Pandoc.hs similarity index 91% rename from byg/src/Functions/Pandoc.hs rename to byg/src/Byg/Functions/Pandoc.hs index 928ec84..1dd6297 100644 --- a/byg/src/Functions/Pandoc.hs +++ b/byg/src/Byg/Functions/Pandoc.hs @@ -1,4 +1,4 @@ -module Functions.Pandoc +module Byg.Functions.Pandoc ( readMarkdown , writeHtml , markdownToHtml @@ -6,8 +6,8 @@ module Functions.Pandoc , injectAfterTitle ) where -import Types (Token) -import DependencyGenerator (DepGenM, TokenableTo(..), onToken, onTupleToken) +import Byg.Types (Token) +import Byg.DependencyGenerator (DepGenM, TokenableTo(..), onToken, onTupleToken) import Data.Text (Text) import Control.Monad ((>=>)) diff --git a/byg/src/Functions/Paths.hs b/byg/src/Byg/Functions/Paths.hs similarity index 93% rename from byg/src/Functions/Paths.hs rename to byg/src/Byg/Functions/Paths.hs index d679b9b..cc1c48c 100644 --- a/byg/src/Functions/Paths.hs +++ b/byg/src/Byg/Functions/Paths.hs @@ -1,4 +1,4 @@ -module Functions.Paths +module Byg.Functions.Paths ( joinPaths , fileComponents , hasExtension @@ -9,10 +9,10 @@ module Functions.Paths , copyTo ) where -import Types (IsFunctionIO(..), Token(..)) -import DependencyGenerator (DepGenM, TokenableTo(..), onToken, onTupleToken, toTupleToken, +import Byg.Types (IsFunctionIO(..), Token(..)) +import Byg.DependencyGenerator (DepGenM, TokenableTo(..), onToken, onTupleToken, toTupleToken, runFunctionIO, runFunctionIO_, untupleSndDepGenM) -import DependencyRunner (extractSndTokenAsList) +import Byg.DependencyRunner (extractSndTokenAsList) import Data.Char (toLower) import Control.Monad (when) diff --git a/byg/src/Functions/Template.hs b/byg/src/Byg/Functions/Template.hs similarity index 84% rename from byg/src/Functions/Template.hs rename to byg/src/Byg/Functions/Template.hs index 322c5a7..810081d 100644 --- a/byg/src/Functions/Template.hs +++ b/byg/src/Byg/Functions/Template.hs @@ -1,11 +1,11 @@ -module Functions.Template +module Byg.Functions.Template ( Template(..) , makeTemplate , applyTemplate ) where -import Types (Token) -import DependencyGenerator (DepGenM, TokenableTo(..), onTupleToken) +import Byg.Types (Token) +import Byg.DependencyGenerator (DepGenM, TokenableTo(..), onTupleToken) import Data.Text (Text) import qualified Data.Text as T diff --git a/byg/src/Functions/Text.hs b/byg/src/Byg/Functions/Text.hs similarity index 84% rename from byg/src/Functions/Text.hs rename to byg/src/Byg/Functions/Text.hs index 7e37d11..321c1e7 100644 --- a/byg/src/Functions/Text.hs +++ b/byg/src/Byg/Functions/Text.hs @@ -1,12 +1,12 @@ -module Functions.Text +module Byg.Functions.Text ( readTextFile , saveTextFile ) where -import Types (IsFunctionIO(..), Token(..)) -import DependencyGenerator (DepGenM, TokenableTo(..), toTupleToken, +import Byg.Types (IsFunctionIO(..), Token(..)) +import Byg.DependencyGenerator (DepGenM, TokenableTo(..), toTupleToken, runFunctionIO, runFunctionIO_) -import DependencyRunner (extractSndTokenAsList) +import Byg.DependencyRunner (extractSndTokenAsList) import Data.Text (Text) import qualified Data.Text.IO as T diff --git a/byg/src/Byg/Types.hs b/byg/src/Byg/Types.hs new file mode 100644 index 0000000..dff6ae5 --- /dev/null +++ b/byg/src/Byg/Types.hs @@ -0,0 +1,13 @@ +module Byg.Types + ( module Byg.Types.Token + , module Byg.Types.Value + , module Byg.Types.Functions + , module Byg.Types.Date + , Dependency + ) where + +import Byg.Types.Token +import Byg.Types.Value +import Byg.Types.Functions +import Byg.Types.Date +import Byg.Types.Dependency (Dependency) diff --git a/byg/src/Types/Date.hs b/byg/src/Byg/Types/Date.hs similarity index 97% rename from byg/src/Types/Date.hs rename to byg/src/Byg/Types/Date.hs index d0f939c..8a06911 100644 --- a/byg/src/Types/Date.hs +++ b/byg/src/Byg/Types/Date.hs @@ -1,4 +1,4 @@ -module Types.Date +module Byg.Types.Date ( Date(..) , formatDate , formatDateShort diff --git a/byg/src/Types/Dependency.hs b/byg/src/Byg/Types/Dependency.hs similarity index 97% rename from byg/src/Types/Dependency.hs rename to byg/src/Byg/Types/Dependency.hs index e2401ba..59f59d1 100644 --- a/byg/src/Types/Dependency.hs +++ b/byg/src/Byg/Types/Dependency.hs @@ -1,5 +1,5 @@ {-# LANGUAGE GADTs #-} -module Types.Dependency +module Byg.Types.Dependency ( Action(..) , F(..) , Dependency(..) @@ -12,8 +12,8 @@ module Types.Dependency , formatDependencyTrees ) where -import Types.Token (Token(..)) -import Types.Functions (IsFunctionIO(..)) +import Byg.Types.Token (Token(..)) +import Byg.Types.Functions (IsFunctionIO(..)) import Type.Reflection (Typeable, TypeRep, typeRep) import Text.Printf (printf) diff --git a/byg/src/Types/Functions.hs b/byg/src/Byg/Types/Functions.hs similarity index 86% rename from byg/src/Types/Functions.hs rename to byg/src/Byg/Types/Functions.hs index 6f3240c..bf2436d 100644 --- a/byg/src/Types/Functions.hs +++ b/byg/src/Byg/Types/Functions.hs @@ -1,9 +1,10 @@ {-# LANGUAGE FunctionalDependencies #-} -module Types.Functions +module Byg.Types.Functions ( IsFunctionIO(..) ) where -import Types.Token (Token) +import Byg.Types.Token (Token) + import Type.Reflection (Typeable) class (Show f, Show a, Typeable a, Show b, Typeable b) => IsFunctionIO f a b | f -> a b where diff --git a/byg/src/Types/Token.hs b/byg/src/Byg/Types/Token.hs similarity index 95% rename from byg/src/Types/Token.hs rename to byg/src/Byg/Types/Token.hs index 31d8481..9ed28a2 100644 --- a/byg/src/Types/Token.hs +++ b/byg/src/Byg/Types/Token.hs @@ -1,5 +1,5 @@ {-# LANGUAGE GADTs #-} -module Types.Token +module Byg.Types.Token ( Token(..) ) where diff --git a/byg/src/Types/Value.hs b/byg/src/Byg/Types/Value.hs similarity index 97% rename from byg/src/Types/Value.hs rename to byg/src/Byg/Types/Value.hs index 794158f..f0d2af0 100644 --- a/byg/src/Types/Value.hs +++ b/byg/src/Byg/Types/Value.hs @@ -1,5 +1,5 @@ {-# LANGUAGE MonoLocalBinds #-} -module Types.Value +module Byg.Types.Value ( Value(..) , toValue , toValueRep diff --git a/byg/src/Functions.hs b/byg/src/Functions.hs deleted file mode 100644 index dfbf6a2..0000000 --- a/byg/src/Functions.hs +++ /dev/null @@ -1,17 +0,0 @@ -module Functions - ( module Functions.Image - , module Functions.Pandoc - , module Functions.Paths - , module Functions.Template - , module Functions.Text - , module Functions.Date - , module Functions.Atom - ) where - -import Functions.Image -import Functions.Pandoc -import Functions.Paths -import Functions.Template -import Functions.Text -import Functions.Date -import Functions.Atom diff --git a/byg/src/Types.hs b/byg/src/Types.hs deleted file mode 100644 index 7c17601..0000000 --- a/byg/src/Types.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Types - ( module Types.Token - , module Types.Value - , module Types.Functions - , module Types.Date - , Dependency - ) where - -import Types.Token -import Types.Value -import Types.Functions -import Types.Date -import Types.Dependency (Dependency)