mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-11 16:12:20 +00:00
Add 'check' command to verify dependencies.
This commit is contained in:
parent
be02961285
commit
25fad43b53
3 changed files with 130 additions and 19 deletions
|
|
@ -16,7 +16,6 @@ jobs:
|
|||
export PATH=$HOME/.local/bin:$PATH
|
||||
curl --insecure -L https://get.haskellstack.org/stable/osx-x86_64.tar.gz | tar xz --strip-components=1 --include '*/stack' -C ~/.local/bin
|
||||
stack build
|
||||
stack test
|
||||
- job: linux
|
||||
pool:
|
||||
vmImage: 'ubuntu-latest'
|
||||
|
|
@ -26,5 +25,5 @@ jobs:
|
|||
export PATH=$HOME/.local/bin:$PATH
|
||||
curl -L https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
|
||||
stack build
|
||||
stack test
|
||||
./examples/counter.hs check
|
||||
displayName: 'Build reanimate'
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ library
|
|||
diagrams-core, diagrams-lib, diagrams-contrib,
|
||||
svg-builder, matrices, cubicbezier, palette, websockets,
|
||||
hashable, fsnotify, open-browser, random-shuffle, base64-bytestring,
|
||||
vector, colour, cassava
|
||||
vector, colour, cassava, ansi-wl-pprint
|
||||
|
||||
Flag server
|
||||
Description: Enable rendering server
|
||||
|
|
|
|||
|
|
@ -1,27 +1,32 @@
|
|||
module Reanimate.Driver ( reanimate ) where
|
||||
|
||||
import Control.Concurrent (MVar, forkIO, killThread, modifyMVar_,
|
||||
newEmptyMVar, putMVar, takeMVar)
|
||||
import Control.Exception (finally)
|
||||
import Control.Monad.Fix (fix)
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Read as T
|
||||
import Control.Concurrent (MVar, forkIO, killThread,
|
||||
modifyMVar_, newEmptyMVar,
|
||||
putMVar, takeMVar)
|
||||
import Control.Exception (finally)
|
||||
import Control.Monad.Fix (fix)
|
||||
import Control.Monad
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Read as T
|
||||
import Network.WebSockets
|
||||
import System.Directory (findFile, listDirectory)
|
||||
import System.Environment (getArgs, getProgName)
|
||||
import System.Directory (findFile, listDirectory, findExecutable)
|
||||
import System.Environment (getArgs, getProgName)
|
||||
import System.Exit
|
||||
import Text.Printf
|
||||
import System.FilePath
|
||||
import System.FSNotify
|
||||
import System.Exit
|
||||
import System.IO (BufferMode (..), hPutStrLn, hSetBuffering,
|
||||
stderr, stdin)
|
||||
import System.IO (BufferMode (..), hPutStrLn,
|
||||
hSetBuffering, stderr, stdin)
|
||||
import qualified Text.PrettyPrint.ANSI.Leijen as Doc
|
||||
|
||||
import Data.Maybe
|
||||
import Paths_reanimate
|
||||
import Reanimate.Misc (runCmdLazy, runCmd_, withTempDir,
|
||||
withTempFile)
|
||||
import Reanimate.Monad (Animation)
|
||||
import Reanimate.Render (render, renderSvgs, renderSnippets)
|
||||
import Web.Browser (openBrowser)
|
||||
import Reanimate.Misc (runCmdLazy, runCmd_, withTempDir,
|
||||
withTempFile)
|
||||
import Reanimate.Monad (Animation)
|
||||
import Reanimate.Render (render, renderSnippets,
|
||||
renderSvgs)
|
||||
import Web.Browser (openBrowser)
|
||||
|
||||
opts = defaultConnectionOptions
|
||||
{ connectionCompressionOptions = PermessageDeflateCompression defaultPermessageDeflate }
|
||||
|
|
@ -34,6 +39,7 @@ reanimate animation = do
|
|||
case args of
|
||||
["once"] -> renderSvgs animation
|
||||
["snippets"] -> renderSnippets animation
|
||||
["check"] -> checkEnvironment
|
||||
["render", target] ->
|
||||
render animation target
|
||||
_ -> withTempDir $ \tmpDir -> do
|
||||
|
|
@ -112,3 +118,109 @@ ghcOptions :: FilePath -> [String]
|
|||
ghcOptions tmpDir =
|
||||
["-rtsopts", "--make", "-threaded", "-O2"] ++
|
||||
["-odir", tmpDir, "-hidir", tmpDir]
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
-- Check environment
|
||||
|
||||
checkEnvironment :: IO ()
|
||||
checkEnvironment = do
|
||||
putStrLn "reanimate checks:"
|
||||
runCheck "Has LaTeX" hasLaTeX
|
||||
runCheck "Has XeLaTeX" hasXeLaTeX
|
||||
runCheck "Has dvisvgm" hasDvisvgm
|
||||
forM_ latexPackages $ \pkg ->
|
||||
runCheck ("Has LaTeX package '"++ pkg ++ "'") $ hasTeXPackage "latex" $
|
||||
"{"++pkg++"}"
|
||||
forM_ xelatexPackages $ \pkg ->
|
||||
runCheck ("Has XeLaTeX package '"++ pkg ++ "'") $ hasTeXPackage "xelatex" $
|
||||
"{"++pkg++"}"
|
||||
where
|
||||
latexPackages =
|
||||
["babel"
|
||||
,"amsmath"
|
||||
,"amssymb"
|
||||
,"dsfont"
|
||||
,"setspace"
|
||||
,"relsize"
|
||||
,"textcomp"
|
||||
,"mathrsfs"
|
||||
,"calligra"
|
||||
,"wasysym"
|
||||
,"ragged2e"
|
||||
,"physics"
|
||||
,"xcolor"
|
||||
,"textcomp"
|
||||
,"xfrac"
|
||||
,"microtype"]
|
||||
xelatexPackages =
|
||||
["ctex"]
|
||||
runCheck msg fn = do
|
||||
printf " %-35s" (msg ++ ":")
|
||||
val <- fn
|
||||
case val of
|
||||
Left err -> print $ Doc.red $ Doc.text err
|
||||
Right ok -> print $ Doc.green $ Doc.text ok
|
||||
|
||||
-- latex, dvisvgm, xelatex
|
||||
|
||||
hasLaTeX :: IO (Either String String)
|
||||
hasLaTeX = hasProgram "latex"
|
||||
|
||||
hasXeLaTeX :: IO (Either String String)
|
||||
hasXeLaTeX = hasProgram "xelatex"
|
||||
|
||||
hasDvisvgm :: IO (Either String String)
|
||||
hasDvisvgm = hasProgram "dvisvgm"
|
||||
|
||||
hasTeXPackage :: FilePath -> String -> IO (Either String String)
|
||||
hasTeXPackage exec pkg =
|
||||
withTempDir $ \tmp_dir -> withTempFile "tex" $ \tex_file -> do
|
||||
let tmp_dir = "."
|
||||
tex_file = "test.tex"
|
||||
writeFile tex_file tex_document
|
||||
appendFile tex_file $ "\\usepackage" ++ pkg ++ "\n"
|
||||
appendFile tex_file "\\begin{document}\n"
|
||||
appendFile tex_file "blah\n"
|
||||
appendFile tex_file tex_epilogue
|
||||
ret <- runCmd_ exec ["-interaction=batchmode", "-halt-on-error", "-output-directory="++tmp_dir, tex_file]
|
||||
return $ case ret of
|
||||
Right{} -> Right "OK"
|
||||
Left{} -> Left "missing"
|
||||
where
|
||||
tex_document = "\\documentclass[preview]{standalone}\n"
|
||||
tex_xelatex =
|
||||
"\\usepackage[UTF8]{ctex}\n"
|
||||
|
||||
tex_prologue =
|
||||
"\\usepackage[english]{babel}\n\
|
||||
\\\usepackage{amsmath}\n\
|
||||
\\\usepackage{amssymb}\n\
|
||||
\\\usepackage{dsfont}\n\
|
||||
\\\usepackage{setspace}\n\
|
||||
\\\usepackage{relsize}\n\
|
||||
\\\usepackage{textcomp}\n\
|
||||
\\\usepackage{mathrsfs}\n\
|
||||
\\\usepackage{calligra}\n\
|
||||
\\\usepackage{wasysym}\n\
|
||||
\\\usepackage{ragged2e}\n\
|
||||
\\\usepackage{physics}\n\
|
||||
\\\usepackage{xcolor}\n\
|
||||
\\\usepackage{textcomp}\n\
|
||||
\\\usepackage{xfrac}\n\
|
||||
\\\usepackage{microtype}\n\
|
||||
\\\linespread{1}\n\
|
||||
\\\begin{document}\n"
|
||||
|
||||
tex_epilogue =
|
||||
"\n\
|
||||
\\\end{document}"
|
||||
|
||||
hasProgram :: String -> IO (Either String String)
|
||||
hasProgram exec = do
|
||||
mbPath <- findExecutable exec
|
||||
return $ case mbPath of
|
||||
Nothing -> Left $ "'" ++ exec ++ "'' not found"
|
||||
Just path -> Right path
|
||||
|
|
|
|||
Loading…
Reference in a new issue