pandoc-plot 0.9.3.0 → 0.9.4.0
raw patch · 7 files changed
+71/−40 lines, 7 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Text.Pandoc.Filter.Plot.Internal: [envCWD] :: RuntimeEnv -> FilePath
- Text.Pandoc.Filter.Plot.Internal: RuntimeEnv :: Configuration -> Logger -> RuntimeEnv
+ Text.Pandoc.Filter.Plot.Internal: RuntimeEnv :: Configuration -> Logger -> FilePath -> RuntimeEnv
Files
- CHANGELOG.md +8/−3
- MANUAL.md +1/−1
- docs/MANUAL.html +3/−3
- pandoc-plot.cabal +2/−1
- src/Text/Pandoc/Filter/Plot/Monad.hs +9/−5
- src/Text/Pandoc/Filter/Plot/Scripting.hs +43/−27
- tests/fixtures/data.csv +5/−0
CHANGELOG.md view
@@ -2,18 +2,23 @@ pandoc-plot uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html) +Release 0.9.4.0 +--------------- + +* Fixed an issue where the current working directory was changed. This prevented users from referring to files in scripts with relative paths (#2). + Release 0.9.3.0 --------------- -* Added executable caching: repeated useage of a particular toolkit will be faster because executables are only looked-for once. +* Added executable caching: repeated usage of a particular toolkit will be faster because executables are only looked-for once. * Reverting the change from 0.8.1.0: internal machinery of `pandoc-plot` has been moved to the `Text.Pandoc.Filter.Plot.Internal` module, where there is no guarantee of backwards-compatibility after 1.0.0. * Removed the `makePlot` function, which could not take advantage of multithreading and other key features of `pandoc-plot`. -* Fixed an issue where files required for tests were missing from source tarballs. +* Fixed an issue where files required for tests were missing from source tarballs (#13). Release 0.9.2.0 --------------- -* Fixed an issue where executables located on paths with spaces would not be invoked correctly (#12) +* Fixed an issue where executables located on paths with spaces would not be invoked correctly (#12). * Fixed an issue where R-paths were not normalized correctly. * Fixed an issue where executables specified in configuration that did not exist would crash `pandoc-plot`. * Fixed an issue where some R-based toolkits appeared to be available, but were not.
MANUAL.md view
@@ -159,7 +159,7 @@ `pandoc-plot` is a command line executable with a few functions. You can take a look at the help using the `-h`/`--help` flag: ``` bash -pandoc-plot 0.9.3.0 - generate figures directly in documents +pandoc-plot 0.9.4.0 - generate figures directly in documents Usage: pandoc-plot.EXE [(-v|--version) | --full-version | (-m|--manual)] [COMMAND] [AST]
docs/MANUAL.html view
@@ -4,7 +4,7 @@ <meta charset="utf-8" /> <meta name="generator" content="pandoc" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> - <title>pandoc-plot 0.9.3.0 manual</title> + <title>pandoc-plot 0.9.4.0 manual</title> <style> code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} @@ -83,7 +83,7 @@ </head> <body> <header id="title-block-header"> -<h1 class="title">pandoc-plot 0.9.3.0 manual</h1> +<h1 class="title">pandoc-plot 0.9.4.0 manual</h1> </header> <!-- The file MANUAL.md is automatically generated by the tools/mkmanual.ps1 script. Do not edit manually. @@ -187,7 +187,7 @@ <div class="sourceCode" id="cb10"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="ex">pandoc</span> --filter pandoc-plot --filter pandoc-crossref -i myfile.md -o myfile.html</span></code></pre></div> <h2 id="detailed-usage">Detailed usage</h2> <p><code>pandoc-plot</code> is a command line executable with a few functions. You can take a look at the help using the <code>-h</code>/<code>--help</code> flag:</p> -<div class="sourceCode" id="cb11"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="ex">pandoc-plot</span> 0.9.3.0 - generate figures directly in documents</span> +<div class="sourceCode" id="cb11"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="ex">pandoc-plot</span> 0.9.4.0 - generate figures directly in documents</span> <span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a></span> <span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a><span class="ex">Usage</span>: pandoc-plot.EXE [(-v<span class="kw">|</span><span class="ex">--version</span>) <span class="kw">|</span> <span class="ex">--full-version</span> <span class="kw">|</span> <span class="kw">(</span><span class="ex">-m</span><span class="kw">|</span><span class="ex">--manual</span><span class="kw">)</span>] </span> <span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a> [<span class="ex">COMMAND</span>] [AST]</span>
pandoc-plot.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: pandoc-plot -version: 0.9.3.0 +version: 0.9.4.0 synopsis: A Pandoc filter to include figures generated from code blocks using your plotting toolkit of choice. description: A Pandoc filter to include figures generated from code blocks. Keep the document and code in the same location. Output is captured and included as a figure. category: Text @@ -25,6 +25,7 @@ tests/fixtures/.empty-config.yml tests/fixtures/.verbose-config.yml tests/fixtures/plotfile.py + tests/fixtures/data.csv tests/includes/bokeh.py tests/includes/ggplot2.r tests/includes/gnuplot.gp
src/Text/Pandoc/Filter/Plot/Monad.hs view
@@ -55,7 +55,9 @@ import Data.Text.Encoding (decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) -import System.Directory (doesFileExist, getModificationTime, findExecutable) +import System.Directory ( doesFileExist, getModificationTime + , findExecutable, getCurrentDirectory + ) import System.Exit (ExitCode (..)) import System.Process.Typed ( readProcessStderr, shell, nullStream , setStdout, setStderr, byteStringOutput @@ -74,14 +76,15 @@ data RuntimeEnv = - RuntimeEnv { envConfig :: Configuration - , envLogger :: Logger + RuntimeEnv { envConfig :: Configuration + , envLogger :: Logger + , envCWD :: FilePath } -- | Modify the runtime environment to be silent. silence :: PlotM a -> PlotM a -silence = local (\(RuntimeEnv c l) -> RuntimeEnv c l{lVerbosity = Silent}) +silence = local (\(RuntimeEnv c l d) -> RuntimeEnv c l{lVerbosity = Silent} d) -- | Get access to configuration within the @PlotM@ monad. @@ -92,12 +95,13 @@ -- | Evaluate a @PlotM@ action. runPlotM :: Configuration -> PlotM a -> IO a runPlotM conf v = do + cwd <- getCurrentDirectory st <- PlotState <$> newMVar mempty <*> newMVar mempty let verbosity = logVerbosity conf sink = logSink conf withLogger verbosity sink $ - \logger -> runReaderT (evalStateT v st) (RuntimeEnv conf logger) + \logger -> runReaderT (evalStateT v st) (RuntimeEnv conf logger cwd) debug, err, warning, info :: Text -> PlotM ()
src/Text/Pandoc/Filter/Plot/Scripting.hs view
@@ -27,8 +27,8 @@ import Paths_pandoc_plot (version) import System.Directory (createDirectoryIfMissing, - doesFileExist, getTemporaryDirectory, - getCurrentDirectory) + doesFileExist, getTemporaryDirectory) +import System.Environment (getEnv, setEnv) import System.Exit (ExitCode (..)) import System.FilePath (addExtension, normalise, replaceExtension, @@ -65,8 +65,8 @@ -- | Possible result of running a script data ScriptResult = ScriptSuccess - | ScriptChecksFailed Text -- Message - | ScriptFailure Text Int -- Command and exit code + | ScriptChecksFailed Text -- Message + | ScriptFailure Text Int -- Command and exit code | ToolkitNotInstalled Toolkit -- Script failed because toolkit is not installed instance Show ScriptResult where @@ -97,31 +97,33 @@ exe <- executable toolkit case exe of Nothing -> error $ "Toolkit " <> show toolkit <> " is not installed." - Just (Executable exedir exename) -> do - -- Commands are run from the executable directory, - -- so we need to tell the full absolute path where to save the - -- figure - curdir <- liftIO $ getCurrentDirectory - let scriptWithCapture = (capture toolkit) spec (curdir </> target) + Just (Executable exedir exename) -> + -- Change the PATH environment variable so the appropriate executable is + -- found first + withPrependedPath exedir $ do + let scriptWithCapture = (capture toolkit) spec target - liftIO $ T.writeFile scriptPath scriptWithCapture - let outputSpec = OutputSpec { oFigureSpec = spec - , oScriptPath = scriptPath - , oFigurePath = target - } + liftIO $ T.writeFile scriptPath scriptWithCapture + let outputSpec = OutputSpec { oFigureSpec = spec + , oScriptPath = scriptPath + , oFigurePath = target + } - let command_ = command toolkit outputSpec exename - (ec, _) <- runCommand exedir command_ - case ec of - ExitSuccess -> return ScriptSuccess - ExitFailure code -> do - -- Two possible types of failures: either the script - -- failed because the toolkit was not available, or - -- because of a genuine error - toolkitInstalled <- toolkitAvailable toolkit - if toolkitInstalled - then return $ ScriptFailure command_ code - else return $ ToolkitNotInstalled toolkit + let command_ = command toolkit outputSpec exename + -- It is important that the CWD be inherited from the + -- parent process. See #2. + cwd <- asks envCWD + (ec, _) <- runCommand cwd command_ + case ec of + ExitSuccess -> return ScriptSuccess + ExitFailure code -> do + -- Two possible types of failures: either the script + -- failed because the toolkit was not available, or + -- because of a genuine error + toolkitInstalled <- toolkitAvailable toolkit + if toolkitInstalled + then return $ ScriptFailure command_ code + else return $ ToolkitNotInstalled toolkit -- | Determine the temp script path from Figure specifications @@ -176,3 +178,17 @@ let ext = extension . saveFormat $ spec stem = flip addExtension ext . show $ fh return $ normalise $ directory spec </> stem + + +-- | Prepend a directory to the PATH environment variable for the duration +-- of a computation. +withPrependedPath :: FilePath -> PlotM a -> PlotM a +withPrependedPath dir f = do + pathVar <- liftIO $ getEnv "PATH" + let pathVarPrepended = mconcat [dir, ";", pathVar] + liftIO $ setEnv "PATH" $ pathVarPrepended + r <- f + liftIO $ setEnv "PATH" pathVar + return r + +
+ tests/fixtures/data.csv view
@@ -0,0 +1,5 @@+0,0 +1,1 +2,2 +3,3 +4,4