pipes-shell 0.1.2 → 0.1.3
raw patch · 2 files changed
+44/−42 lines, 2 filesdep +directorydep ~hspecPVP ok
version bump matches the API change (PVP)
Dependencies added: directory
Dependency ranges changed: hspec
API changes (from Hackage documentation)
Files
- pipes-shell.cabal +25/−24
- src/Pipes/Shell.hs +19/−18
pipes-shell.cabal view
@@ -4,7 +4,7 @@ -- The name of the package. name: pipes-shell -version: 0.1.2+version: 0.1.3 -- A short (one-line) description of the package. synopsis: Create proper Pipes from System.Process@@ -59,21 +59,21 @@ -- other-extensions: -- Other library packages from which modules are imported.- build-depends: base >=4.5 && <4.8,- stm >=2.4 && <2.5,- process >=1.2 && <1.3,- pipes >= 4.0.1 && <5,- pipes-safe >= 2.0.1 && <3,- pipes-bytestring >= 1.0.1 && <3,- text >= 0.11.3.0 && <1.2,- bytestring >= 0.10.0.2 && <0.11,- async >= 2.0.1.0 && <2.1,- stm-chans >= 3.0.0 && <3.1+ build-depends: async >= 2.0.1.0 && <2.1+ , base >=4.5 && <4.8+ , bytestring >= 0.10.0.2 && <0.11+ , pipes >= 4.0.1 && <5+ , pipes-bytestring >= 1.0.1 && <3+ , pipes-safe >= 2.0.1 && <3+ , process >=1.2 && <1.3+ , stm >=2.4 && <2.5+ , stm-chans >= 3.0.0 && <3.1+ , text >= 0.11.3.0 && <1.2 -- Directories containing source files. hs-source-dirs: src - ghc-options: -O2 -Wall+ ghc-options: -Wall -O2 -- Base language which the package is written in. default-language: Haskell2010@@ -89,21 +89,22 @@ -- other-extensions: -- Other library packages from which modules are imported.- build-depends: base >=4.5 && <4.8,- stm >=2.4 && <2.5,- process >=1.2 && <1.3,- pipes >= 4.0.1 && <5,- pipes-safe >= 2.0.1 && <3,- pipes-bytestring >= 1.0.1 && <3,- text >= 0.11.3.0 && <1.2,- bytestring >= 0.10.0.2 && <0.11,- async >= 2.0.1.0 && <2.1,- stm-chans >= 3.0.0 && <3.1,- hspec >= 1.7.2.0 && <1.10+ build-depends: async >= 2.0.1.0 && <2.1+ , base >=4.5 && <4.8+ , bytestring >= 0.10.0.2 && <0.11+ , directory >= 1.2.1.0+ , hspec >= 1.12.1+ , pipes >= 4.0.1 && <5+ , pipes-bytestring >= 1.0.1 && <3+ , pipes-safe >= 2.0.1 && <3+ , process >=1.2 && <1.3+ , stm >=2.4 && <2.5+ , stm-chans >= 3.0.0 && <3.1+ , text >= 0.11.3.0 && <1.2 -- Directories containing source files. hs-source-dirs: src, test -- Base language which the package is written in. default-language: Haskell2010- ghc-options: -Wall -rtsopts+ ghc-options: -Wall -O2 -rtsopts
src/Pipes/Shell.hs view
@@ -42,9 +42,10 @@ import Control.Concurrent hiding (yield) import Control.Concurrent.Async import Control.Concurrent.STM-import Control.Concurrent.STM.TBMChan+import Control.Concurrent.STM.TMChan import qualified System.IO as IO import System.Process+import Debug.Trace import qualified Data.ByteString as BS @@ -134,13 +135,13 @@ -- >>> runShell $ yield (BSC.pack "aaa") >?> pipeCmdEnv Nothing "tr 'a' 'A'" >-> PBS.stdout -- AAA pipeCmdEnv :: MonadSafe m =>- Maybe [(String,String)] ->- String ->- Pipe (Maybe BS.ByteString) (Either BS.ByteString BS.ByteString) m ()+ Maybe [(String,String)] ->+ String ->+ Pipe (Maybe BS.ByteString) (Either BS.ByteString BS.ByteString) m () pipeCmdEnv env' cmdStr = bracket (aquirePipe env' cmdStr) releasePipe $ \(stdin, stdout, stderr) -> do - chan <- liftIO $ newTBMChanIO 4+ chan <- liftIO $ newTMChanIO _ <- liftIO . forkIO $ handlesToChan stdout stderr chan @@ -152,7 +153,7 @@ case got of Nothing -> do liftIO $ IO.hClose stdin- fromTBMChan chan+ fromTMChan chan Just val -> do liftIO $ BS.hPutStr stdin val yieldOne chan@@ -160,24 +161,24 @@ -- *try* to read one line from the chan and yield it. yieldOne chan = do- mLine <- liftIO $ atomically $ tryReadTBMChan chan+ mLine <- liftIO $ atomically $ tryReadTMChan chan whenJust (join mLine) yield - -- fill the TBMChan from the stdout and stderr handles+ -- fill the TMChan from the stdout and stderr handles -- the current implementation reads stderr and stdout async handlesToChan stdout stderr chan = do- out <- async $ toTBMChan chan $ do+ out <- async $ toTMChan chan $ do PBS.fromHandle stdout >-> P.map Right liftIO $ IO.hClose stdout - err <- async $ toTBMChan chan $ do+ err <- async $ toTMChan chan $ do PBS.fromHandle stderr >-> P.map Left liftIO $ IO.hClose stderr forM_ [out, err] wait - atomically $ closeTBMChan chan+ atomically $ closeTMChan chan -- | Like 'pipeCmdEnv' but doesn't set enviorment varaibles pipeCmd :: MonadSafe m =>@@ -284,16 +285,16 @@ whenJust (Just x) action = action x whenJust Nothing _ = return () -fromTBMChan :: (MonadIO m) => TBMChan a -> Producer' a m ()-fromTBMChan chan = do- msg <- liftIO $ atomically $ readTBMChan chan+fromTMChan :: (MonadIO m) => TMChan a -> Producer' a m ()+fromTMChan chan = do+ msg <- liftIO $ atomically $ readTMChan chan whenJust msg $ \m -> do yield m- fromTBMChan chan+ fromTMChan chan -toTBMChan :: MonadIO m => TBMChan a -> Producer' a m () -> m ()-toTBMChan chan prod = runEffect $- for prod (liftIO . atomically . writeTBMChan chan)+toTMChan :: MonadIO m => TMChan a -> Producer' a m () -> m ()+toTMChan chan prod = runEffect $+ for prod (liftIO . atomically . writeTMChan chan) -- | Creates the pipe handles aquirePipe :: MonadIO m =>