1
0
Fork 0
mirror of https://github.com/tensorflow/haskell.git synced 2024-12-24 18:49:46 +01:00

Update to LTS-11 (#187)

Fix Conduit 1.3 deprecation warnings
- The `Conduit`, `Producer` and `Consumer` aliases are deprecated and
  `ConduitT` is used directly instead
- `=$=` is deprecated and replaced by `.|`
This commit is contained in:
Erlend Hamberg 2018-05-19 01:20:11 +02:00 committed by fkm3
parent baa501b262
commit 88dafe8f3a
4 changed files with 17 additions and 18 deletions

View file

@ -1,4 +1,4 @@
resolver: lts-8.13
resolver: lts-11.9
packages:
- tensorflow
@ -16,12 +16,11 @@ packages:
extra-deps:
- snappy-framing-0.1.1
- snappy-0.2.0.2
# TODO: Remove these once the new versions are in lts-9.
# `haskell-src-exts < 1.20` is needed due the dependency on
# `proto-lens-protoc < 0.3` in the `tensorflow-proto` package:
- haskell-src-exts-1.19.1
- proto-lens-protobuf-types-0.2.2.0
- proto-lens-0.2.2.0
- proto-lens-descriptors-0.2.2.0
- proto-lens-protoc-0.2.2.3
- lens-labels-0.1.0.2
# For Mac OS X, whose linker doesn't use this path by default
# unless you run `xcode-select --install`.

View file

@ -58,7 +58,7 @@ import Control.Monad.Catch (MonadMask, bracket)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Trans.Resource (runResourceT)
import Data.ByteString (ByteString)
import Data.Conduit ((=$=))
import Data.Conduit ((.|))
import Data.Conduit.TQueue (sourceTBMQueue)
import Data.Default (def)
import Data.Int (Int64)
@ -113,8 +113,8 @@ newEventWriter logdir = do
let writer = EventWriter q done
consumeQueue = runResourceT $ Conduit.runConduit $
sourceTBMQueue q
=$= Conduit.map (L.fromStrict . encodeMessage)
=$= sinkTFRecords filename
.| Conduit.map (L.fromStrict . encodeMessage)
.| sinkTFRecords filename
_ <- forkFinally consumeQueue (\_ -> putMVar done ())
logEvent writer $ def & wallTime .~ t
& fileVersion .~ T.pack "brain.Event:2"

View file

@ -16,7 +16,7 @@
module Main where
import Control.Monad.Trans.Resource (runResourceT)
import Data.Conduit ((=$=))
import Data.Conduit ((.|))
import Data.Default (def)
import Data.List ((\\))
import Data.ProtoLens (encodeMessage, decodeMessageOrDie)
@ -53,7 +53,7 @@ testEventWriter = testCase "EventWriter" $
files <- listDirectory dir
assertEqual "One file exists after" 1 (length files)
records <- runResourceT $ Conduit.runConduit $
sourceTFRecords (dir </> head files) =$= Conduit.consume
sourceTFRecords (dir </> head files) .| Conduit.consume
assertBool "File is not empty" (not (null records))
let (header:body) = decodeMessageOrDie . BL.toStrict <$> records
assertEqual "Header has expected version"
@ -71,7 +71,7 @@ testLogGraph = testCase "LogGraph" $
logGraph eventWriter graphBuild
files <- listDirectory dir
records <- runResourceT $ Conduit.runConduit $
sourceTFRecords (dir </> head files) =$= Conduit.consume
sourceTFRecords (dir </> head files) .| Conduit.consume
let (_:event:_) = decodeMessageOrDie . BL.toStrict <$> records
assertEqual "First record expected to be Event containing GraphDef" expectedGraphEvent event

View file

@ -30,24 +30,24 @@ import Control.Monad.Catch (MonadThrow)
import Control.Monad.Trans.Resource (MonadResource)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import Data.Conduit ((=$=), Conduit, Consumer, Producer)
import Data.Conduit ((.|), ConduitT)
import Data.Conduit.Binary (sinkFile, sourceFile)
import Data.Conduit.Cereal (conduitGet2, conduitPut)
import TensorFlow.Records (getTFRecord, putTFRecord)
-- | Decode TFRecords from a stream of bytes.
decodeTFRecords :: MonadThrow m => Conduit B.ByteString m BL.ByteString
decodeTFRecords :: MonadThrow m => ConduitT B.ByteString BL.ByteString m ()
decodeTFRecords = conduitGet2 getTFRecord
-- | Read TFRecords from a file.
sourceTFRecords :: (MonadResource m, MonadThrow m) => FilePath -> Producer m BL.ByteString
sourceTFRecords path = sourceFile path =$= decodeTFRecords
sourceTFRecords :: (MonadResource m, MonadThrow m) => FilePath -> ConduitT i BL.ByteString m ()
sourceTFRecords path = sourceFile path .| decodeTFRecords
-- | Encode TFRecords to a stream of bytes.
encodeTFRecords :: Monad m => Conduit BL.ByteString m B.ByteString
encodeTFRecords :: Monad m => ConduitT BL.ByteString B.ByteString m ()
encodeTFRecords = conduitPut putTFRecord
-- | Write TFRecords to a file.
sinkTFRecords :: (MonadResource m) => FilePath -> Consumer BL.ByteString m ()
sinkTFRecords path = encodeTFRecords =$= sinkFile path
sinkTFRecords :: (MonadResource m) => FilePath -> ConduitT BL.ByteString o m ()
sinkTFRecords path = encodeTFRecords .| sinkFile path