Skip to content

Commit

Permalink
Consistent imports for NonEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Oct 21, 2023
1 parent dee421d commit 3695ff5
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/Stack/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ module Stack.Build
import Data.Attoparsec.Args ( EscapingMode (Escaping), parseArgs )
import Data.List ( (\\) )
import Data.List.Extra ( groupSort )
import qualified Data.List.NonEmpty as NE
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Distribution.PackageDescription as C
import Distribution.Types.Dependency ( Dependency (..), depLibraries )
import Distribution.Version ( mkVersion )
import RIO.NonEmpty ( nonEmpty )
import qualified RIO.NonEmpty as NE
import Stack.Build.ConstructPlan ( constructPlan )
import Stack.Build.Execute ( executePlan, preFetch, printPlan )
import Stack.Build.Installed ( getInstalled, toInstallMap )
Expand Down Expand Up @@ -291,7 +292,7 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do
, exe <- Set.toList (packageExes pkg)
]
collect :: Ord k => [(k, v)] -> Map k (NonEmpty v)
collect = Map.mapMaybe NE.nonEmpty . Map.fromDistinctAscList . groupSort
collect = Map.mapMaybe nonEmpty . Map.fromDistinctAscList . groupSort

warnAboutSplitObjs :: HasTerm env => BuildOpts -> RIO env ()
warnAboutSplitObjs bopts | boptsSplitObjs bopts =
Expand Down
6 changes: 3 additions & 3 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import qualified Data.Conduit.List as CL
import Data.Conduit.Process.Typed ( createSource )
import qualified Data.Conduit.Text as CT
import qualified Data.List as L
import Data.List.NonEmpty ( nonEmpty )
import qualified Data.List.NonEmpty as NonEmpty
import Data.List.Split ( chunksOf )
import qualified Data.Map.Merge.Strict as Map
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -81,6 +79,8 @@ import Path.IO
, ignoringAbsence, removeDirRecur, removeFile, renameDir
, renameFile
)
import RIO.NonEmpty ( nonEmpty )
import qualified RIO.NonEmpty as NE
import RIO.Process
( HasProcessContext, byteStringInput, eceExitCode
, findExecutable, getStderr, getStdout, inherit
Expand Down Expand Up @@ -922,7 +922,7 @@ unregisterPackages cv localDB ids = do
let batchSize = case platform of
Platform _ Windows -> 100
_ -> 500
let chunksOfNE size = mapMaybe nonEmpty . chunksOf size . NonEmpty.toList
let chunksOfNE size = mapMaybe nonEmpty . chunksOf size . NE.toList
for_ (chunksOfNE batchSize ids) $ \batch -> do
for_ batch $ \(_, (ident, reason)) -> logReason ident reason
pkg <- getGhcPkgExe
Expand Down
8 changes: 4 additions & 4 deletions src/Stack/BuildPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module Stack.BuildPlan

import qualified Data.Foldable as F
import Data.List (intercalate)
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
Expand All @@ -34,6 +33,7 @@ import Distribution.Text ( display )
import Distribution.Types.UnqualComponentName
( unUnqualComponentName )
import qualified Distribution.Version as C
import qualified RIO.NonEmpty as NE
import Stack.Constants ( wiredInPackages )
import Stack.Package
( PackageConfig (..), packageDependencies
Expand Down Expand Up @@ -221,7 +221,7 @@ selectPackageBuildPlan ::
-> GenericPackageDescription
-> (Map PackageName (Map FlagName Bool), DepErrors)
selectPackageBuildPlan platform compiler pool gpd =
(selectPlan . limitSearchSpace . NonEmpty.map makePlan) flagCombinations
(selectPlan . limitSearchSpace . NE.map makePlan) flagCombinations
where
selectPlan :: NonEmpty (a, DepErrors) -> (a, DepErrors)
selectPlan = F.foldr1 fewerErrors
Expand Down Expand Up @@ -410,11 +410,11 @@ selectBestSnapshot pkgDirs snaps = do
prettyInfo $
fillSep
[ flow "Selecting the best among"
, fromString $ show (NonEmpty.length snaps)
, fromString $ show (NE.length snaps)
, "snapshots..."
]
<> line
F.foldr1 go (NonEmpty.map (getResult <=< snapshotLocation) snaps)
F.foldr1 go (NE.map (getResult <=< snapshotLocation) snaps)
where
go mold mnew = do
old@(_snap, _loc, bpc) <- mold
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import Options.Applicative.Builder.Extra
( boolFlags, extraHelpOption, textOption )
import Options.Applicative.Complicated
( addCommand, addSubCommands, complicatedOptions )
import qualified RIO.NonEmpty as NE
import RIO.NonEmpty ( (<|) )
import qualified RIO.NonEmpty as NE
import qualified RIO.Process ( exec )
import RIO.Process ( withProcessContextNoLogging )
import Stack.Build ( buildCmd )
Expand Down
7 changes: 4 additions & 3 deletions src/Stack/ConfigCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Data.Attoparsec.Text as P
, takeWhile
)
import qualified Data.Map.Merge.Strict as Map
import qualified Data.List.NonEmpty as NE
import qualified Data.Text as T
import qualified Data.Yaml as Yaml
import qualified Options.Applicative as OA
Expand All @@ -31,6 +30,8 @@ import qualified Options.Applicative.Types as OA
import Pantry ( loadSnapshot )
import Path ( (</>), parent )
import qualified RIO.Map as Map
import RIO.NonEmpty ( nonEmpty )
import qualified RIO.NonEmpty as NE
import RIO.Process ( envVarsL )
import Stack.Config
( makeConcreteResolver, getProjectConfig
Expand Down Expand Up @@ -131,7 +132,7 @@ cfgCmdSet cmd = do
-- key3: value
--
writeLines yamlLines spaces cmdKeys value =
case NE.nonEmpty $ NE.tail cmdKeys of
case nonEmpty $ NE.tail cmdKeys of
Nothing -> yamlLines <> [spaces <> NE.head cmdKeys <> ": " <> value]
Just ks -> writeLines
(yamlLines <> [spaces <> NE.head cmdKeys <> ":"])
Expand All @@ -143,7 +144,7 @@ cfgCmdSet cmd = do
Yaml.Object obj ->
case KeyMap.lookup (Key.fromText (NE.head cmdKeys)) obj of
Nothing -> Nothing
Just v' -> case NE.nonEmpty $ NE.tail cmdKeys of
Just v' -> case nonEmpty $ NE.tail cmdKeys of
Nothing -> Just v'
Just ks -> inConfig v' ks
_ -> Nothing
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import qualified Data.ByteString.Char8 as S8
import qualified Data.ByteString.Lazy as LBS
import qualified Data.List as L
import Data.List.Extra ( (!?) )
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import qualified Data.Text as T
Expand All @@ -29,6 +28,7 @@ import Path ((</>), parent, parseRelFile )
import Path.Extra ( forgivingResolveFile', toFilePathNoTrailingSep )
import Path.IO
( XdgDirectory (..), doesFileExist, ensureDir, getXdgDir )
import RIO.NonEmpty ( nonEmpty )
import RIO.Process
( HasProcessContext, exec, proc, readProcess_
, withWorkingDir
Expand Down Expand Up @@ -462,7 +462,7 @@ buildDepsAndInitialSteps GhciOpts{..} localTargets = do
let targets = localTargets ++ map T.pack ghciAdditionalPackages
-- If necessary, do the build, for local packagee targets, only do
-- 'initialBuildSteps'.
case NE.nonEmpty targets of
case nonEmpty targets of
-- only new local targets could appear here
Just nonEmptyTargets | not ghciNoBuild -> do
eres <- buildLocalTargets nonEmptyTargets
Expand Down
12 changes: 6 additions & 6 deletions src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import qualified Data.ByteString.Char8 as BC
import qualified Data.Foldable as F
import qualified Data.IntMap as IntMap
import Data.List.Extra ( groupSortOn )
import Data.List.NonEmpty ( nonEmpty )
import qualified Data.List.NonEmpty as NonEmpty
import Data.List.NonEmpty.Extra ( minimumBy1 )
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
Expand All @@ -37,6 +35,8 @@ import Path.IO
)
import qualified RIO.FilePath as FP
import RIO.List ( (\\), intercalate, isSuffixOf, isPrefixOf )
import RIO.NonEmpty ( nonEmpty )
import qualified RIO.NonEmpty as NE
import Stack.BuildPlan
( BuildPlanCheck (..), checkSnapBuildPlan, deNeededBy
, removeSrcPkgDefaultFlags, selectBestSnapshot
Expand Down Expand Up @@ -138,7 +138,7 @@ instance Pretty InitPrettyException where
<> flow "None of the following snapshots provides a compiler matching \
\your package(s):"
<> line
<> bulletedList (map (fromString . show) (NonEmpty.toList names))
<> bulletedList (map (fromString . show) (NE.toList names))
<> blankLine
<> resolveOptions
pretty (ResolverMismatch resolver errDesc) =
Expand Down Expand Up @@ -624,7 +624,7 @@ checkBundleResolver initOpts snapshotLoc snapCandidate pkgDirs = do
getRecommendedSnapshots :: Snapshots -> NonEmpty SnapName
getRecommendedSnapshots snapshots =
-- in order - Latest LTS, Latest Nightly, all LTS most recent first
case NonEmpty.nonEmpty supportedLtss of
case nonEmpty supportedLtss of
Just (mostRecent :| older) -> mostRecent :| (nightly : older)
Nothing -> nightly :| []
where
Expand Down Expand Up @@ -704,7 +704,7 @@ cabalPackagesCheck cabaldirs = do
when (nameMismatchPkgs /= []) $
prettyThrowIO $ PackageNameInvalid nameMismatchPkgs
let dupGroups = mapMaybe nonEmpty . groupSortOn (gpdPackageName . snd)
dupAll = concatMap NonEmpty.toList $ dupGroups packages
dupAll = concatMap NE.toList $ dupGroups packages
-- Among duplicates prefer to include the ones in upper level dirs
pathlen = length . FP.splitPath . toFilePath . fst
getmin = minimumBy1 (compare `on` pathlen)
Expand All @@ -717,7 +717,7 @@ cabalPackagesCheck cabaldirs = do
flow "The following packages have duplicate package names:"
<> line
<> foldMap
( \dup -> bulletedList (map fromString (NonEmpty.toList dup))
( \dup -> bulletedList (map fromString (NE.toList dup))
<> line
)
dups
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Lock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import Data.Aeson.WarningParser
, jsonSubWarningsT, logJSONWarnings, withObjectWarnings
)
import Data.ByteString.Builder ( byteString )
import qualified Data.List.NonEmpty as NE
import qualified Data.Map as Map
import qualified Data.Text as T
import qualified Data.Yaml as Yaml
import qualified RIO.NonEmpty as NE
import Path ( parent )
import Path.Extended ( addExtension )
import Path.IO ( doesFileExist )
Expand Down
7 changes: 4 additions & 3 deletions src/Stack/SDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import qualified Data.ByteString.Lazy as L
import Data.Char ( toLower )
import Data.Data ( cast )
import qualified Data.List as List
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified Data.Text as T
Expand All @@ -45,6 +44,8 @@ import Distribution.Version
)
import Path ( (</>), parent, parseRelDir, parseRelFile )
import Path.IO ( ensureDir, resolveDir' )
import RIO.NonEmpty ( nonEmpty )
import qualified RIO.NonEmpty as NE
import Stack.Build ( mkBaseConfigOpts, build, buildLocalTargets )
import Stack.Build.Execute
( ExcludeTHLoading (..), KeepOutputOpen (..), withExecuteEnv
Expand Down Expand Up @@ -209,7 +210,7 @@ getSDistTarball mpvpBounds pkgDir = do
pkgFp = toFilePath pkgDir
lp <- readLocalPackage pkgDir
forM_ (packageSetupDeps (lpPackage lp)) $ \customSetupDeps ->
case NE.nonEmpty (map (T.pack . packageNameString) (Map.keys customSetupDeps)) of
case nonEmpty (map (T.pack . packageNameString) (Map.keys customSetupDeps)) of
Just nonEmptyDepTargets -> do
eres <- buildLocalTargets nonEmptyDepTargets
case eres of
Expand Down Expand Up @@ -614,7 +615,7 @@ checkPackageInExtractedTarball pkgDir = do
flow "Package check reported the following warnings:"
<> line
<> bulletedList (map (fromString . show) warnings)
case NE.nonEmpty errors of
case nonEmpty errors of
Nothing -> pure ()
Just ne -> prettyThrowM $ CheckException ne

Expand Down

0 comments on commit 3695ff5

Please sign in to comment.