Commit dfd26c31 authored by Daniel Firth's avatar Daniel Firth
Browse files

Fix styling

parent ee68c10f
Pipeline #529 failed with stages
in 8 seconds
{- |
Module : Development.Shake.Plus.Extended
Copyright : Copyright (C) 2020 Daniel Firth
Maintainer : Daniel Firth <dan.firth@homotopic.tech>
License : MIT
Stability : experimental
Module exports for Development.Shake.Plus.Extended.
-}
module Development.Shake.Plus.Extended (
module Development.Shake.Plus.Extended.FileRules
, module Development.Shake.Plus.Extended.Loaders
, module Development.Shake.Plus.Extended.Simple
) where
-- |
-- Module : Development.Shake.Plus.Extended
-- Copyright : Copyright (C) 2020 Daniel Firth
-- Maintainer : Daniel Firth <dan.firth@homotopic.tech>
-- License : MIT
-- Stability : experimental
--
-- Module exports for Development.Shake.Plus.Extended.
module Development.Shake.Plus.Extended
( module Development.Shake.Plus.Extended.FileRules,
module Development.Shake.Plus.Extended.Loaders,
module Development.Shake.Plus.Extended.Simple,
)
where
import Data.IxSet.Typed.Binary ()
import Data.IxSet.Typed.Hashable ()
import Development.Shake.Plus.Extended.FileRules
import Development.Shake.Plus.Extended.Loaders
import Development.Shake.Plus.Extended.Simple
import Path.Binary()
import Data.IxSet.Typed.Binary()
import Data.IxSet.Typed.Hashable()
import Path.Binary ()
{- |
Module : Shakebook.Conduit
License : MIT
Stability : experimental
Utilities for using conduit to store remote caches.
-}
module Development.Shake.Plus.Extended.Conduit (
RemoteJSONLookup(..)
, addRemoteJSONOracleCache
) where
import Data.Aeson
import Data.Binary.Instances.Aeson ()
import Development.Shake.Plus
import Network.HTTP.Simple
import RIO
import qualified RIO.Text as T
-- |
-- Module : Shakebook.Conduit
-- License : MIT
-- Stability : experimental
--
-- Utilities for using conduit to store remote caches.
module Development.Shake.Plus.Extended.Conduit
( RemoteJSONLookup (..),
addRemoteJSONOracleCache,
)
where
import Data.Aeson
import Data.Binary.Instances.Aeson ()
import Development.Shake.Plus
import Network.HTTP.Simple
import RIO
import qualified RIO.Text as T
-- | Remote json lookup for an oracle, this should contain a URL as Text.
newtype RemoteJSONLookup = RemoteJSONLookup Text
......@@ -25,7 +24,9 @@ newtype RemoteJSONLookup = RemoteJSONLookup Text
type instance RuleResult RemoteJSONLookup = Value
deriving instance Hashable RemoteJSONLookup
deriving instance Binary RemoteJSONLookup
deriving instance NFData RemoteJSONLookup
-- | Adds an oracle cache for looking up json from a remote server.
......@@ -34,4 +35,3 @@ addRemoteJSONOracleCache = addOracleCache $ \(RemoteJSONLookup x) -> do
initReq <- parseRequest $ T.unpack x
(y :: Response Value) <- httpJSON initReq
return $ getResponseBody y
{- |
Module : Development.Shake.Plus.Extended.FileRules
Copyright : Copyright (C) 2020 Daniel Firth
Maintainer : Daniel Firth <dan.firth@homotopic.tech>
License : MIT
Stability : experimental
-- |
-- Module : Development.Shake.Plus.Extended.FileRules
-- Copyright : Copyright (C) 2020 Daniel Firth
-- Maintainer : Daniel Firth <dan.firth@homotopic.tech>
-- License : MIT
-- Stability : experimental
module Development.Shake.Plus.Extended.FileRules
( HasLocalOut (..),
(/%>),
(/|%>),
(%^>),
(|%^>),
)
where
-}
module Development.Shake.Plus.Extended.FileRules (
HasLocalOut(..)
, (/%>)
, (/|%>)
, (%^>)
, (|%^>)
) where
import Control.Comonad.Env as E
import Control.Exception.Extra
import Development.Shake.FilePath
import Development.Shake.Plus
import RIO as R
import Within
import Control.Comonad.Env as E
import Control.Exception.Extra
import Development.Shake.FilePath
import Development.Shake.Plus
import RIO as R
import Within
class HasLocalOut r where
localOutL :: Lens' r (Path Rel Dir)
-- | Variant of `(%>)` that passes the local directory from the environment into the callback.
(/%>) :: (MonadReader r m, HasLocalOut r, MonadRules m) => FilePattern -> ((Path Rel Dir, Path Rel File) -> RAction r ()) -> m ()
(/%>) xs ract = R.ask >>= \r -> do
let d = view localOutL r
(toFilePath d <> xs) %> (stripProperPrefix d >=> \x -> ract (d, x))
(/%>) xs ract =
R.ask >>= \r -> do
let d = view localOutL r
(toFilePath d <> xs) %> (stripProperPrefix d >=> \x -> ract (d, x))
-- | Variant of `(|%>)` that passes the local directory from the environment into the callback.
(/|%>) :: (MonadReader r m, HasLocalOut r, MonadRules m) => [FilePattern] -> ((Path Rel Dir, Path Rel File) -> RAction r ()) -> m ()
(/|%>) xs ract = R.ask >>= \r -> do
let d = view localOutL r
((toFilePath d <>) <$> xs) |%> (stripProperPrefix d >=> \x -> ract (d, x))
(/|%>) xs ract =
R.ask >>= \r -> do
let d = view localOutL r
((toFilePath d <>) <$> xs) |%> (stripProperPrefix d >=> \x -> ract (d, x))
-- | `Within` variant of `(%>)`, used to keep track of local directories.
(%^>) :: (Partial, MonadReader r m, MonadRules m) => Within Rel FilePattern -> (Within Rel (Path Rel File) -> RAction r ()) -> m ()
......
{- |
Module : Development.Shake.Plus.Extended.Loaders
Copyright : Copyright (C) 2020 Daniel Firth
Maintainer : Daniel Firth <dan.firth@homotopic.tech
License : MIT
Stability : experimental
-- |
-- Module : Development.Shake.Plus.Extended.Loaders
-- Copyright : Copyright (C) 2020 Daniel Firth
-- Maintainer : Daniel Firth <dan.firth@homotopic.tech
-- License : MIT
-- Stability : experimental
--
-- Experimental loaders for shake-plus. Load a collection of `FilePattern`s as a `HashMap`.
module Development.Shake.Plus.Extended.Loaders
( batchLoad,
batchLoadWithin,
batchLoadWithin',
batchLoadIndex,
batchLoadIndex',
)
where
Experimental loaders for shake-plus. Load a collection of `FilePattern`s as a `HashMap`.
-}
module Development.Shake.Plus.Extended.Loaders (
batchLoad
, batchLoadWithin
, batchLoadWithin'
, batchLoadIndex
, batchLoadIndex'
) where
import Control.Comonad.Env as E
import Development.Shake.Plus.Core
import Development.Shake.Plus.Directory
import qualified Data.IxSet.Typed as Ix
import Path
import RIO
import qualified RIO.HashMap as HM
import Within
import Control.Comonad.Env as E
import qualified Data.IxSet.Typed as Ix
import Development.Shake.Plus.Core
import Development.Shake.Plus.Directory
import Path
import RIO
import qualified RIO.HashMap as HM
import Within
traverseToSnd :: Functor f => (a -> f b) -> a -> f (a, b)
traverseToSnd f a = (a,) <$> f a
-- | Load a directory of `FilePattern`s via some loading function. This should
-- be a `Development.Shake.newCache` operation that takes full filepaths.
batchLoad :: MonadAction m
=> Path b Dir -- ^ The directory to search in
-> [FilePattern] -- ^ A filepattern to match against.
-> (Path b File -> m a) -- ^ A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
-> m (HashMap (Path Rel File) a)
batchLoad ::
MonadAction m =>
-- | The directory to search in
Path b Dir ->
-- | A filepattern to match against.
[FilePattern] ->
-- | A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
(Path b File -> m a) ->
m (HashMap (Path Rel File) a)
batchLoad dir pat f = do
xs <- getDirectoryFiles dir pat
xs <- getDirectoryFiles dir pat
xs' <- mapM (traverseToSnd $ f . (dir </>)) xs
return . HM.fromList $ xs'
-- | Like `batchLoad`, but returns an `Within` of a `Dir` containing the `HashMap`
batchLoadWithin :: MonadAction m
=> Within b [FilePattern] -- ^ The directory and filepattern to search.
-> (Within b (Path Rel File) -> m a) -- ^ A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
-> m (Within b (HashMap (Path Rel File) a))
batchLoadWithin ::
MonadAction m =>
-- | The directory and filepattern to search.
Within b [FilePattern] ->
-- | A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
(Within b (Path Rel File) -> m a) ->
m (Within b (HashMap (Path Rel File) a))
batchLoadWithin w f = do
xs <- getDirectoryFiles (E.ask w) (extract w)
xs <- getDirectoryFiles (E.ask w) (extract w)
xs' <- mapM (traverseToSnd $ f . (`within` E.ask w)) xs
return $ (`within` E.ask w) $ HM.fromList xs'
-- | Like `batchLoadWithin'`, but returns a `HashMap` containing `Within` values instead of an `Within` of a `Hashmap`.
batchLoadWithin' :: MonadAction m
=> Within b [FilePattern] -- ^ The directory and filepattern to search.
-> (Within b (Path Rel File) -> m a) -- ^ A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
-> m (HashMap (Within b (Path Rel File)) a)
batchLoadWithin' ::
MonadAction m =>
-- | The directory and filepattern to search.
Within b [FilePattern] ->
-- | A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
(Within b (Path Rel File) -> m a) ->
m (HashMap (Within b (Path Rel File)) a)
batchLoadWithin' w f = do
xs <- getDirectoryFiles (E.ask w) (extract w)
xs <- getDirectoryFiles (E.ask w) (extract w)
xs' <- mapM (traverseToSnd $ f . (`within` E.ask w)) xs
return $ HM.fromList (first (`within` E.ask w) <$> xs')
-- | Take a loading function and a filepattern and return an IxSet
batchLoadIndex :: (MonadAction m, Ix.Indexable ixs x)
=> (Path Rel File -> m x)
-> Path Rel Dir
-> [FilePattern]
-> m (Ix.IxSet ixs x)
batchLoadIndex ::
(MonadAction m, Ix.Indexable ixs x) =>
(Path Rel File -> m x) ->
Path Rel Dir ->
[FilePattern] ->
m (Ix.IxSet ixs x)
batchLoadIndex rd dir fp = Ix.fromList . HM.elems <$> batchLoad dir fp rd
-- | Take a loading function and a filepattern and return an IxSet
batchLoadIndex' :: (MonadAction m, Ix.Indexable ixs x)
=> Proxy ixs
-> (Path Rel File -> m x)
-> Path Rel Dir
-> [FilePattern]
-> m (Ix.IxSet ixs x)
batchLoadIndex' ::
(MonadAction m, Ix.Indexable ixs x) =>
Proxy ixs ->
(Path Rel File -> m x) ->
Path Rel Dir ->
[FilePattern] ->
m (Ix.IxSet ixs x)
batchLoadIndex' _ rd dir fp = Ix.fromList . HM.elems <$> batchLoad dir fp rd
{- |
Module : Development.Shake.Plus.Extended.Simple
Copyright : Copyright (C) 2020 Daniel Firth
Maintainer : Daniel Firth <dan.firth@homotopic.tech>
License : MIT
Stability : experimental
Shortcuts to run shake-plus with a simple environment.
-}
module Development.Shake.Plus.Extended.Simple (
SimpleSPlusEnv(..)
, runLoggedShakePlus
, runSimpleShakePlus
, runLoggedShakeForward
) where
-- |
-- Module : Development.Shake.Plus.Extended.Simple
-- Copyright : Copyright (C) 2020 Daniel Firth
-- Maintainer : Daniel Firth <dan.firth@homotopic.tech>
-- License : MIT
-- Stability : experimental
--
-- Shortcuts to run shake-plus with a simple environment.
module Development.Shake.Plus.Extended.Simple
( SimpleSPlusEnv (..),
runLoggedShakePlus,
runSimpleShakePlus,
runLoggedShakeForward,
)
where
import Development.Shake.Plus
import Development.Shake.Plus.Forward
import Development.Shake.Plus.Extended.FileRules
import Development.Shake.Plus.Forward
import RIO
data SimpleSPlusEnv = SimpleSPlusEnv {
logFunc :: LogFunc
, localOut :: Path Rel Dir
}
data SimpleSPlusEnv = SimpleSPlusEnv
{ logFunc :: LogFunc,
localOut :: Path Rel Dir
}
instance HasLogFunc SimpleSPlusEnv where
logFuncL = lens logFunc (\x y -> x { logFunc = y} )
logFuncL = lens logFunc (\x y -> x {logFunc = y})
instance HasLocalOut SimpleSPlusEnv where
localOutL = lens localOut (\x y -> x { localOut = y})
localOutL = lens localOut (\x y -> x {localOut = y})
-- | Run a `ShakePlus` with just a `LogFunc` in the environment that logs to stderr.
runLoggedShakePlus :: MonadIO m => ShakeOptions -> ShakePlus LogFunc a -> m ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment