summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Filter/Pyplot/Scripting.hs
diff options
context:
space:
mode:
authorLaurentRDC <>2019-04-08 23:10:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-04-08 23:10:00 (GMT)
commit27a4ae7b3b04161800959901a17dec4481c06c09 (patch)
tree7793f17e75e03ca22fea3d32cdf354c7159228b2 /src/Text/Pandoc/Filter/Pyplot/Scripting.hs
parent30fea466d0dd6beb5e55a851e802ea7b470a35d0 (diff)
version 2.1.0.12.1.0.1
Diffstat (limited to 'src/Text/Pandoc/Filter/Pyplot/Scripting.hs')
-rw-r--r--src/Text/Pandoc/Filter/Pyplot/Scripting.hs23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Filter/Pyplot/Scripting.hs b/src/Text/Pandoc/Filter/Pyplot/Scripting.hs
index ec90780..d867363 100644
--- a/src/Text/Pandoc/Filter/Pyplot/Scripting.hs
+++ b/src/Text/Pandoc/Filter/Pyplot/Scripting.hs
@@ -14,13 +14,10 @@ with running Python scripts.
module Text.Pandoc.Filter.Pyplot.Scripting
( runTempPythonScript
, hasBlockingShowCall
- , PythonScript
- , ScriptResult(..)
) where
import Data.Hashable (hash)
import Data.Monoid (Any(..))
-import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
@@ -29,40 +26,34 @@ import System.FilePath ((</>))
import System.IO.Temp (getCanonicalTemporaryDirectory)
import System.Process.Typed (runProcess, shell)
--- | String representation of a Python script
-type PythonScript = Text
-
--- | Possible result of running a Python script
-data ScriptResult
- = ScriptSuccess
- | ScriptFailure Int
+import Text.Pandoc.Filter.Pyplot.Types
-- | Take a python script in string form, write it in a temporary directory,
-- then execute it.
runTempPythonScript :: String -- ^ Interpreter (e.g. "python" or "python35")
-> PythonScript -- ^ Content of the script
-> IO ScriptResult -- ^ Result with exit code.
-runTempPythonScript interpreter script = do
+runTempPythonScript interpreter' script' = do
-- We involve the script hash as a temporary filename
-- so that there is never any collision
scriptPath <- (</> hashedPath) <$> getCanonicalTemporaryDirectory
- T.writeFile scriptPath script
+ T.writeFile scriptPath script'
- ec <- runProcess $ shell $ mconcat [interpreter, " ", show scriptPath]
+ ec <- runProcess $ shell $ mconcat [interpreter', " ", show scriptPath]
case ec of
ExitSuccess -> return ScriptSuccess
ExitFailure code -> return $ ScriptFailure code
where
- hashedPath = show . hash $ script
+ hashedPath = show . hash $ script'
-- | Detect the presence of a blocking show call, for example "plt.show()"
hasBlockingShowCall :: PythonScript -> Bool
-hasBlockingShowCall script =
+hasBlockingShowCall script' =
anyOf
[ "plt.show()" `elem` scriptLines
, "pyplot.show()" `elem` scriptLines
, "matplotlib.pyplot.show()" `elem` scriptLines
]
where
- scriptLines = T.lines script
+ scriptLines = T.lines script'
anyOf xs = getAny $ mconcat $ Any <$> xs \ No newline at end of file