<commit_before>{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Mafia.Cabal.Version
  ( getCabalVersion
  , checkCabalVersion
  ) where

import           Control.Monad.IO.Class (liftIO)

import           Data.Text (Text)
import qualified Data.Text as T

import           Mafia.Cabal.Process
import           Mafia.Cabal.Types
import           Mafia.Package
import           Mafia.Process

import           P

import           System.IO (IO)

import           X.Control.Monad.Trans.Either (EitherT, left, runEitherT)


getCabalVersion :: EitherT CabalError IO Version
getCabalVersion = do
  result <- liftIO . runEitherT $ cabal "--version" []
  case result of
    Left  _         -> left CabalNotInstalled
    Right (Out out) ->
      case parseCabalVersion out of
        Nothing  -> left (CabalCouldNotParseVersion out)
        Just ver -> return ver

parseCabalVersion :: Text -> Maybe Version
parseCabalVersion out =
  case T.words out of
    ("cabal-install" : "version" : version : _) -> parseVersion version
    _                                           -> Nothing

-- TODO not sure if maybe we should have no upper bounds here?
-- TODO maybe mafia should just install its own cabal?
checkCabalVersion :: EitherT CabalError IO ()
checkCabalVersion = do
  -- We need at least cabal-install-1.22.4 for the "cabal install --dry-run -v2" in
  -- Mafia.Cabal.Dependencies to get the right output.
  --
  -- It's this commit that we need:
  --   https://github.com/haskell/cabal/commit/c0b3c7f1b6ae7bb7663a2c18578ede95d6a40919

  let vmin = Version [1,22,4] []
      vmax = Version [1,23]   []

  version <- getCabalVersion

  case version >= vmin && version < vmax of
    False -> left (CabalInvalidVersion version vmin vmax)
    True  -> return ()<commit_msg>Allow mafia to be used with the development version (1.23.*) of cabal<commit_after>{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Mafia.Cabal.Version
  ( getCabalVersion
  , checkCabalVersion
  ) where

import           Control.Monad.IO.Class (liftIO)

import           Data.Text (Text)
import qualified Data.Text as T

import           Mafia.Cabal.Process
import           Mafia.Cabal.Types
import           Mafia.Package
import           Mafia.Process

import           P

import           System.IO (IO)

import           X.Control.Monad.Trans.Either (EitherT, left, runEitherT)


getCabalVersion :: EitherT CabalError IO Version
getCabalVersion = do
  result <- liftIO . runEitherT $ cabal "--version" []
  case result of
    Left  _         -> left CabalNotInstalled
    Right (Out out) ->
      case parseCabalVersion out of
        Nothing  -> left (CabalCouldNotParseVersion out)
        Just ver -> return ver

parseCabalVersion :: Text -> Maybe Version
parseCabalVersion out =
  case T.words out of
    ("cabal-install" : "version" : version : _) -> parseVersion version
    _                                           -> Nothing

-- TODO not sure if maybe we should have no upper bounds here?
-- TODO maybe mafia should just install its own cabal?
checkCabalVersion :: EitherT CabalError IO ()
checkCabalVersion = do
  -- We need at least cabal-install-1.22.4 for the "cabal install --dry-run -v2" in
  -- Mafia.Cabal.Dependencies to get the right output.
  --
  -- It's this commit that we need:
  --   https://github.com/haskell/cabal/commit/c0b3c7f1b6ae7bb7663a2c18578ede95d6a40919

  let vmin = Version [1,22,4] []
      vmax = Version [1,24]   []

  version <- getCabalVersion

  case version >= vmin && version < vmax of
    False -> left (CabalInvalidVersion version vmin vmax)
    True  -> return ()
{'fraction_non_alphanumeric': 0.0928030303030303, 'fraction_numerical': 0.020292207792207792, 'mean_word_length': 2.4681050656660415, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7456726', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1176, 'n_words': 341}