Skip to content

Commit 12f5a13

Browse files
authored
Introduce package "notices" (#320)
* Add notice config option * expose any given notice as a warning when installing a package.
1 parent dd32806 commit 12f5a13

File tree

9 files changed

+41
-30
lines changed

9 files changed

+41
-30
lines changed

src/Pack/Admin/Report/Types.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ apiLink p =
5959
"https://stefan-hoeck.github.io/idris2-pack-db/docs/\{p}/docs/index.html"
6060

6161
url : (e : Env) => Package -> URL
62-
url (Git u _ _ _ _) = u
62+
url (Git u _ _ _ _ _) = u
6363
url (Local dir ipkg pkgPath _) = MkURL "\{dir}"
6464
url (Core _) = e.db.idrisURL
6565

6666
commit : (e : Env) => Package -> Commit
67-
commit (Git _ c _ _ _) = c
67+
commit (Git _ c _ _ _ _) = c
6868
commit (Local dir ipkg pkgPath _) = ""
6969
commit (Core _) = e.db.idrisCommit
7070

src/Pack/Admin/Runner/Check.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test (RL pkg n d _ _) =
4343
case e.env.config.skipTests of
4444
True => pure Skipped
4545
False => case pkg of
46-
Git u c _ _ (Just t) => do
46+
Git u c _ _ (Just t) _ => do
4747
d <- withGit n u c pure
4848
runIpkg (d </> t) [] e
4949
pure TestSuccess

src/Pack/Config/Environment.idr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ idrisDataDir = idrisInstallDir /> "support"
157157
||| Directory where an installed library or app goes
158158
export %inline
159159
pkgPrefixDir : PackDir => DB => PkgName -> Package -> Path Abs
160-
pkgPrefixDir n (Git _ c _ _ _) = commitDir <//> n <//> c
160+
pkgPrefixDir n (Git _ c _ _ _ _) = commitDir <//> n <//> c
161161
pkgPrefixDir n (Local _ _ _ _) = commitDir </> "local" <//> n
162162
pkgPrefixDir n (Core _) = idrisPrefixDir
163163

@@ -219,7 +219,7 @@ pkgInstallDir n p d =
219219
dir := pkgPrefixDir n p /> idrisDir
220220
in case p of
221221
Core c => dir /> (c <-> vers)
222-
Git _ _ _ _ _ => dir </> pkgRelDir d
222+
Git _ _ _ _ _ _ => dir </> pkgRelDir d
223223
Local _ _ _ _ => dir </> pkgRelDir d
224224

225225
||| Directory where the API docs of the package will be installed.
@@ -577,7 +577,7 @@ cacheCoreIpkgFiles dir = for_ corePkgs $ \c =>
577577

578578
export
579579
notCached : HasIO io => (e : Env) => PkgName -> Package -> io Bool
580-
notCached n (Git u c i _ _) = fileMissing $ ipkgCachePath n c i
580+
notCached n (Git u c i _ _ _) = fileMissing $ ipkgCachePath n c i
581581
notCached n (Local d i _ _) = pure False
582582
notCached n (Core c) = fileMissing $ coreCachePath c
583583

@@ -588,7 +588,7 @@ cachePkg :
588588
-> PkgName
589589
-> Package
590590
-> EitherT PackErr io ()
591-
cachePkg n (Git u c i _ _) =
591+
cachePkg n (Git u c i _ _ _) =
592592
let cache := ipkgCachePath n c i
593593
tmpLoc := gitTmpDir n </> i
594594
in withGit n u c $ \dir => do

src/Pack/Database/TOML.idr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ git f v =
2121
(valAt "ipkg" f v)
2222
(optValAt "packagePath" f False v)
2323
(maybeValAt "test" f v)
24+
(maybeValAt "notice" f v)
2425
|]
2526

2627
local : File Abs -> TomlValue -> Either TOMLErr (Package_ c)

src/Pack/Database/Types.idr

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ data Package_ : (c : Type) -> Type where
143143
-> (ipkg : File Rel)
144144
-> (pkgPath : Bool)
145145
-> (testIpkg : Maybe (File Rel))
146+
-> (notice : Maybe String)
146147
-> Package_ c
147148

148149
||| A local Idris project given as an absolute path to a local
@@ -161,13 +162,13 @@ data Package_ : (c : Type) -> Type where
161162

162163
export
163164
Functor Package_ where
164-
map f (Git u c i p t) = Git u (f c) i p t
165+
map f (Git u c i p t n) = Git u (f c) i p t n
165166
map f (Local d i p t) = Local d i p t
166167
map f (Core c) = Core c
167168

168169
export
169170
traverse : Applicative f => (URL -> a -> f b) -> Package_ a -> f (Package_ b)
170-
traverse g (Git u c i p t) = (\c' => Git u c' i p t) <$> g u c
171+
traverse g (Git u c i p t n) = (\c' => Git u c' i p t n) <$> g u c
171172
traverse _ (Local d i p t) = pure $ Local d i p t
172173
traverse _ (Core c) = pure $ Core c
173174

@@ -250,14 +251,14 @@ isGit (Local {}) = No absurd
250251
||| folders where Idris package are installed.
251252
export
252253
usePackagePath : Package_ c -> Bool
253-
usePackagePath (Git _ _ _ pp _) = pp
254+
usePackagePath (Git _ _ _ pp _ _) = pp
254255
usePackagePath (Local _ _ pp _) = pp
255256
usePackagePath (Core _) = False
256257

257258
||| Absolute path to the `.ipkg` file of a package.
258259
export
259260
ipkg : (dir : Path Abs) -> Package -> File Abs
260-
ipkg dir (Git _ _ i _ _) = toAbsFile dir i
261+
ipkg dir (Git _ _ i _ _ _) = toAbsFile dir i
261262
ipkg dir (Local _ i _ _) = toAbsFile dir i
262263
ipkg dir (Core c) = toAbsFile dir (coreIpkgPath c)
263264

@@ -452,29 +453,31 @@ tomlBool : Bool -> String
452453
tomlBool True = "true"
453454
tomlBool False = "false"
454455

455-
testPath : Maybe (File Rel) -> List String
456-
testPath Nothing = []
457-
testPath (Just x) = [ "test = \{quote x}" ]
456+
testPath : Maybe (File Rel) -> Maybe String
457+
testPath = map (\x => "test = \{quote x}")
458+
459+
notice : Maybe String -> Maybe String
460+
notice = map (\x => "notice = \{quote x}")
458461

459462
-- we need to print `Git` packages as `"github"` at
460463
-- least for the time being for reasons of compatibility
461464
printPair : (PkgName,Package) -> List String
462-
printPair (x, Git url commit ipkg pp t) =
465+
printPair (x, Git url commit ipkg pp t n) =
463466
[ "[db.\{x}]"
464467
, "type = \"github\""
465468
, "url = \{quote url}"
466469
, "commit = \{quote commit}"
467470
, "ipkg = \{quote ipkg}"
468471
, "packagePath = \{tomlBool pp}"
469-
] ++ testPath t
472+
] ++ (catMaybes [testPath t, notice n])
470473

471474
printPair (x, Local dir ipkg pp t) =
472475
[ "[db.\{x}]"
473476
, "type = \"local\""
474477
, "path = \{quote dir}"
475478
, "ipkg = \{quote ipkg}"
476479
, "packagePath = \{tomlBool pp}"
477-
] ++ testPath t
480+
] ++ (catMaybes [testPath t])
478481

479482
printPair (x, Core c) =
480483
[ "[db.\{x}]"

src/Pack/Runner/Database.idr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ withPkgEnv :
181181
-> Package
182182
-> (Path Abs -> EitherT PackErr io a)
183183
-> EitherT PackErr io a
184-
withPkgEnv n (Git u c i _ _) f = withGit n u c f
185-
withPkgEnv n (Local d i _ _) f = inDir d f
186-
withPkgEnv n (Core _) f = withCoreGit f
184+
withPkgEnv n (Git u c i _ _ _) f = withGit n u c f
185+
withPkgEnv n (Local d i _ _) f = inDir d f
186+
withPkgEnv n (Core _) f = withCoreGit f
187187

188188
isOutdated : DPair Package PkgStatus -> Bool
189189
isOutdated (fst ** Outdated) = True
@@ -265,7 +265,7 @@ loadIpkg :
265265
-> PkgName
266266
-> Package
267267
-> EitherT PackErr io (Desc U)
268-
loadIpkg n (Git u c i _ _) =
268+
loadIpkg n (Git u c i _ _ _) =
269269
let cache := ipkgCachePath n c i
270270
tmpLoc := gitTmpDir n </> i
271271
in parseIpkgFile cache tmpLoc

src/Pack/Runner/Develop.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ runTest :
184184
-> EitherT PackErr io ()
185185
runTest n args e = case lookup n allPackages of
186186
Nothing => throwE (UnknownPkg n)
187-
Just (Git u c _ _ $ Just t) => do
187+
Just (Git u c _ _ (Just t) _) => do
188188
d <- withGit n u c pure
189189
runIpkg (d </> t) args e
190190
Just (Local d _ _ $ Just t) => runIpkg (d </> t) args e

src/Pack/Runner/Install.idr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ withSrcStr = case c.withSrc of
222222
True => " (with sources)"
223223
False => ""
224224

225+
maybeGiveNotice : HasIO io => Config => SafeLib -> io ()
226+
maybeGiveNotice (RL (Git _ _ _ _ _ (Just notice)) _ _ _ _) = warn notice
227+
maybeGiveNotice _ = pure ()
228+
225229
installImpl :
226230
{auto _ : HasIO io}
227231
-> {auto e : IdrisEnv}
@@ -234,6 +238,7 @@ installImpl dir rl =
234238
libDir := rl.desc.path.parent </> "lib"
235239
in do
236240
info "Installing library\{withSrcStr}: \{name rl}"
241+
maybeGiveNotice rl
237242
when (isInstalled rl) $ do
238243
info "Removing currently installed version of \{name rl}"
239244
rmDir (pkgInstallDir rl.name rl.pkg rl.desc)
@@ -253,7 +258,7 @@ preInstall :
253258
preInstall rl = withPkgEnv rl.name rl.pkg $ \dir =>
254259
let ipkgAbs := ipkg dir rl.pkg
255260
in case rl.pkg of
256-
Git u c ipkg _ _ => do
261+
Git u c ipkg _ _ _ => do
257262
let cache := ipkgCachePath rl.name c ipkg
258263
copyFile cache ipkgAbs
259264
Local _ _ _ _ => pure ()
@@ -308,7 +313,7 @@ installApp b ra =
308313
let ipkgAbs := ipkg dir ra.pkg
309314
in case ra.pkg of
310315
Core _ => pure ()
311-
Git u c ipkg pp _ => do
316+
Git u c ipkg pp _ _ => do
312317
let cache := ipkgCachePath ra.name c ipkg
313318
copyFile cache ipkgAbs
314319
libPkg [] Build True ["--build"] (notPackIsSafe ra.desc)

src/Pack/Runner/Query.idr

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,27 @@ appStatus qp = case qp.app of
147147
, "App : \{status' st}"
148148
]
149149

150-
testFile : Maybe (File Rel) -> List String
151-
testFile Nothing = []
152-
testFile (Just f) = ["Test File : \{f}"]
150+
testFile : Maybe (File Rel) -> Maybe String
151+
testFile = map (\f => "Test File : \{f}")
152+
153+
notice : Maybe String -> Maybe String
154+
notice = map (\f => "Notice : \{f}")
153155

154156
details : QPkg -> List String
155157
details qp = case qp.lib.pkg of
156-
Git url commit ipkg _ t => [
158+
Git url commit ipkg _ t n => [
157159
"Type : Git project"
158160
, "URL : \{url}"
159161
, "Commit : \{commit}"
160162
, "ipkg File : \{ipkg}"
161-
] ++ testFile t
163+
] ++ (catMaybes [testFile t, notice n])
162164

163165
Local d i _ t =>
164166
let ipkg := toAbsFile d i
165167
in [ "Type : Local Idris project"
166168
, "Location : \{ipkg.parent}"
167169
, "ipkg File : \{ipkg.file}"
168-
] ++ testFile t
170+
] ++ (catMaybes [testFile t])
169171

170172
Core _ => [
171173
"Type : Idris core package"

0 commit comments

Comments
 (0)