<commit_before>{-# LANGUAGE DataKinds     #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Main where

import Control.Exception (finally)
import Data.Monoid       ((<>))

import Data.Acid                            (closeAcidState, createCheckpoint,
                                             openLocalState, update)
import Network.HTTP.Client                  (newManager)
import Network.HTTP.Client.TLS              (tlsManagerSettings)
import Network.Wai                          (Application)
import Network.Wai.Handler.Warp             (run)
import Network.Wai.Middleware.Cors          (CorsResourcePolicy (..), cors,
                                             simpleCorsResourcePolicy,
                                             simpleHeaders, simpleMethods)
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Servant

import           Inspection.API
import           Inspection.API.Types
import           Inspection.BuildMatrix
import qualified Inspection.Config      as Config
import           Inspection.Database
import           Inspection.Flags

newEnvironment :: IO Environment
newEnvironment = Environment <$> openLocalState initialDB
                             <*> newManager tlsManagerSettings
                             <*> getEnvironmentFlags
                             <*> Config.getConfig "inspection.yaml"

main :: IO ()
main = do
  env <- newEnvironment
  finally<commit_msg>Avoid locking database when failed to start main<commit_after>{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DataKinds     #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Main where

import Control.Exception (finally)
import Data.Monoid       ((<>))

import Data.Acid                            (closeAcidState, createCheckpoint,
                                             openLocalState, update)
import Network.HTTP.Client                  (newManager)
import Network.HTTP.Client.TLS              (tlsManagerSettings)
import Network.Wai                          (Application)
import Network.Wai.Handler.Warp             (run)
import Network.Wai.Middleware.Cors          (CorsResourcePolicy (..), cors,
                                             simpleCorsResourcePolicy,
                                             simpleHeaders, simpleMethods)
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Servant

import           Inspection.API
import           Inspection.API.Types
import           Inspection.BuildMatrix
import qualified Inspection.Config      as Config
import           Inspection.Database
import           Inspection.Flags

newEnvironment :: IO Environment
newEnvironment = do
  envFlags   <- getEnvironmentFlags
  envConfig  <- Config.getConfig "inspection.yaml"
  envManager <- newManager tlsManagerSettings
  envAcid    <- openLocalState initialDB
  pure Environment{..}

main :: IO ()
main = do
  env <- newEnvironment
  finally
{'fraction_non_alphanumeric': 0.0733446519524618, 'fraction_numerical': 0.0, 'mean_word_length': 1.902463054187192, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '166223', 'n_tokens_mistral': 706, 'n_tokens_neox': 711, 'n_words': 172}