<commit_before>{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE OverloadedStrings #-}
-- | The constraints on package selection for a new build plan.
module Stackage2.PackageConstraints
    ( PackageConstraints (..)
    , defaultPackageConstraints
    , defaultGlobalFlags
    , packageFlags
    , tryBuildTest
    , tryBuildBenchmark
    ) where

import           Stackage2.Prelude
import qualified Stackage.Config as Old
import qualified Stackage.Types  as Old
import qualified Stackage.Select as Old

-- FIXME have the defaults here live in IO to make sure we don't have any
-- global state floating around. Will make it easier to test.

data PackageConstraints = PackageConstraints
    { pcPackages :: Map PackageName (VersionRange, Maintainer)
    -- ^ This does not include core packages or dependencies, just packages
    -- added by some maintainer.
    , pcExpectedFailures :: Set PackageName
    -- ^ At some point in the future, we should split this into Haddock
    -- failures, test failures, etc.
    }

-- | The proposed plan from the requirements provided by contributors.
defaultPackageConstraints :: PackageConstraints
defaultPackageConstraints = PackageConstraints
    { pcPackages = fmap (Maintainer . pack . Old.unMaintainer)
               <$> Old.defaultStablePackages ghcVer False
    , pcExpectedFailures = Old.defaultExpectedFailures ghcVer False
    }

ghcVer :: Old.GhcMajorVersion
ghcVer = Old.GhcMajorVersion 7 8

oldSettings :: Old.SelectSettings
oldSettings = Old.defaultSelectSettings ghcVer False

defaultGlobalFlags :: Map FlagName Bool
defaultGlobalFlags = mapFromList $
    map (, True) (map FlagName $ setToList $ Old.flags oldSettings mempty) ++
    map (, False) (map FlagName $ setToList $ Old.disabledFlags oldSettings)

packageFlags :: PackageName -> Map FlagName Bool
packageFlags _ = mempty

tryBuildTest :: PackageName -> Bool
tryBuildTest = (`member` Old.skippedTests oldSettings)

tryBuildBenchmark :: PackageName -> Bool
tryBuildBenchmark _ = True<commit_msg>Fix some reversed logic<commit_after>{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE OverloadedStrings #-}
-- | The constraints on package selection for a new build plan.
module Stackage2.PackageConstraints
    ( PackageConstraints (..)
    , defaultPackageConstraints
    , defaultGlobalFlags
    , packageFlags
    , tryBuildTest
    , tryBuildBenchmark
    ) where

import           Stackage2.Prelude
import qualified Stackage.Config as Old
import qualified Stackage.Types  as Old
import qualified Stackage.Select as Old

-- FIXME have the defaults here live in IO to make sure we don't have any
-- global state floating around. Will make it easier to test.

data PackageConstraints = PackageConstraints
    { pcPackages :: Map PackageName (VersionRange, Maintainer)
    -- ^ This does not include core packages or dependencies, just packages
    -- added by some maintainer.
    , pcExpectedFailures :: Set PackageName
    -- ^ At some point in the future, we should split this into Haddock
    -- failures, test failures, etc.
    }

-- | The proposed plan from the requirements provided by contributors.
defaultPackageConstraints :: PackageConstraints
defaultPackageConstraints = PackageConstraints
    { pcPackages = fmap (Maintainer . pack . Old.unMaintainer)
               <$> Old.defaultStablePackages ghcVer False
    , pcExpectedFailures = Old.defaultExpectedFailures ghcVer False
    }

ghcVer :: Old.GhcMajorVersion
ghcVer = Old.GhcMajorVersion 7 8

oldSettings :: Old.SelectSettings
oldSettings = Old.defaultSelectSettings ghcVer False

defaultGlobalFlags :: Map FlagName Bool
defaultGlobalFlags = mapFromList $
    map (, True) (map FlagName $ setToList $ Old.flags oldSettings mempty) ++
    map (, False) (map FlagName $ setToList $ Old.disabledFlags oldSettings)

packageFlags :: PackageName -> Map FlagName Bool
packageFlags _ = mempty

tryBuildTest :: PackageName -> Bool
tryBuildTest = (`notMember` Old.skippedTests oldSettings)

tryBuildBenchmark :: PackageName -> Bool
tryBuildBenchmark _ = True
{'fraction_non_alphanumeric': 0.07287845438982636, 'fraction_numerical': 0.0019564685742235266, 'mean_word_length': 3.927710843373494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '497241', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1102, 'n_words': 374}