Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into 479-mismatch-of-names-of-t…
Browse files Browse the repository at this point in the history
…he-binary-and-package
  • Loading branch information
deemp committed Oct 25, 2024
2 parents c26df71 + a3b06f2 commit 116842c
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ghc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: "20.18.0"
cache: npm

- uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: 21
java-version: 21.0.5+11

# TODO #340:10m switch to chrisdickinson/setup-yq after https://github.com/chrisdickinson/setup-yq/pull/14 is merged
- uses: deemp/setup-yq@latest
Expand Down
27 changes: 27 additions & 0 deletions eo-phi-normalizer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to the
[Haskell Package Versioning Policy](https://pvp.haskell.org/).

## v1.1.0 - 2024-10-03

### New

- Add unit tests [#461](https://github.com/objectionary/normalizer/pull/461)
- Add `R_DOT_ρ` [#468](https://github.com/objectionary/normalizer/pull/468)
- Support printing rules in LaTeX [#474](https://github.com/objectionary/normalizer/pull/474)
- Automatically create an output directory [#499](https://github.com/objectionary/normalizer/pull/499)

### Changes and fixes

- Update the `COPY` rule as in phi-paper [#445](https://github.com/objectionary/normalizer/pull/445)
- Remove special case for delta binding since VTX is removed [#356](https://github.com/objectionary/normalizer/pull/356)
- Replace `normalizer report` command with the `normalizer pipeline report` command [#456](https://github.com/objectionary/normalizer/pull/456)
- Fix sorting in numeric columns [#460](https://github.com/objectionary/normalizer/pull/460)
- Run mdbook in the pipeline job [#463](https://github.com/objectionary/normalizer/pull/463)

### Documentation and maintenance

- Document all dependencies in a single doc in `eo/phi/normalizer/data` for each eo version [#446](https://github.com/objectionary/normalizer/pull/446).
- Create a metrics page on the site [#453](https://github.com/objectionary/normalizer/pull/453)
- Chore(deps): update dependency pre-commit to v3.8.0 [#455](https://github.com/objectionary/normalizer/pull/455)
- Provide instructions for the customer to check that we've completed the contract requirements [#458](https://github.com/objectionary/normalizer/pull/458)
- Bump stack action version [#459](https://github.com/objectionary/normalizer/pull/459)
- Update proposal process [#464](https://github.com/objectionary/normalizer/pull/464)
- Document creating custom atoms on the site [#467](https://github.com/objectionary/normalizer/pull/467)

## v1.0.0 - 2024-07-19

### New
Expand Down
33 changes: 28 additions & 5 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Data.List (intercalate, isPrefixOf)
import Data.Maybe (fromMaybe)
import Data.Text.Internal.Builder (toLazyText)
import Data.Text.Lazy as TL (unpack)
import Data.Version (showVersion)
import Data.Yaml (decodeFileThrow)
import GHC.Generics (Generic)
import Language.EO.Phi (Binding (..), Bytes (Bytes), Object (..), Program (Program), parseProgram, printTree)
Expand All @@ -56,13 +57,16 @@ import Language.EO.Phi.Rules.Fast (fastYegorInsideOut, fastYegorInsideOutAsRule)
import Language.EO.Phi.Rules.RunYegor (yegorRuleSet)
import Language.EO.Phi.Rules.Yaml (RuleSet (rules, title), convertRuleNamed, parseRuleSetFromFile)
import Language.EO.Phi.ToLaTeX
import Language.EO.Test.YamlSpec (spec)
import Main.Utf8
import Options.Applicative hiding (metavar)
import Options.Applicative qualified as Optparse (metavar)
import Paths_eo_phi_normalizer (version)
import PyF (fmt, fmtTrim)
import System.Directory (createDirectoryIfMissing, doesFileExist)
import System.FilePath (takeDirectory)
import System.IO (IOMode (WriteMode), getContents', hFlush, hPutStr, hPutStrLn, openFile, stdout)
import Test.Hspec.Core.Runner

data CLI'TransformPhi = CLI'TransformPhi
{ chain :: Bool
Expand Down Expand Up @@ -131,12 +135,16 @@ data CLI'Pipeline
| CLI'Pipeline'PrintDataizeConfigs' CLI'Pipeline'PrintDataizeConfigs
deriving stock (Show)

newtype CLI'Test = CLI'Test {rulePaths :: [FilePath]}
deriving stock (Show)

data CLI
= CLI'TransformPhi' CLI'TransformPhi
| CLI'DataizePhi' CLI'DataizePhi
| CLI'MetricsPhi' CLI'MetricsPhi
| CLI'PrintRules' CLI'PrintRules
| CLI'Pipeline' CLI'Pipeline
| CLI'Test' CLI'Test
deriving stock (Show)

data MetavarName = MetavarName
Expand Down Expand Up @@ -236,6 +244,7 @@ data CommandParser = CommandParser
, pipeline :: Parser CLI'Pipeline
, pipeline' :: CommandParser'Pipeline
, printRules :: Parser CLI'PrintRules
, test :: Parser CLI'Test
}

commandParser :: CommandParser
Expand Down Expand Up @@ -302,6 +311,9 @@ commandParser =
<> command commandNames.pipeline'.prepareTests commandParserInfo.pipeline'.prepareTests
<> command commandNames.pipeline'.printDataizeConfigs commandParserInfo.pipeline'.printDataizeConfigs
)
test = do
rulePaths <- many $ strOption (long "rules" <> short 'r' <> metavar.file <> help [fmt|{metavarName.file} with user-defined rules.|])
pure CLI'Test{..}

data CommandParserInfo'Pipeline = CommandParserInfo'Pipeline
{ report :: ParserInfo CLI'Pipeline
Expand All @@ -316,6 +328,7 @@ data CommandParserInfo = CommandParserInfo
, printRules :: ParserInfo CLI
, pipeline :: ParserInfo CLI
, pipeline' :: CommandParserInfo'Pipeline
, test :: ParserInfo CLI
}

commandParserInfo :: CommandParserInfo
Expand All @@ -332,6 +345,7 @@ commandParserInfo =
, prepareTests = info (CLI'Pipeline'PrepareTests' <$> commandParser.pipeline'.prepareTests) (progDesc "Prepare EO test files for the pipeline.")
, printDataizeConfigs = info (CLI'Pipeline'PrintDataizeConfigs' <$> commandParser.pipeline'.printDataizeConfigs) (progDesc [fmt|Print configs for the `{commandNames.dataize}` command.|])
}
, test = info (CLI'Test' <$> commandParser.test) (progDesc "Run unit tests in given files with user-defined rules.")
}

data CommandNames'Pipeline = CommandNames'Pipeline
Expand All @@ -347,6 +361,7 @@ data CommandNames = CommandNames
, printRules :: String
, pipeline :: String
, pipeline' :: CommandNames'Pipeline
, test :: String
}

commandNames :: CommandNames
Expand All @@ -363,6 +378,7 @@ commandNames =
, prepareTests = "prepare-tests"
, printDataizeConfigs = "print-dataize-configs"
}
, test = "test"
}

cli :: Parser CLI
Expand All @@ -373,12 +389,13 @@ cli =
<> command commandNames.dataize commandParserInfo.dataize
<> command commandNames.pipeline commandParserInfo.pipeline
<> command commandNames.printRules commandParserInfo.printRules
<> command commandNames.test commandParserInfo.test
)

cliOpts :: ParserInfo CLI
cliOpts =
cliOpts :: String -> ParserInfo CLI
cliOpts version' =
info
(cli <**> helper)
(cli <**> helper <**> simpleVersioner version')
(fullDesc <> progDesc "Work with PHI expressions.")

data StructuredJSON = StructuredJSON
Expand Down Expand Up @@ -435,7 +452,7 @@ getProgram inputFile = do

getLoggers :: Maybe FilePath -> IO (String -> IO (), String -> IO ())
getLoggers outputFile = do
handle <- maybe (pure stdout) (`openFile` WriteMode) outputFile
handle <- maybe (pure stdout) (\file -> createDirectoryIfMissing True (takeDirectory file) >> openFile file WriteMode) outputFile
pure
( \x -> hPutStrLn handle x >> hFlush handle
, \x -> hPutStr handle x >> hFlush handle
Expand Down Expand Up @@ -520,7 +537,7 @@ wrapRawBytesIn = \case

main :: IO ()
main = withUtf8 do
opts <- customExecParser pprefs cliOpts
opts <- customExecParser pprefs (cliOpts (showVersion version))
let printAsProgramOrAsObject = \case
Formation bindings' -> printTree $ Program bindings'
x -> printTree x
Expand Down Expand Up @@ -693,3 +710,9 @@ main = withUtf8 do
CLI'Pipeline' (CLI'Pipeline'PrintDataizeConfigs' CLI'Pipeline'PrintDataizeConfigs{..}) -> do
config <- decodeFileThrow @_ @PipelineConfig configFile
PrintConfigs.printDataizeConfigs config phiPrefixesToStrip singleLine
CLI'Test' (CLI'Test{..}) ->
evalSpec defaultConfig (spec rulePaths)
>>= \(config, spec') ->
readConfig config []
>>= runSpecForest spec'
>>= evaluateResult
16 changes: 13 additions & 3 deletions eo-phi-normalizer/eo-phi-normalizer.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cabal-version: 1.24

-- This file has been generated from package.yaml by hpack version 0.36.0.
-- This file has been generated from package.yaml by hpack version 0.37.0.
--
-- see: https://github.com/sol/hpack

name: eo-phi-normalizer
version: 1.0.0
version: 1.1.0
synopsis: Command line normalizer of 𝜑-calculus expressions.
description: Please see the README on GitHub at <https://github.com/objectionary/eo-phi-normalizer#readme>
homepage: https://github.com/objectionary/eo-phi-normalizer#readme
Expand Down Expand Up @@ -167,6 +167,8 @@ library
Language.EO.Phi.Syntax.Print
Language.EO.Phi.TH
Language.EO.Phi.ToLaTeX
Language.EO.Test.Yaml
Language.EO.Test.YamlSpec
other-modules:
Paths_eo_phi_normalizer
hs-source-dirs:
Expand Down Expand Up @@ -194,6 +196,8 @@ library
, filepath
, generic-lens
, hashable
, hspec
, hspec-core
, lens
, mtl
, regex-compat
Expand Down Expand Up @@ -235,6 +239,8 @@ executable eo-phi-normalizer
, filepath
, generic-lens
, hashable
, hspec
, hspec-core
, lens
, mtl
, optparse-applicative
Expand Down Expand Up @@ -278,6 +284,8 @@ test-suite doctests
Language.EO.Phi.Syntax.Skel
Language.EO.Phi.TH
Language.EO.Phi.ToLaTeX
Language.EO.Test.Yaml
Language.EO.Test.YamlSpec
Paths_eo_phi_normalizer
hs-source-dirs:
test/doctests
Expand Down Expand Up @@ -307,6 +315,8 @@ test-suite doctests
, filepath
, generic-lens
, hashable
, hspec
, hspec-core
, lens
, mtl
, regex-compat
Expand All @@ -327,7 +337,6 @@ test-suite spec
Language.EO.YamlSpec
Spec
Test.EO.Phi
Test.EO.Yaml
Test.Metrics.Phi
Paths_eo_phi_normalizer
hs-source-dirs:
Expand Down Expand Up @@ -358,6 +367,7 @@ test-suite spec
, generic-lens
, hashable
, hspec
, hspec-core
, hspec-discover
, lens
, mtl
Expand Down
4 changes: 3 additions & 1 deletion eo-phi-normalizer/package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: eo-phi-normalizer
synopsis: "Command line normalizer of 𝜑-calculus expressions."
version: 1.0.0
version: 1.1.0
github: "objectionary/eo-phi-normalizer"
license: BSD3
author: "EO/Polystat Development Team"
Expand Down Expand Up @@ -49,6 +49,8 @@ dependencies:
- PyF
- lens
- generic-lens
- hspec
- hspec-core
- text
- template-haskell
- blaze-html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.EO.Yaml where
module Language.EO.Test.Yaml where

import Control.Monad (forM)
import Data.List (sort)
Expand Down
26 changes: 26 additions & 0 deletions eo-phi-normalizer/src/Language/EO/Test/YamlSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE OverloadedRecordDot #-}

module Language.EO.Test.YamlSpec where

import Control.Monad (forM_)
import Language.EO.Phi.Dataize.Context (defaultContext)
import Language.EO.Phi.Rules.Common (applyOneRule)
import Language.EO.Phi.Rules.Yaml (Rule (..), RuleSet (..), RuleTest (..), RuleTestOption (..), convertRuleNamed)
import Language.EO.Test.Yaml
import Test.Hspec

spec :: [FilePath] -> Spec
spec testPaths = describe "User-defined rules unit tests" do
forM_ testPaths $ \path -> do
ruleset <- runIO $ fileTests path
describe ruleset.title do
forM_ ruleset.rules $ \rule -> do
describe rule.name do
forM_ rule.tests $ \ruleTest -> do
it ruleTest.name $
let rule' = convertRuleNamed rule
resultOneStep = applyOneRule (defaultContext [rule'] ruleTest.input) ruleTest.input
normalizationResult = maybe resultOneStep (\lst -> if TakeOne True `elem` lst then take 1 resultOneStep else resultOneStep) ruleTest.options
expected = ruleTest.output
in map snd normalizationResult `shouldBe` expected
26 changes: 4 additions & 22 deletions eo-phi-normalizer/test/Language/EO/YamlSpec.hs
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE OverloadedRecordDot #-}

module Language.EO.YamlSpec where

import Control.Monad (forM_)
import Language.EO.Phi.Dataize.Context (defaultContext)
import Language.EO.Phi.Rules.Common (applyOneRule)
import Language.EO.Phi.Rules.Yaml (Rule (..), RuleSet (..), RuleTest (..), RuleTestOption (..), convertRuleNamed)
import Test.EO.Yaml
import Test.Hspec
import Language.EO.Test.YamlSpec qualified as Test
import Test.Hspec (Spec)

spec :: Spec
spec = describe "User-defined rules unit tests" do
forM_ testPaths $ \path -> do
ruleset <- runIO $ fileTests path
describe ruleset.title do
forM_ ruleset.rules $ \rule -> do
describe rule.name do
forM_ rule.tests $ \ruleTest -> do
it ruleTest.name $
let rule' = convertRuleNamed rule
resultOneStep = applyOneRule (defaultContext [rule'] ruleTest.input) ruleTest.input
normalizationResult = maybe resultOneStep (\lst -> if TakeOne True `elem` lst then take 1 resultOneStep else resultOneStep) ruleTest.options
expected = ruleTest.output
in map snd normalizationResult `shouldBe` expected
where
testPaths =
spec =
Test.spec
[ "test/eo/phi/rules/yegor.yaml"
, "test/eo/phi/rules/streams.yaml"
]
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
"eo-phi-normalizer/metrics.md"
"eo-phi-normalizer/transform.md"
"eo-phi-normalizer/print-rules.md"
"eo-phi-normalizer/test.md"
"contributing.md"
]}
Expand Down
1 change: 1 addition & 0 deletions scripts/update-markdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mdsh -i site/docs/src/eo-phi-normalizer/dataize.md --work_dir .
mdsh -i site/docs/src/eo-phi-normalizer/metrics.md --work_dir .
mdsh -i site/docs/src/eo-phi-normalizer/transform.md --work_dir .
mdsh -i site/docs/src/eo-phi-normalizer/print-rules.md --work_dir .
mdsh -i site/docs/src/eo-phi-normalizer/test.md --work_dir .
mdsh -i site/docs/src/contributing.md --work_dir .

rm celsius.phi
Expand Down
1 change: 1 addition & 0 deletions site/docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
- [eo-phi-normalizer pipeline prepare-tests](./eo-phi-normalizer/pipeline/prepare-tests.md)
- [eo-phi-normalizer pipeline print-dataize-configs](./eo-phi-normalizer/pipeline/print-dataize-configs.md)
- [eo-phi-normalizer pipeline report](./eo-phi-normalizer/pipeline/report.md)
- [eo-phi-normalizer test](./eo-phi-normalizer/test.md)
- [eo-phi-normalizer print-rules](./eo-phi-normalizer/print-rules.md)
- [Contributing](./contributing.md)
Loading

0 comments on commit 116842c

Please sign in to comment.