packages feed

cassava 0.5.2.0 → 0.5.3.0

raw patch · 8 files changed

+129/−32 lines, 8 filesdep ~QuickCheckdep ~basedep ~bytestringsetup-changednew-uploaderPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: QuickCheck, base, bytestring, containers, deepseq, text

API changes (from Hackage documentation)

Files

CHANGES.md view
@@ -1,3 +1,12 @@+## Version 0.5.3.0++ * Improve error messages for `lookup` and NamedRecord parsers (#197)+ * Fix bug (infinite loop) in `FromField Const` instance (#185)+ * Turn flag `bytestring--LT-0_10_4` off by default (#183)+ * Doc: Add cassava usage example of reading/writing to file (#97)+ * Update to latest version of dependencies (#190, #193, #199)+ * Tested with GHC 7.4 - 9.4 (#184, #204)+ ## Version 0.5.2.0   * Add `FromField`/`ToField` instances for `Identity` and `Const` (#158)
README.md view
@@ -1,5 +1,8 @@-# `cassava`: A CSV parsing and encoding library [![Hackage](https://img.shields.io/hackage/v/cassava.svg)](https://hackage.haskell.org/package/cassava) [![Build Status](https://travis-ci.org/hvr/cassava.svg)](https://travis-ci.org/hvr/cassava)+[![Hackage](https://img.shields.io/hackage/v/cassava.svg?label=Hackage&color=informational)](https://hackage.haskell.org/package/cassava)+[![Cabal build](https://github.com/haskell-hvr/cassava/workflows/Haskell-CI/badge.svg)](https://github.com/haskell-hvr/cassava/actions) +# `cassava`: A CSV parsing and encoding library+ **Please refer to the [package description](https://hackage.haskell.org/package/cassava#description) for an overview of `cassava`.**  ## Usage example@@ -91,7 +94,7 @@  ## Further reading -The primary API documentation for `cassava` is its Haddock documentation which can be found at http://hackage.haskell.org/package/cassava/docs/Data-Csv.html +The primary API documentation for `cassava` is its Haddock documentation which can be found at http://hackage.haskell.org/package/cassava/docs/Data-Csv.html  Below are listed additional recommended third-party blogposts and tutorials 
Setup.hs view
@@ -1,8 +1,3 @@ import Distribution.Simple main = defaultMain -----
cassava.cabal view
@@ -1,6 +1,6 @@ cabal-version:       1.12 Name:                cassava-Version:             0.5.2.0+Version:             0.5.3.0 Synopsis:            A CSV parsing and encoding library Description: { @@ -28,30 +28,45 @@ Please refer to the documentation in "Data.Csv" and the included [README](#readme) for more usage examples.  }-Homepage:            https://github.com/hvr/cassava+Homepage:            https://github.com/haskell-hvr/cassava License:             BSD3 License-file:        LICENSE-Bug-reports:         https://github.com/hvr/cassava/issues+Bug-reports:         https://github.com/haskell-hvr/cassava/issues Copyright:           (c) 2012 Johan Tibell                      (c) 2012 Bryan O'Sullivan                      (c) 2011 MailRank, Inc. Author:              Johan Tibell-Maintainer:          hvr@gnu.org+Maintainer:          https://github.com/haskell-hvr/cassava Category:            Text, Web, CSV Build-type:          Simple Extra-source-files:  examples/*.hs,                      CHANGES.md,                      README.md-Tested-with:         GHC==8.8.1, GHC==8.6.5, GHC==8.4.4, GHC ==8.2.2, GHC ==8.0.2, GHC ==7.10.3, GHC ==7.8.4, GHC ==7.6.3, GHC ==7.4.2+Tested-with:+  GHC == 9.4.1+  GHC == 9.2.3+  GHC == 9.0.2+  GHC == 8.10.7+  GHC == 8.8.4+  GHC == 8.6.5+  GHC == 8.4.4+  GHC == 8.2.2+  GHC == 8.0.2+  GHC == 7.10.3+  GHC == 7.8.4+  GHC == 7.6.3+  GHC == 7.4.2  ----------------------------------------------------------------------------  source-repository head   type:     git-  location: https://github.com/hvr/cassava.git+  location: https://github.com/haskell-hvr/cassava.git  flag bytestring--LT-0_10_4   description: [bytestring](https://hackage.haskell.org/haskell/package/bytestring) < 0.10.4+  default: False+  manual:  False  Library   default-language: Haskell2010@@ -94,19 +109,19 @@     Data.Csv.Util    Build-depends:-    array >= 0.4 && < 0.6,-    attoparsec >= 0.11.3.0 && < 0.14,-    base >= 4.5 && < 4.14,-    bytestring >= 0.9.2 && < 0.11,-    containers >= 0.4.2 && < 0.7,-    deepseq >= 1.1 && < 1.5,-    hashable < 1.4,-    scientific >= 0.3.4.7 && < 0.4,-    text < 1.3,-    transformers >= 0.2 && < 0.6,-    unordered-containers < 0.3,-    vector >= 0.8 && < 0.13,-    Only >= 0.1 && < 0.1.1+      base         >= 4.5      && < 4.18+    , array        >= 0.4      && < 0.6+    , attoparsec   >= 0.11.3.0 && < 0.15+    , bytestring   >= 0.9.2    && < 0.12+    , containers   >= 0.4.2    && < 0.7+    , deepseq      >= 1.1      && < 1.5+    , hashable                    < 1.5+    , scientific   >= 0.3.4.7  && < 0.4+    , text                        < 2.1+    , transformers >= 0.2      && < 0.7+    , unordered-containers        < 0.3+    , vector       >= 0.8      && < 0.14+    , Only         >= 0.1      && < 0.1.1    if flag(bytestring--LT-0_10_4)     build-depends: bytestring <  0.10.4@@ -137,7 +152,7 @@   if impl(ghc >= 8.2)     ghc-options: -Wcpp-undef -  ghc-options: -Wall -O2+  ghc-options: -Wall  ---------------------------------------------------------------------------- @@ -158,7 +173,7 @@                , vector   -- extra dependencies not already used by lib:cassava   build-depends: HUnit < 1.7-               , QuickCheck == 2.13.*+               , QuickCheck == 2.14.*                , quickcheck-instances >= 0.3.12 && < 0.4                , test-framework == 0.8.*                , test-framework-hunit == 0.3.*@@ -176,7 +191,9 @@    -- https://ghc.haskell.org/trac/ghc/wiki/Migration/8.0#Recommendationsforforward-compatibility   if impl(ghc >= 8.0)-    ghc-options: -Wcompat -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances+    ghc-options: -Wcompat -Wnoncanonical-monad-instances+    if impl(ghc < 8.8)+      ghc-options:  -Wnoncanonical-monadfail-instances   else     -- provide/emulate `Control.Monad.Fail` and `Data.Semigroups` API for pre-GHC8     build-depends: fail, semigroups
examples/NamedBasedExplicitDecode.hs view
src/Data/Csv.hs view
@@ -24,6 +24,9 @@     -- *** Name-based record conversion     -- $example-named-instance +    -- ** Reading/writing CSV files+    -- $example-file+     -- * Treating CSV data as opaque byte strings     -- $generic-processing @@ -151,6 +154,63 @@ -- -- In practice, the return type of 'decode' rarely needs to be given, -- as it can often be inferred from the context.++-- $example-file+--+-- Demonstration of reading from a CSV file/ writing to a CSV file+-- using the incremental API:+--+-- > {-# LANGUAGE BangPatterns      #-}+-- > {-# LANGUAGE DeriveGeneric     #-}+-- > {-# LANGUAGE LambdaCase        #-}+-- > {-# LANGUAGE OverloadedStrings #-}+-- >+-- > -- from base+-- > import GHC.Generics+-- > import System.IO+-- > import System.Exit (exitFailure)+-- > -- from bytestring+-- > import Data.ByteString (ByteString, hGetSome, empty)+-- > import qualified Data.ByteString.Lazy as BL+-- > -- from cassava+-- > import Data.Csv.Incremental+-- > import Data.Csv (FromRecord, ToRecord)+-- >+-- > data Person = Person+-- >   { name :: !ByteString+-- >   , age  :: !Int+-- >   } deriving (Show, Eq, Generic)+-- >+-- > instance FromRecord Person+-- > instance ToRecord Person+-- >+-- > persons :: [Person]+-- > persons = [Person "John Doe" 19, Person "Smith" 20]+-- >+-- > writeToFile :: IO ()+-- > writeToFile = do+-- >   BL.writeFile "persons.csv" $ encode $+-- >     foldMap encodeRecord persons+-- >+-- > feed :: (ByteString -> Parser Person) -> Handle -> IO (Parser Person)+-- > feed k csvFile = do+-- >   hIsEOF csvFile >>= \case+-- >     True  -> return $ k empty+-- >     False -> k <$> hGetSome csvFile 4096+-- >+-- > readFromFile :: IO ()+-- > readFromFile = do+-- >   withFile "persons.csv" ReadMode $ \ csvFile -> do+-- >     let loop !_ (Fail _ errMsg) = do putStrLn errMsg; exitFailure+-- >         loop acc (Many rs k)    = loop (acc <> rs) =<< feed k csvFile+-- >         loop acc (Done rs)      = print (acc <> rs)+-- >     loop [] (decode NoHeader)+-- >+-- > main :: IO ()+-- > main = do+-- >   writeToFile+-- >   readFromFile+-- >  -- $example-instance --
src/Data/Csv/Conversion.hs view
@@ -811,7 +811,7 @@  -- | @since 0.5.2.0 instance FromField a => FromField (Const a b) where-    parseField = fmap getConst . parseField+    parseField = fmap Const . parseField     {-# INLINE parseField #-}  -- | @since 0.5.2.0@@ -1148,8 +1148,11 @@ -- 'empty' if the field is missing or if the value cannot be converted -- to the desired type. lookup :: FromField a => NamedRecord -> B.ByteString -> Parser a-lookup m name = maybe (fail err) parseField $ HM.lookup name m+lookup m name = maybe (fail err) parseField' $ HM.lookup name m   where err = "no field named " ++ show (B8.unpack name)+        parseField' fld = case runParser (parseField fld) of+          Left e -> fail $ "in named field " ++ show (B8.unpack name) ++ ": " ++ e+          Right res -> pure res {-# INLINE lookup #-}  -- | Alias for 'lookup'.
tests/UnitTests.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE CPP, DeriveGeneric, OverloadedStrings, ScopedTypeVariables #-}+{-# LANGUAGE CPP, DataKinds, DeriveGeneric, OverloadedStrings, ScopedTypeVariables #-}  #if __GLASGOW_HASKELL__ >= 801 {-# OPTIONS_GHC -Wno-orphans -Wno-unused-top-binds #-}@@ -10,6 +10,7 @@     ( main     ) where +import Control.Applicative (Const) import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BL8@@ -303,6 +304,15 @@         (roundTrip :: BL.ByteString -> Bool)       , testProperty "Text" (roundTrip :: T.Text -> Bool)       , testProperty "lazy Text" (roundTrip :: LT.Text -> Bool)++#if __GLASGOW_HASKELL__ >= 800+      -- Using DataKinds here to prove that our Const instance is polykinded.+      , testProperty "Const Char" (roundTrip :: Const Char "" -> Bool)+#else+      -- For lower GHC versions, Const does not support PolyKinds.+      , testProperty "Const Char" (roundTrip :: Const Char () -> Bool)+#endif+       ]     , testGroup "boundary"       [ testProperty "Int" (boundary (undefined :: Int))