Skip to content

Commit

Permalink
Replace PyF with string-interpolate (#4862)
Browse files Browse the repository at this point in the history
Replaced `PyF` with `string-interpolate` (#4862)
  • Loading branch information
zeme-wana committed Sep 24, 2022
1 parent 313116e commit 1a6de85
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 47 deletions.
8 changes: 4 additions & 4 deletions plutus-ledger-api/plutus-ledger-api.cabal
Expand Up @@ -114,15 +114,15 @@ library plutus-ledger-api-testlib
PlutusLedgerApi.Test.Scripts

build-depends:
, base >=4.9 && <5
, base >=4.9 && <5
, base64-bytestring
, bytestring
, plutus-core ^>=1.0
, plutus-core ^>=1.0
, plutus-ledger-api
, plutus-tx ^>=1.0
, plutus-tx ^>=1.0
, prettyprinter
, PyF
, serialise
, string-interpolate
, text

test-suite plutus-ledger-api-test
Expand Down
19 changes: 9 additions & 10 deletions plutus-ledger-api/testlib/PlutusLedgerApi/Test/EvaluationEvent.hs
Expand Up @@ -27,10 +27,11 @@ import Codec.Serialise (Serialise (..))
import Data.ByteString.Base64 qualified as Base64
import Data.ByteString.Short qualified as BS
import Data.List.NonEmpty (NonEmpty, toList)
import Data.String.Interpolate (__i)
import Data.Text.Encoding qualified as Text
import GHC.Generics (Generic)
import Prettyprinter
import PyF (fmt)


data ScriptEvaluationResult = ScriptEvaluationSuccess | ScriptEvaluationFailure
deriving stock (Show, Generic)
Expand Down Expand Up @@ -143,17 +144,15 @@ data TestFailure
renderTestFailure :: TestFailure -> String
renderTestFailure = \case
InvalidResult err -> display err
MissingCostParametersFor ver ->
[fmt|
Missing cost parameters for {show ver}. Report this as a bug
against the script dumper in plutus-apps."
|]
MissingCostParametersFor ver -> [__i|
Missing cost parameters for #{show ver}.
Report this as a bug against the script dumper in plutus-apps.
|]

renderTestFailures :: NonEmpty TestFailure -> String
renderTestFailures xs =
[fmt|
Number of failed test cases: {length xs}
{unlines . fmap renderTestFailure $ toList xs}
renderTestFailures xs = [__i|
Number of failed test cases: #{length xs}
#{unlines . fmap renderTestFailure $ toList xs}
|]

-- | Re-evaluate an on-chain script evaluation event.
Expand Down
27 changes: 13 additions & 14 deletions plutus-tx-plugin/app/GeneratePluginOptionsDoc.hs
Expand Up @@ -9,12 +9,13 @@ import PlutusTx.Options qualified as O

import Control.Lens
import Data.Map qualified as Map
import Data.String.Interpolate (__i)
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Text.IO qualified as Text
import Options.Applicative qualified as OA
import Prettyprinter
import PyF (fmt)


newtype Params = Params
{paramOutputFile :: Text}
Expand All @@ -39,8 +40,7 @@ main = do
Text.writeFile (Text.unpack $ paramOutputFile params) optionsTable

optionsTable :: Text
optionsTable =
[fmt|
optionsTable = [__i|
..
This file is generated by running plutus-tx-plugin:gen-plugin-opts-doc.
Do not modify by hand.
Expand All @@ -53,17 +53,16 @@ optionsTable =
- Value Type
- Default
- Description
{Text.unlines $ uncurry genRow <$> Map.toList O.pluginOptions}

#{Text.unlines $ uncurry genRow <$> Map.toList O.pluginOptions}
|]

genRow :: O.OptionKey -> O.PluginOption -> Text
genRow k (O.PluginOption tr _ field desc) =
[fmt|
* - ``{k}``
- {valueType}
- {show (pretty defaultValue)}
- {desc}
|]
where
valueType = show tr
defaultValue = O.defaultPluginOptions ^. field
genRow k (O.PluginOption tr _ field desc) = [__i|
* - ``#{k}``
- #{show tr}
- #{show (pretty defaultValue)}
- #{desc}
|]
where
defaultValue = O.defaultPluginOptions ^. field
12 changes: 5 additions & 7 deletions plutus-tx-plugin/plutus-tx-plugin.cabal
Expand Up @@ -68,11 +68,9 @@ library
PlutusTx.PIRTypes
PlutusTx.PLCTypes

-- this comment should be by the dep, but cabal-fmt moves it :(
-- Newer PyF is mysteriously broken, hence the bound: https://github.com/guibou/PyF/issues/111
build-depends:
, array
, base >=4.9 && <5
, base >=4.9 && <5
, bytestring
, containers
, either
Expand All @@ -81,10 +79,10 @@ library
, ghc-prim
, lens
, mtl
, plutus-core ^>=1.0
, plutus-tx ^>=1.0
, plutus-core ^>=1.0
, plutus-tx ^>=1.0
, prettyprinter
, PyF <0.11
, string-interpolate
, template-haskell
, text
, transformers
Expand All @@ -109,7 +107,7 @@ executable gen-plugin-opts-doc
, optparse-applicative
, plutus-tx-plugin
, prettyprinter
, PyF
, string-interpolate
, text

default-language: Haskell2010
Expand Down
23 changes: 11 additions & 12 deletions plutus-tx-plugin/src/PlutusTx/Options.hs
Expand Up @@ -23,12 +23,13 @@ import Data.List.NonEmpty (NonEmpty)
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Proxy
import Data.String.Interpolate (__i)
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Type.Equality
import GhcPlugins qualified as GHC
import Prettyprinter
import PyF (fmt)

import Text.Read (readMaybe)
import Type.Reflection

Expand Down Expand Up @@ -88,27 +89,25 @@ newtype ParseErrors = ParseErrors (NonEmpty ParseError)
deriving newtype (Semigroup)

instance Show ParseErrors where
show (ParseErrors errs) =
[fmt|PlutusTx.Plugin: failed to parse options:
{Text.intercalate "\n" (fmap renderParseError (toList errs))}|]
show (ParseErrors errs) = [__i|
PlutusTx.Plugin: failed to parse options:
#{Text.intercalate "\n" (fmap renderParseError (toList errs))}
|]

instance Exception ParseErrors

renderParseError :: ParseError -> Text
renderParseError = \case
CannotParseValue k v tr ->
[fmt|Cannot parse value {v} for option {k} into type {show tr}.|]
[__i|Cannot parse value #{v} for option #{k} into type #{show tr}.|]
UnexpectedValue k v ->
[fmt|Option {k} is a flag and does not take a value, but was given {v}.|]
[__i|Option #{k} is a flag and does not take a value, but was given #{v}.|]
MissingValue k ->
[fmt|Option {k} needs a value.|]
[__i|Option #{k} needs a value.|]
UnrecognisedOption k suggs ->
[fmt|Unrecgonised option: {k}.|] <> case suggs of
[__i|Unrecognised option: #{k}.|] <> case suggs of
[] -> ""
_ ->
[fmt|
Did you mean one of:
{Text.intercalate "\n" suggs}|]
_ -> [__i|\nDid you mean one of:\n#{Text.intercalate "\n" suggs}|]

{- | Definition of plugin options.
Expand Down

0 comments on commit 1a6de85

Please sign in to comment.