Skip to content

Commit 8c87389

Browse files
authored
Move out the Curator to its own repo (#586)
1 parent 2f3d948 commit 8c87389

File tree

14 files changed

+94
-822
lines changed

14 files changed

+94
-822
lines changed

Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

app/Curator.hs

Lines changed: 0 additions & 743 deletions
This file was deleted.

app/Spago.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import qualified Spago.Build
1919
import qualified Spago.Config as Config
2020
import Spago.Dhall (TemplateComments (..))
2121
import Spago.DryRun (DryRun (..))
22+
import Spago.Env
2223
import qualified Spago.GitHub
2324
import Spago.GlobalCache (CacheFlag (..), getGlobalCacheDir)
2425
import Spago.Messages as Messages

package.yaml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,36 +124,6 @@ executables:
124124
- text < 1.3
125125
- turtle
126126

127-
spago-curator:
128-
main: Curator.hs
129-
source-dirs: app
130-
other-modules: []
131-
ghc-options:
132-
- -main-is Curator
133-
- -threaded
134-
- -rtsopts
135-
- -with-rtsopts=-N
136-
dependencies:
137-
- aeson-pretty
138-
- async-pool
139-
- base >= 4.7 && < 5
140-
- bytestring
141-
- containers
142-
- dhall
143-
- filepath
144-
- github
145-
- lens-family-core
146-
- megaparsec
147-
- process
148-
- retry
149-
- spago
150-
- stm
151-
- temporary
152-
- text < 1.3
153-
- time
154-
- turtle
155-
- vector
156-
157127
tests:
158128
spec:
159129
defaults: hspec/hspec@master

src/Spago/Bower.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ mkDependencies config = do
143143
-- Windows sucks so lets make it slow for them!
144144
-- (just kidding, its a bug: https://github.com/bower/spec/issues/79)
145145
Windows -> pure 1
146-
_ -> askEnv envJobs
146+
_ -> view jobsL

src/Spago/Build.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ repl cacheFlag newPackages sourcePaths pursArgs depsOnly = do
189189
Purs.repl globs pursArgs
190190
Left (err :: SomeException) -> do
191191
logDebug $ display err
192-
cacheDir <- askEnv envGlobalCache
192+
cacheDir <- view globalCacheL
193193
Temp.withTempDirectory cacheDir "spago-repl-tmp" $ \dir -> do
194194
Turtle.cd (Turtle.decodeString dir)
195195

@@ -385,7 +385,7 @@ getOutputPath
385385
:: BuildOptions
386386
-> Spago (Maybe Sys.FilePath)
387387
getOutputPath buildOpts = do
388-
configPath <- askEnv envConfigPath
388+
configPath <- view configPathL
389389
outputPath <- PackageSet.findRootOutputPath (Text.unpack configPath)
390390
case findOutputFlag (pursArgs buildOpts) of
391391
Just path -> pure (Just path)

src/Spago/Config.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ parseConfig = do
127127
-- Here we try to migrate any config that is not in the latest format
128128
withConfigAST $ pure . addSourcePaths
129129

130-
path <- askEnv envConfigPath
130+
path <- view configPathL
131131
expr <- liftIO $ Dhall.inputExpr $ "./" <> path
132132
case expr of
133133
Dhall.RecordLit ks -> do
@@ -156,7 +156,7 @@ parseConfig = do
156156
-- | Checks that the Spago config is there and readable
157157
ensureConfig :: Spago (Either Utf8Builder Config)
158158
ensureConfig = do
159-
path <- askEnv envConfigPath
159+
path <- view configPathL
160160
exists <- testfile path
161161
if not exists
162162
then pure $ Left $ display Messages.cannotFindConfig
@@ -179,7 +179,7 @@ ensureConfigUnsafe = ensureConfig >>= \case
179179
-- Eventually ports an existing `psc-package.json` to the new config.
180180
makeConfig :: Bool -> Dhall.TemplateComments -> Spago ()
181181
makeConfig force comments = do
182-
path <- askEnv envConfigPath
182+
path <- view configPathL
183183
unless force $ do
184184
hasSpagoDhall <- testfile path
185185
when hasSpagoDhall $ die [ display $ Messages.foundExistingProject path ]
@@ -361,7 +361,7 @@ filterDependencies expr = expr
361361
-- still be in the tree). If you need the resolved one, use `ensureConfig`.
362362
withConfigAST :: (Expr -> Spago Expr) -> Spago Bool
363363
withConfigAST transform = do
364-
path <- askEnv envConfigPath
364+
path <- view configPathL
365365
rawConfig <- liftIO $ Dhall.readRawExpr path
366366
case rawConfig of
367367
Nothing -> die [ display $ Messages.cannotFindConfig ]

src/Spago/Env.hs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
module Spago.Env
2+
( Env(..)
3+
, HasEnv(..)
4+
, HasGlobalCache(..)
5+
, HasConfigPath(..)
6+
, HasJobs(..)
7+
, HasPsa(..)
8+
, UsePsa(..)
9+
) where
10+
11+
import RIO
12+
13+
import qualified GHC.IO
14+
15+
16+
-- | Flag to disable the automatic use of `psa`
17+
data UsePsa = UsePsa | NoPsa
18+
19+
-- | App configuration containing parameters and other common
20+
-- things it's useful to compute only once at startup.
21+
data Env = Env
22+
{ envUsePsa :: UsePsa
23+
, envJobs :: Int
24+
, envConfigPath :: Text
25+
, envGlobalCache :: GHC.IO.FilePath
26+
, envLogFunc :: !LogFunc
27+
}
28+
29+
30+
class HasGlobalCache env where
31+
globalCacheL :: Lens' env GHC.IO.FilePath
32+
33+
class HasConfigPath env where
34+
configPathL :: Lens' env Text
35+
36+
class HasJobs env where
37+
jobsL :: Lens' env Int
38+
39+
class HasPsa env where
40+
usePsaL :: Lens' env UsePsa
41+
42+
class
43+
( HasGlobalCache env
44+
, HasLogFunc env
45+
, HasConfigPath env
46+
, HasJobs env
47+
, HasPsa env
48+
) => HasEnv env where
49+
envL :: Lens' env Env
50+
51+
instance HasLogFunc Env where
52+
logFuncL = lens envLogFunc (\x y -> x { envLogFunc = y })
53+
54+
instance HasGlobalCache Env where
55+
globalCacheL = lens envGlobalCache (\x y -> x { envGlobalCache = y })
56+
57+
instance HasConfigPath Env where
58+
configPathL = lens envConfigPath (\x y -> x { envConfigPath = y })
59+
60+
instance HasJobs Env where
61+
jobsL = lens envJobs (\x y -> x { envJobs = y })
62+
63+
instance HasPsa Env where
64+
usePsaL = lens envUsePsa (\x y -> x { envUsePsa = y })
65+
66+
instance HasEnv Env where
67+
envL = id

src/Spago/FetchPackage.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fetchPackages globalCacheFlag allDeps minPursVersion = do
4646
PackageSet.checkPursIsUpToDate minPursVersion
4747

4848
-- Ensure both local and global cache dirs are there
49-
globalCache <- askEnv envGlobalCache
49+
globalCache <- view globalCacheL
5050
assertDirectory globalCache
5151
assertDirectory localCacheDir
5252

@@ -63,7 +63,7 @@ fetchPackages globalCacheFlag allDeps minPursVersion = do
6363
logInfo $ "Installing " <> display nOfDeps <> " dependencies."
6464
metadata <- GlobalCache.getMetadata globalCacheFlag
6565

66-
limit <- askEnv envJobs
66+
limit <- view jobsL
6767
withTaskGroup' limit $ \taskGroup -> do
6868
asyncs <- for depsToFetch (async' taskGroup . fetchPackage metadata)
6969
handle (handler asyncs) (for_ asyncs wait')
@@ -98,7 +98,7 @@ fetchPackage _ (PackageName package, Package { location = Local{..}, .. }) =
9898
logInfo $ display $ Messages.foundLocalPackage package localPath
9999
fetchPackage metadata pair@(packageName'@PackageName{..}, Package{ location = Remote{..}, .. } ) = do
100100
logDebug $ "Fetching package " <> display packageName
101-
globalCache <- askEnv envGlobalCache
101+
globalCache <- view globalCacheL
102102
let packageDir = getPackageDir packageName' version
103103
packageGlobalCacheDir = globalCache </> packageDir
104104

src/Spago/GitHub.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ tagCacheFile = "package-sets-tag.txt"
2121
tokenCacheFile = "github-token.txt"
2222

2323

24-
login :: Spago ()
24+
login :: HasEnv env => RIO env ()
2525
login = do
2626
maybeToken <- liftIO (System.Environment.lookupEnv githubTokenEnvVar)
27-
globalCacheDir <- askEnv envGlobalCache
27+
globalCacheDir <- view globalCacheL
2828

2929
case maybeToken of
3030
Nothing -> die [ display Messages.getNewGitHubToken ]
@@ -58,10 +58,10 @@ readToken = readFromEnv <|> readFromFile
5858

5959
getLatestPackageSetsTag :: Spago (Either SomeException Text)
6060
getLatestPackageSetsTag = do
61-
globalCacheDir <- askEnv envGlobalCache
61+
globalCacheDir <- view globalCacheL
6262
assertDirectory globalCacheDir
6363
let globalPathToCachedTag = globalCacheDir </> tagCacheFile
64-
let writeTagCache releaseTagName = writeTextFile (Text.pack globalPathToCachedTag) releaseTagName
64+
let writeTagCache = writeTextFile (Text.pack globalPathToCachedTag)
6565
let readTagCache = try $ readTextFile $ pathFromText $ Text.pack globalPathToCachedTag
6666
let downloadTagToCache env = try
6767
$ Retry.recoverAll (Retry.fullJitterBackoff 50000 <> Retry.limitRetries 5)

0 commit comments

Comments
 (0)