Skip to content

Commit 7f2467a

Browse files
authored
Migrate to prettyprinter from deprecated ansi-wl-pprint (#279)
We replace the `text` function in most places in favour of just using the already-enabled `OverloadedStrings`, or with `pretty` when not using string literals. Where the old instance `Pretty a => Pretty (Maybe a)` was relied upon, we replace `pretty` with `maybe mempty id` (then apply an HLint-suggested simplification), which is what we'd get from inlining a few definitions with the old library.
1 parent 593e3eb commit 7f2467a

File tree

4 files changed

+78
-77
lines changed

4 files changed

+78
-77
lines changed

src/Database/Postgres/Temp/Internal.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import Data.ByteString (ByteString)
1919
import qualified Data.Map.Strict as Map
2020
import qualified Database.PostgreSQL.Simple.Options as Client
2121
import GHC.Generics
22+
import Prettyprinter
2223
import System.Exit (ExitCode(..))
2324
import System.IO.Unsafe (unsafePerformIO)
2425
import System.Process
25-
import Text.PrettyPrint.ANSI.Leijen hiding ((<$>))
2626
import System.Directory
2727

2828
-- | Handle for holding temporary resources, the @postgres@ process handle
@@ -40,11 +40,11 @@ data DB = DB
4040

4141
instance Pretty DB where
4242
pretty DB {..}
43-
= text "dbResources"
43+
= "dbResources"
4444
<> softline
4545
<> indent 2 (pretty dbResources)
4646
<> hardline
47-
<> text "dbPostgresProcess"
47+
<> "dbPostgresProcess"
4848
<> softline
4949
<> indent 2 (pretty dbPostgresProcess)
5050

src/Database/Postgres/Temp/Internal/Config.hs

+40-40
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Data.Traversable
3636
import qualified Database.PostgreSQL.Simple.Options as Client
3737
import GHC.Generics (Generic)
3838
import Network.Socket.Free (getFreePort)
39+
import Prettyprinter
3940
import System.Directory
4041
import System.Environment
4142
import System.Exit (ExitCode(..))
@@ -44,7 +45,6 @@ import System.IO.Error
4445
import System.IO.Temp (createTempDirectory)
4546
import System.IO.Unsafe (unsafePerformIO)
4647
import System.Process
47-
import Text.PrettyPrint.ANSI.Leijen hiding ((<$>))
4848
import Control.Applicative
4949

5050
{-|
@@ -90,7 +90,7 @@ getAccum = \case
9090
instance Monoid a => Monoid (Accum a) where
9191
mempty = DontCare
9292

93-
prettyMap :: (Pretty a, Pretty b) => Map a b -> Doc
93+
prettyMap :: (Pretty a, Pretty b) => Map a b -> Doc ann
9494
prettyMap theMap =
9595
let xs = Map.toList theMap
9696
in vsep $ map (uncurry prettyKeyPair) xs
@@ -119,10 +119,10 @@ instance Monoid EnvironmentVariables where
119119

120120
instance Pretty EnvironmentVariables where
121121
pretty EnvironmentVariables {..}
122-
= text "inherit:"
122+
= "inherit:"
123123
<+> pretty (getLast inherit)
124124
<> hardline
125-
<> text "specific:"
125+
<> "specific:"
126126
<> softline
127127
<> indent 2 (prettyMap specific)
128128

@@ -168,15 +168,15 @@ instance Semigroup CommandLineArgs where
168168

169169
instance Pretty CommandLineArgs where
170170
pretty p@CommandLineArgs {..}
171-
= text "keyBased:"
171+
= "keyBased:"
172172
<> softline
173173
<> indent 2 (prettyMap keyBased)
174174
<> hardline
175-
<> text "indexBased:"
175+
<> "indexBased:"
176176
<> softline
177177
<> indent 2 (prettyMap indexBased)
178178
<> hardline
179-
<> text "completed:" <+> text (unwords (completeCommandLineArgs p))
179+
<> "completed:" <+> pretty (unwords (completeCommandLineArgs p))
180180

181181
-- Take values as long as the index is the successor of the
182182
-- last index.
@@ -222,24 +222,24 @@ data ProcessConfig = ProcessConfig
222222

223223
instance Pretty ProcessConfig where
224224
pretty ProcessConfig {..}
225-
= text "environmentVariables:"
225+
= "environmentVariables:"
226226
<> softline
227227
<> indent 2 (pretty environmentVariables)
228228
<> hardline
229-
<> text "commandLine:"
229+
<> "commandLine:"
230230
<> softline
231231
<> indent 2 (pretty environmentVariables)
232232
<> hardline
233-
<> text "stdIn:" <+>
234-
pretty (prettyHandle <$> getLast stdIn)
233+
<> "stdIn:" <+>
234+
maybe mempty prettyHandle (getLast stdIn)
235235
<> hardline
236-
<> text "stdOut:" <+>
237-
pretty (prettyHandle <$> getLast stdOut)
236+
<> "stdOut:" <+>
237+
maybe mempty prettyHandle (getLast stdOut)
238238
<> hardline
239-
<> text "stdErr:" <+>
240-
pretty (prettyHandle <$> getLast stdErr)
239+
<> "stdErr:" <+>
240+
maybe mempty prettyHandle (getLast stdErr)
241241
<> hardline
242-
<> text "createGroup:" <+>
242+
<> "createGroup:" <+>
243243
pretty (getAny createGroup)
244244

245245

@@ -327,8 +327,8 @@ toFilePath = \case
327327

328328
instance Pretty CompleteDirectoryType where
329329
pretty = \case
330-
CPermanent x -> text "CPermanent" <+> pretty x
331-
CTemporary x -> text "CTemporary" <+> pretty x
330+
CPermanent x -> "CPermanent" <+> pretty x
331+
CTemporary x -> "CTemporary" <+> pretty x
332332

333333
makePermanent :: CompleteDirectoryType -> CompleteDirectoryType
334334
makePermanent = \case
@@ -349,8 +349,8 @@ data DirectoryType
349349

350350
instance Pretty DirectoryType where
351351
pretty = \case
352-
Permanent x -> text "Permanent" <+> pretty x
353-
Temporary -> text "Temporary"
352+
Permanent x -> "Permanent" <+> pretty x
353+
Temporary -> "Temporary"
354354

355355
-- | Takes the last 'Permanent' value.
356356
instance Semigroup DirectoryType where
@@ -546,46 +546,46 @@ data Config = Config
546546

547547
instance Pretty Config where
548548
pretty Config {..}
549-
= text "socketDirectory:"
549+
= "socketDirectory:"
550550
<> softline
551551
<> pretty socketDirectory
552552
<> hardline
553-
<> text "dataDirectory:"
553+
<> "dataDirectory:"
554554
<> softline
555555
<> pretty dataDirectory
556556
<> hardline
557-
<> text "port:" <+> pretty (getLast port)
557+
<> "port:" <+> pretty (getLast port)
558558
<> hardline
559-
<> text "temporaryDirectory:"
559+
<> "temporaryDirectory:"
560560
<> softline
561561
<> pretty (getLast temporaryDirectory)
562562
<> hardline
563-
<> text "initDbCache:" <+> pretty (getLast initDbCache)
563+
<> "initDbCache:" <+> pretty (getLast initDbCache)
564564
<> hardline
565-
<> text "initDbConfig:"
565+
<> "initDbConfig:"
566566
<> softline
567567
<> indent 2 (pretty $ getAccum initDbConfig)
568568
<> hardline
569-
<> text "initDbConfig:"
569+
<> "initDbConfig:"
570570
<> softline
571571
<> indent 2 (pretty $ getAccum createDbConfig)
572-
<> text "copyConfig:"
572+
<> "copyConfig:"
573573
<> softline
574574
<> indent 2 (pretty (getLast copyConfig))
575575
<> hardline
576-
<> text "postgresConfig:"
576+
<> "postgresConfig:"
577577
<> softline
578578
<> indent 2 (pretty postgresConfig)
579579
<> hardline
580-
<> text "connectionOptions:"
580+
<> "connectionOptions:"
581581
<> softline
582582
<> indent 2 (prettyOptions connectionOptions)
583583
<> hardline
584-
<> text "postgresConfigFile:"
584+
<> "postgresConfigFile:"
585585
<> softline
586-
<> indent 2 (vsep $ map (\(x, y) -> text x <> "=" <> text y) postgresConfigFile)
586+
<> indent 2 (vsep $ map (\(x, y) -> pretty x <> "=" <> pretty y) postgresConfigFile)
587587
<> hardline
588-
<> text "connectionTimeout:" <+> pretty (getLast connectionTimeout)
588+
<> "connectionTimeout:" <+> pretty (getLast connectionTimeout)
589589

590590
socketDirectoryToConfig :: FilePath -> [(String, String)]
591591
socketDirectoryToConfig dir =
@@ -613,15 +613,15 @@ data CopyDirectoryCommand = CopyDirectoryCommand
613613

614614
instance Pretty CopyDirectoryCommand where
615615
pretty CopyDirectoryCommand {..}
616-
= text "sourceDirectory:"
616+
= "sourceDirectory:"
617617
<> softline
618-
<> indent 2 (text sourceDirectory)
618+
<> indent 2 (pretty sourceDirectory)
619619
<> hardline
620-
<> text "destinationDirectory:"
620+
<> "destinationDirectory:"
621621
<> softline
622622
<> indent 2 (pretty destinationDirectory)
623623
<> hardline
624-
<> text "useCopyOnWrite:"
624+
<> "useCopyOnWrite:"
625625
<+> pretty useCopyOnWrite
626626

627627
completeCopyDirectory
@@ -847,14 +847,14 @@ data Resources = Resources
847847

848848
instance Pretty Resources where
849849
pretty Resources {..}
850-
= text "resourcePlan:"
850+
= "resourcePlan:"
851851
<> softline
852852
<> indent 2 (pretty resourcesPlan)
853853
<> hardline
854-
<> text "resourcesSocket:"
854+
<> "resourcesSocket:"
855855
<+> pretty resourcesSocketDirectory
856856
<> hardline
857-
<> text "resourcesDataDir:"
857+
<> "resourcesDataDir:"
858858
<+> pretty resourcesDataDir
859859

860860
-- | Make the 'resourcesDataDir' 'CPermanent' so it will not

0 commit comments

Comments
 (0)