@@ -74,7 +74,6 @@ import Control.Monad.State.Strict
7474 evalStateT ,
7575 )
7676import Data.ByteString.Lazy (toStrict )
77- import Data.Functor ((<&>) )
7877import Data.Hashable (hash )
7978import Data.Map.Strict (Map )
8079import qualified Data.Map.Strict as M
@@ -84,7 +83,6 @@ import Data.Text.Encoding (decodeUtf8With)
8483import Data.Text.Encoding.Error (lenientDecode )
8584import System.Directory
8685 ( doesFileExist ,
87- findExecutable ,
8886 getCurrentDirectory ,
8987 getModificationTime ,
9088 )
@@ -141,7 +139,6 @@ runPlotM fmt conf v = do
141139 cwd <- getCurrentDirectory
142140 st <-
143141 PlotState <$> newMVar mempty
144- <*> newMVar mempty
145142 let verbosity = logVerbosity conf
146143 sink = logSink conf
147144 withLogger verbosity sink $
@@ -224,27 +221,23 @@ throwStrictError msg = do
224221 logger <- askLogger
225222 liftIO $ terminateLogging logger >> exitFailure
226223
227- -- Plot state is used for caching.
228- -- One part consists of a map of filepaths to hashes
224+ -- Plot state is used for caching a map of filepaths to hashes
229225-- This allows multiple plots to depend on the same file/directory, and the file hashes
230226-- will only be calculated once. This is OK because pandoc-plot will not run for long.
231227-- We note that because figures are rendered possibly in parallel, access to
232228-- the state must be synchronized; otherwise, each thread might compute its own
233229-- hashes.
234- -- The other part is comprised of a map of toolkits to renderers (possibly missing)
235- -- This means that checking if renderers are available will only be done once.
236230type FileHash = Word
237231
238232data PlotState
239233 = PlotState
240234 (MVar (Map FilePath FileHash ))
241- (MVar (Map Toolkit (Maybe Renderer )))
242235
243236-- | Get a filehash. If the file hash has been computed before,
244237-- it is reused. Otherwise, the filehash is calculated and stored.
245238fileHash :: FilePath -> PlotM FileHash
246239fileHash path = do
247- PlotState varHashes varExes <- get
240+ PlotState varHashes <- get
248241 hashes <- liftIO $ takeMVar varHashes
249242 (fh, hashes') <- case M. lookup path hashes of
250243 Nothing -> do
@@ -256,7 +249,7 @@ fileHash path = do
256249 debug $ mconcat [" Hash of dependency " , pack path, " already calculated." ]
257250 return (h, hashes)
258251 liftIO $ putMVar varHashes hashes'
259- put $ PlotState varHashes varExes
252+ put $ PlotState varHashes
260253 return fh
261254 where
262255 -- As a proxy for the state of a file dependency, we use the modification time
@@ -269,12 +262,8 @@ fileHash path = do
269262 else err (mconcat [" Dependency " , pack fp, " does not exist." ]) >> return 0
270263
271264-- | Find an executable.
272- executable :: Toolkit -> PlotM (Maybe Executable )
273- executable tk =
274- exeSelector tk
275- >>= \ name ->
276- liftIO $
277- findExecutable name <&> fmap exeFromPath
265+ executable :: Toolkit -> PlotM Executable
266+ executable tk = exeSelector tk >>= return . exeFromPath
278267 where
279268 exeSelector Matplotlib = asksConfig matplotlibExe
280269 exeSelector PlotlyPython = asksConfig plotlyPythonExe
0 commit comments