pkg: "module name resolver" and "index" -> "catalog"

This termonology change affects lots of function names from `pkg/lib'
and `pkg/db' (former `pkg/pnr-db'), and it also affects some `raco
pkg' commands.

Existing package installations that are marked as 'pnr in a
local configuration are converted automatically to 'catalog, but any
existing "indexes" configuration must be changed to "catalogs".
This commit is contained in:
Matthew Flatt 2013-04-22 18:23:35 -06:00
parent 5970bbb6bf
commit fc54bbba3c
26 changed files with 529 additions and 524 deletions

View File

@ -9,11 +9,11 @@
(provide
(struct-out pkg)
(contract-out
[current-pkg-index-file
[current-pkg-catalog-file
(parameter/c path-string?)]
[get-indexes (-> (listof string?))]
[set-indexes! ((listof string?) . -> . void?)]
[get-catalogs (-> (listof string?))]
[set-catalogs! ((listof string?) . -> . void?)]
[set-pkgs! ((string? (listof (or/c pkg? string?)))
(#:clear-other-checksums? boolean?)
@ -22,7 +22,7 @@
[get-pkgs (()
(#:name (or/c #f string?)
#:index (or/c #f string?))
#:catalog (or/c #f string?))
. ->* .
(listof pkg?))]
[set-pkg! ((string? string? string? string? string? string?)
@ -44,16 +44,16 @@
[get-module-pkgs (module-path? . -> . (listof pkg?))]
[get-pkgs-without-modules (()
(#:index string?)
(#:catalog string?)
. ->* .
(listof pkg?))]))
(struct pkg (name index author source checksum desc)
(struct pkg (name catalog author source checksum desc)
#:transparent)
(define (prepare-pnr-table db)
(define (prepare-catalog-table db)
(prepare-table db
"pnr"
"catalog"
(~a "(id SMALLINT,"
" url TEXT,"
" pos SMALLINT)")))
@ -62,7 +62,7 @@
(prepare-table db
"pkg"
(~a "(name TEXT,"
" pnr SMALLINT,"
" catalog SMALLINT,"
" author TEXT,"
" source TEXT,"
" checksum TEXT,"
@ -72,7 +72,7 @@
(prepare-table db
"tags"
(~a "(pkg TEXT,"
" pnr TEXT,"
" catalog TEXT,"
" tag TEXT)")))
(define (prepare-modules-table db)
@ -80,21 +80,21 @@
"modules"
(~a "(name TEXT,"
" pkg TEXT,"
" pnr SMALLINT,"
" catalog SMALLINT,"
" checksum TEXT)")))
(define current-pkg-index-file
(define current-pkg-catalog-file
(make-parameter (build-path
(find-system-path 'addon-dir)
(version)
"pkgs"
"pnr.sqlite")))
"catalog.sqlite")))
(define (call-with-pnr-db proc)
(define (call-with-catalog-db proc)
(define db #f)
(dynamic-wind
(lambda ()
(define file (current-pkg-index-file))
(define file (current-pkg-catalog-file))
(define dir (path-only file))
(unless (directory-exists? dir)
(make-directory* dir))
@ -106,29 +106,29 @@
(disconnect db))))
(define (get-pkgs #:name [name #f]
#:index [index #f])
(call-with-pnr-db
#:catalog [catalog #f])
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(for/list ([row (in-list
(apply
query-rows
db
(~a "SELECT K.name, N.url, K.author, K.source, K.checksum, K.desc"
" FROM pkg K, pnr N"
" WHERE N.id = K.pnr"
(if index
" FROM pkg K, catalog N"
" WHERE N.id = K.catalog"
(if catalog
" AND N.url = $1"
"")
(if name
(~a " AND K.name = "
(if index "$2" "$1"))
(if catalog "$2" "$1"))
"")
" ORDER BY N.pos")
(append
(if index
(list index)
(if catalog
(list catalog)
null)
(if name
(list name)
@ -140,119 +140,119 @@
(vector-ref row 4)
(vector-ref row 5))))))
(define (set-pkg! name index author source checksum desc
(define (set-pkg! name catalog author source checksum desc
#:clear-other-checksums? [clear-other-checksums? (not (equal? checksum ""))])
(call-with-pnr-db
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(call-with-transaction
db
(lambda ()
(define pnr (url->pnr db index))
(define catalog-id (url->catalog db catalog))
(query db
(~a "UPDATE pkg"
" SET author=$1, source=$2, checksum=$3, desc=$4"
" WHERE name=$5"
" AND pnr=$6")
" AND catalog=$6")
author source checksum desc
name pnr)
name catalog-id)
(when clear-other-checksums?
(query-exec db
(~a "DELETE FROM modules"
" WHERE pnr=$1 AND pkg=$2 AND checksum<>$3")
pnr
" WHERE catalog=$1 AND pkg=$2 AND checksum<>$3")
catalog-id
name
checksum))
(void))))))
(define (get-pkg-tags name index)
(call-with-pnr-db
(define (get-pkg-tags name catalog)
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(prepare-tags-table db)
(define pnr (url->pnr db index))
(define catalog-id (url->catalog db catalog))
(query-list db
(~a "SELECT tag FROM tags"
" WHERE pnr=$1"
" WHERE catalog=$1"
" AND pkg=$2")
pnr
catalog-id
name))))
(define (set-pkg-tags! name index tags)
(call-with-pnr-db
(define (set-pkg-tags! name catalog tags)
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(prepare-tags-table db)
(call-with-transaction
db
(lambda ()
(define pnr (url->pnr db index))
(define catalog-id (url->catalog db catalog))
(query-exec db
(~a "DELETE FROM tags"
" WHERE pnr=$1"
" WHERE catalog=$1"
" AND pkg=$2")
pnr
catalog-id
name)
(for ([tag (in-list tags)])
(query db
(~a "INSERT INTO tags"
" VALUES ($1, $2, $3)")
name pnr tag)))))))
name catalog-id tag)))))))
(define (get-pkg-modules name index checksum)
(call-with-pnr-db
(define (get-pkg-modules name catalog checksum)
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(prepare-modules-table db)
(define pnr (url->pnr db index))
(define catalog-id (url->catalog db catalog))
(map
string->mod
(query-list db
(~a "SELECT name FROM modules"
" WHERE pnr=$1"
" WHERE catalog=$1"
" AND pkg=$2"
" AND checksum=$3")
pnr
catalog-id
name
checksum)))))
(define (set-pkg-modules! name index checksum modules)
(call-with-pnr-db
(define (set-pkg-modules! name catalog checksum modules)
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(prepare-modules-table db)
(call-with-transaction
db
(lambda ()
(define pnr (url->pnr db index))
(define catalog-id (url->catalog db catalog))
(query-exec db
(~a "DELETE FROM modules"
" WHERE pnr=$1"
" WHERE catalog=$1"
" AND pkg=$2"
" AND checksum=$3")
pnr
catalog-id
name
checksum)
(for ([mod (in-list modules)])
(query db
(~a "INSERT INTO modules"
" VALUES ($1, $2, $3, $4)")
(mod->string mod) name pnr checksum)))))))
(mod->string mod) name catalog-id checksum)))))))
(define (get-module-pkgs mod)
(call-with-pnr-db
(call-with-catalog-db
(lambda (db)
(define rows
(query-rows db
(~a "SELECT M.pkg, P.url, M.checksum"
" FROM modules M, pnr P"
" FROM modules M, catalog P"
" WHERE M.name = $1"
" AND M.pnr = P.id")
" AND M.catalog = P.id")
(mod->string mod)))
(for/list ([row (in-list rows)])
(pkg (vector-ref row 0)
@ -265,10 +265,10 @@
(define (mod->string mp) (~s mp))
(define (string->mod str) (read (open-input-string str)))
(define (get-pkgs-without-modules #:index [index #f])
(call-with-pnr-db
(define (get-pkgs-without-modules #:catalog [catalog #f])
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(prepare-modules-table db)
(define rows
@ -276,20 +276,20 @@
query-rows
db
(~a "SELECT K.name, N.url, K.checksum"
" FROM pkg K, pnr N"
" WHERE N.id = K.pnr"
(if index
" FROM pkg K, catalog N"
" WHERE N.id = K.catalog"
(if catalog
" AND N.url = $1"
"")
" AND NOT EXISTS"
" (SELECT M.name"
" FROM modules M"
" WHERE M.pkg = K.name"
" AND M.pnr = K.pnr"
" AND M.catalog = K.catalog"
" AND M.checksum = K.checksum)")
(append
(if index
(list index)
(if catalog
(list catalog)
null))))
(for/list ([row (in-list rows)])
(pkg (vector-ref row 0)
@ -299,17 +299,17 @@
(vector-ref row 2)
"")))))
(define (get-indexes)
(call-with-pnr-db
(define (get-catalogs)
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(query-list db (~a "SELECT url FROM pnr"
(prepare-catalog-table db)
(query-list db (~a "SELECT url FROM catalog"
" ORDER BY pos")))))
(define (set-indexes! urls)
(call-with-pnr-db
(define (set-catalogs! urls)
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(prepare-tags-table db)
(prepare-modules-table db)
@ -317,7 +317,7 @@
db
(lambda ()
(define current-url+ids
(query-rows db "SELECT url, id FROM pnr"))
(query-rows db "SELECT url, id FROM catalog"))
(define old-urls (for/list ([old (in-list current-url+ids)])
(vector-ref old 0)))
(for ([old (in-list current-url+ids)])
@ -325,73 +325,73 @@
(define old-id (vector-ref old 1))
(unless (member old-url urls)
(query-exec db
"DELETE FROM pnr WHERE id=$1"
"DELETE FROM catalog WHERE id=$1"
old-id)
(query-exec db
"DELETE FROM pkg WHERE pnr=$1"
"DELETE FROM pkg WHERE catalog=$1"
old-id)
(query-exec db
"DELETE FROM tags WHERE pnr=$1"
"DELETE FROM tags WHERE catalog=$1"
old-id)
(query-exec db
"DELETE FROM modules WHERE pnr=$1"
"DELETE FROM modules WHERE catalog=$1"
old-id)))
(for ([new-url (in-list urls)])
(unless (member new-url old-urls)
(let loop ([id 0])
(if (query-maybe-row db
"SELECT url FROM pnr WHERE id=$1"
"SELECT url FROM catalog WHERE id=$1"
id)
(loop (add1 id))
(query-exec db "INSERT INTO pnr VALUES ($1, $2, 0)"
(query-exec db "INSERT INTO catalog VALUES ($1, $2, 0)"
id
new-url)))))
(for ([new-url (in-list urls)]
[pos (in-naturals)])
(query-exec db (~a "UPDATE pnr"
(query-exec db (~a "UPDATE catalog"
" SET pos = $1"
" WHERE url = $2")
pos
new-url)))))))
(define (url->pnr db url)
(define (url->catalog db url)
(query-value db
"SELECT id FROM pnr WHERE url=$1"
"SELECT id FROM catalog WHERE url=$1"
url))
(define (set-pkgs! url pkgs
#:clear-other-checksums? [clear-other-checksums? #t])
(call-with-pnr-db
(call-with-catalog-db
(lambda (db)
(prepare-pnr-table db)
(prepare-catalog-table db)
(prepare-pkg-table db)
(prepare-modules-table db)
(call-with-transaction
db
(lambda ()
(define pnr (url->pnr db url))
(define catalog (url->catalog db url))
(define pkg-names (for/list ([p (in-list pkgs)])
(if (pkg? p)
(pkg-name p)
p)))
(define current-pkgs
(query-list db "SELECT name FROM pkg WHERE pnr=$1"
pnr))
(query-list db "SELECT name FROM pkg WHERE catalog=$1"
catalog))
(define new-pkgs (list->set pkg-names))
(define old-pkgs (list->set current-pkgs))
(for ([old (in-list current-pkgs)])
(unless (set-member? new-pkgs old)
(query-exec db
"DELETE FROM pkg WHERE pnr=$1 AND name=$2"
pnr
"DELETE FROM pkg WHERE catalog=$1 AND name=$2"
catalog
old)
(query-exec db
"DELETE FROM tags WHERE pnr=$1 AND pkg=$2"
pnr
"DELETE FROM tags WHERE catalog=$1 AND pkg=$2"
catalog
old)
(query-exec db
"DELETE FROM modules WHERE pnr=$1 AND pkg=$2"
pnr
"DELETE FROM modules WHERE catalog=$1 AND pkg=$2"
catalog
old)))
(for ([new0 (in-list pkgs)])
(define new (if (pkg? new0)
@ -401,8 +401,8 @@
(not (equal? "" (pkg-checksum new))))
(query-exec db
(~a "DELETE FROM modules"
" WHERE pnr=$1 AND pkg=$2 AND checksum<>$3")
pnr
" WHERE catalog=$1 AND pkg=$2 AND checksum<>$3")
catalog
(pkg-name new)
(pkg-checksum new)))
(unless (and (string? new0)
@ -412,17 +412,17 @@
(~a "UPDATE pkg"
" SET author=$1, source=$2, checksum=$3, desc=$4"
" WHERE name=$5"
" AND pnr=$6")
" AND catalog=$6")
(pkg-author new)
(pkg-source new)
(pkg-checksum new)
(pkg-desc new)
(pkg-name new)
pnr)
catalog)
(query-exec db
"INSERT INTO pkg VALUES ($1, $2, $3, $4, $5, $6)"
(pkg-name new)
pnr
catalog
(pkg-author new)
(pkg-source new)
(pkg-checksum new)
@ -443,15 +443,15 @@
(define (pkg<? a b)
(if (string=? (pkg-name a) (pkg-name b))
(string<? (pkg-index a) (pkg-index b))
(string<? (pkg-catalog a) (pkg-catalog b))
(string<? (pkg-name a) (pkg-name b))))
(parameterize ([current-pkg-index-file (make-temporary-file
(parameterize ([current-pkg-catalog-file (make-temporary-file
"~a.sqlite")])
(check-equal? (get-indexes) '())
(check-equal? (get-catalogs) '())
(set-indexes! '("http://a" "http://b"))
(check-equal? (get-indexes)
(set-catalogs! '("http://a" "http://b"))
(check-equal? (get-catalogs)
'("http://a" "http://b"))
(check-equal? (get-pkgs) '())
@ -467,7 +467,7 @@
(list
(pkg "p1" "http://a" "" "" "" "")
(pkg "p2" "http://b" "" "" "" "")))
(check-equal? (get-pkgs #:index "http://a")
(check-equal? (get-pkgs #:catalog "http://a")
(list
(pkg "p1" "http://a" "" "" "" "")))
(check-equal? (get-pkgs #:name "p1")
@ -480,9 +480,9 @@
(pkg "p1" "http://a" "github:a" "adam" "123" "the first package")
(pkg "p2" "http://b" "" "" "" "")))
;; reverse order of indexes:
(set-indexes! '("http://b" "http://a"))
(check-equal? (get-indexes)
;; reverse order of catalogs:
(set-catalogs! '("http://b" "http://a"))
(check-equal? (get-catalogs)
'("http://b" "http://a"))
(check-equal? (get-pkgs)
(list
@ -508,14 +508,14 @@
(list
(pkg "p1" "http://a" "" "" "123" "")))
(set-indexes! '("http://a" "http://c"))
(check-equal? (sort (get-indexes) string<?)
(set-catalogs! '("http://a" "http://c"))
(check-equal? (sort (get-catalogs) string<?)
'("http://a" "http://c"))
(check-equal? (get-pkgs)
(list
(pkg "p1" "http://a" "github:a" "adam" "123" "the first package")))
(delete-file (current-pkg-index-file))
(delete-file (current-pkg-catalog-file))
(void)))

View File

@ -27,7 +27,7 @@
syntax/modcollapse
"name.rkt"
"util.rkt"
(prefix-in db: "pnr-db.rkt"))
(prefix-in db: "db.rkt"))
(define current-pkg-scope
(make-parameter 'user))
@ -37,7 +37,7 @@
(make-parameter (lambda args (apply error 'pkg args))))
(define current-no-pkg-db
(make-parameter #f))
(define current-pkg-indexes
(define current-pkg-catalogs
(make-parameter #f))
(define (pkg-error . rest)
@ -275,28 +275,28 @@
(hash-ref c k
(λ ()
(match k
["indexes"
["catalogs"
(list "https://pkg.racket-lang.org"
"https://planet-compat.racket-lang.org")]))))
(define (pkg-config-indexes)
(define (pkg-config-catalogs)
(with-pkg-lock/read-only
(read-pkg-cfg/def "indexes")))
(read-pkg-cfg/def "catalogs")))
(define (pkg-indexes)
(or (current-pkg-indexes)
(map string->url (read-pkg-cfg/def "indexes"))))
(define (pkg-catalogs)
(or (current-pkg-catalogs)
(map string->url (read-pkg-cfg/def "catalogs"))))
(define (db-path? p)
(regexp-match? #rx"[.]sqlite$" (path->bytes p)))
(define (pnr-dispatch i server db dir)
(define (catalog-dispatch i server db dir)
(cond
[(equal? "file" (url-scheme i))
(define path (url->path i))
(cond
[(db-path? path)
(parameterize ([db:current-pkg-index-file path])
(parameterize ([db:current-pkg-catalog-file path])
(db))]
[(directory-exists? path) (dir path)])]
[else (server i)]))
@ -308,10 +308,10 @@
(list
(cons 'version (version))))]))
(define (package-index-lookup pkg details?)
(define (package-catalog-lookup pkg details?)
(or
(for/or ([i (in-list (pkg-indexes))])
(pnr-dispatch
(for/or ([i (in-list (pkg-catalogs))])
(catalog-dispatch
i
;; Server:
(lambda (i)
@ -319,7 +319,7 @@
(combine-url/relative i (format "pkg/~a" pkg))))
(log-pkg-debug "resolving via ~a" (url->string addr))
(read-from-server
'package-index-lookup
'package-catalog-lookup
addr
(lambda (v) (and (hash? v)
(for/and ([k (in-hash-keys v)])
@ -335,14 +335,14 @@
(define pkg-path (build-path path "pkg" pkg))
(and (file-exists? pkg-path)
(call-with-input-file* pkg-path read)))))
(pkg-error (~a "cannot find package on indexes\n"
(pkg-error (~a "cannot find package on catalogs\n"
" package: ~a")
pkg)))
(define (db-pkg-info pkg details?)
(if details?
(let ([tags (db:get-pkg-tags (db:pkg-name pkg)
(db:pkg-index pkg))])
(db:pkg-catalog pkg))])
(hash 'name (db:pkg-name pkg)
'author (db:pkg-author pkg)
'source (db:pkg-source pkg)
@ -354,10 +354,8 @@
(define (remote-package-checksum pkg)
(match pkg
[`(pns ,pkg-name) ; compatibility, for now
(hash-ref (package-index-lookup pkg-name #f) 'checksum)]
[`(pnr ,pkg-name)
(hash-ref (package-index-lookup pkg-name #f) 'checksum)]
[`(catalog ,pkg-name)
(hash-ref (package-catalog-lookup pkg-name #f) 'checksum)]
[`(url ,pkg-url-str)
(package-url->checksum pkg-url-str)]))
@ -370,6 +368,7 @@
(file->value file)
(hash))))
the-db)
(define (write-file-hash! file new-db)
(make-parent-directory* file)
(with-output-to-file file
@ -379,7 +378,14 @@
(define (read-pkg-db)
(if (current-no-pkg-db)
#hash()
(read-file-hash (pkg-db-file))))
(let ([the-db (read-file-hash (pkg-db-file))])
;; compatibility: map 'pnr to 'catalog:
(for/hash ([(k v) (in-hash the-db)])
(values k
(if (eq? 'pnr (car (pkg-info-orig-pkg v)))
(struct-copy pkg-info v
[orig-pkg `(catalog ,(cadr (pkg-info-orig-pkg v)))])
v))))))
(define (package-info pkg-name [fail? #t])
(define db (read-pkg-db))
@ -863,9 +869,9 @@
pkg-dir
#t #f)]))]
[(eq? type 'name)
(define index-info (package-index-lookup pkg #f))
(define source (hash-ref index-info 'source))
(define checksum (hash-ref index-info 'checksum))
(define catalog-info (package-catalog-lookup pkg #f))
(define source (hash-ref catalog-info 'source))
(define checksum (hash-ref catalog-info 'checksum))
(define info (stage-package/info source
#f
pkg-name
@ -880,7 +886,7 @@
(update-install-info-checksum
info
checksum)
`(pnr ,pkg))]
`(catalog ,pkg))]
[else
(pkg-error "cannot infer package source type\n source: ~a" pkg)]))
@ -936,8 +942,7 @@
(match-define
(install-info pkg-name orig-pkg pkg-dir clean? checksum)
info)
(define name? (or (eq? 'pns (first orig-pkg)) ; compatibility, for now
(eq? 'pnr (first orig-pkg))))
(define name? (eq? 'catalog (first orig-pkg)))
(define (clean!)
(when clean?
(delete-directory/files pkg-dir)))
@ -1345,8 +1350,8 @@
(cond
[config:set
(match key+vals
[(list* (and key "indexes") val)
(update-pkg-cfg! "indexes" val)]
[(list* (and key "catalogs") val)
(update-pkg-cfg! "catalogs" val)]
[(list (and key "default-scope") val)
(unless (member val '("installation" "user" "shared"))
(pkg-error (~a "invliad value for config key\n"
@ -1370,8 +1375,8 @@
(match key+vals
[(list key)
(match key
["indexes"
(for ([s (in-list (read-pkg-cfg/def "indexes"))])
["catalogs"
(for ([s (in-list (read-pkg-cfg/def "catalogs"))])
(printf "~a\n" s))]
["default-scope"
(if (eq? 'installation (current-pkg-scope))
@ -1456,7 +1461,7 @@
#:exists 'replace
(λ () (display (call-with-input-file pkg sha1))))])))
(define (pkg-index-copy srcs dest
(define (pkg-catalog-copy srcs dest
#:from-config? [from-config? #f]
#:merge? [merge? #f]
#:force? [force? #f]
@ -1464,7 +1469,7 @@
(define src-paths
(for/list ([src (in-list (append srcs
(if from-config?
(pkg-config-indexes)
(pkg-config-catalogs)
null)))])
(define src-path
(cond
@ -1474,7 +1479,7 @@
[(regexp-match? #rx"^file://" src)
(url->path (string->url src))]
[(regexp-match? #rx"^[a-zA-Z]*://" src)
(pkg-error (~a "unrecognized URL scheme for an index\n"
(pkg-error (~a "unrecognized URL scheme for an catalog\n"
" URL: ~a")
src)]
[else (path->complete-path src)]))
@ -1487,7 +1492,7 @@
[(let-values ([(base name dir?) (split-path src-path)]) dir?)
(void)]
[else
(pkg-error (~a "bad source index path\n"
(pkg-error (~a "bad source catalog path\n"
" path: ~a\n"
" expected: directory or path with \".sqlite\" extension")
src)]))
@ -1498,7 +1503,7 @@
[(regexp-match? #rx"^file://" dest)
(url->path (string->url dest))]
[(regexp-match? #rx"^[a-zA-Z]*://" dest)
(pkg-error (~a "cannot copy to a non-file destination index\n"
(pkg-error (~a "cannot copy to a non-file destination catalog\n"
" given URL: ~a")
dest)]
[else (path->complete-path dest)]))
@ -1521,11 +1526,11 @@
(cons dest-path
src-paths))
src-paths)])
(parameterize ([current-pkg-indexes (for/list ([src-path src-paths])
(parameterize ([current-pkg-catalogs (for/list ([src-path src-paths])
(if (path? src-path)
(path->url src-path)
src-path))])
(get-all-pkg-details-from-indexes))))
(get-all-pkg-details-from-catalogs))))
(when (and force? (not merge?))
(cond
@ -1541,8 +1546,8 @@
(cond
[(db-path? dest-path)
(parameterize ([db:current-pkg-index-file dest-path])
(db:set-indexes! '("local"))
(parameterize ([db:current-pkg-catalog-file dest-path])
(db:set-catalogs! '("local"))
(db:set-pkgs! "local"
(for/list ([(k v) (in-hash details)])
(db:pkg k "local"
@ -1571,7 +1576,7 @@
(build-path dest-path "pkgs-all")
(lambda (o) (write details o)))]))
(define (pkg-index-show names
(define (pkg-catalog-show names
#:all? [all? #f]
#:only-names? [only-names? #f])
(for ([name (in-list names)])
@ -1585,22 +1590,22 @@
(cond
[only-names?
(define all-names (if all?
(get-all-pkg-names-from-indexes)
(get-all-pkg-names-from-catalogs)
names))
(for ([name (in-list all-names)])
(unless all?
;; Make sure it's available:
(get-pkg-details-from-indexes name))
(get-pkg-details-from-catalogs name))
(printf "~a\n" name))]
[else
(define all-details (and all?
(get-all-pkg-details-from-indexes)))
(get-all-pkg-details-from-catalogs)))
(for ([name (in-list (if all?
(hash-keys all-details)
names))])
(define details (if all?
(hash-ref all-details name)
(get-pkg-details-from-indexes name)))
(get-pkg-details-from-catalogs name)))
(printf "Package name: ~a\n" name)
(for ([key '(author source checksum tags description)])
(define v (hash-ref details key #f))
@ -1611,16 +1616,16 @@
(apply ~a #:separator ", " v)
v)))))]))
(define (get-all-pkg-names-from-indexes)
(define (get-all-pkg-names-from-catalogs)
(define ht
(for*/hash ([i (in-list (pkg-indexes))]
(for*/hash ([i (in-list (pkg-catalogs))]
[name
(pnr-dispatch
(catalog-dispatch
i
;; Server:
(lambda (i)
(read-from-server
'get-all-pkg-names-from-indexes
'get-all-pkg-names-from-catalogs
(add-version-query
(combine-url/relative i "pkgs"))
(lambda (l) (and (list? l)
@ -1642,19 +1647,19 @@
(values name #t)))
(sort (hash-keys ht) string<?))
(define (get-pkg-details-from-indexes name)
(for/or ([i (in-list (pkg-indexes))])
(package-index-lookup name #t)))
(define (get-pkg-details-from-catalogs name)
(for/or ([i (in-list (pkg-catalogs))])
(package-catalog-lookup name #t)))
(define (get-all-pkg-details-from-indexes)
(for/fold ([ht (hash)]) ([i (in-list (pkg-indexes))])
(define (get-all-pkg-details-from-catalogs)
(for/fold ([ht (hash)]) ([i (in-list (pkg-catalogs))])
(define one-ht
(pnr-dispatch
(catalog-dispatch
i
;; Server:
(lambda (i)
(read-from-server
'get-all-pkg-details-from-indexes
'get-all-pkg-details-from-catalogs
(add-version-query
(combine-url/relative i "pkgs-all"))
(lambda (v)
@ -1730,24 +1735,24 @@
(delete-directory/files dir))))
(define (pkg-index-update-local #:index-file [index-file (db:current-pkg-index-file)]
#:quiet? [quiet? #f])
(parameterize ([db:current-pkg-index-file index-file])
(define indexes (pkg-config-indexes))
(db:set-indexes! indexes)
(define (pkg-catalog-update-local #:catalog-file [catalog-file (db:current-pkg-catalog-file)]
#:quiet? [quiet? #f])
(parameterize ([db:current-pkg-catalog-file catalog-file])
(define catalogs (pkg-config-catalogs))
(db:set-catalogs! catalogs)
(for ([index (in-list indexes)])
(parameterize ([current-pkg-indexes (list (string->url index))])
(define details (get-all-pkg-details-from-indexes))
(db:set-pkgs! index (for/list ([(name ht) (in-hash details)])
(for ([catalog (in-list catalogs)])
(parameterize ([current-pkg-catalogs (list (string->url catalog))])
(define details (get-all-pkg-details-from-catalogs))
(db:set-pkgs! catalog (for/list ([(name ht) (in-hash details)])
(db:pkg name
index
catalog
(hash-ref ht 'author "")
(hash-ref ht 'source "")
(hash-ref ht 'checksum "")
(hash-ref ht 'description ""))))
(define need-modules (db:get-pkgs-without-modules #:index index))
(define need-modules (db:get-pkgs-without-modules #:catalog catalog))
(for ([(pkg) (in-list need-modules)])
(define name (db:pkg-name pkg))
(define ht (hash-ref details name))
@ -1759,11 +1764,11 @@
#f
(hash-ref ht 'checksum #f)
#f)))
(db:set-pkg-modules! name index checksum modules))))))
(db:set-pkg-modules! name catalog checksum modules))))))
(define (choose-index-file)
(define default (db:current-pkg-index-file))
(define (choose-catalog-file)
(define default (db:current-pkg-catalog-file))
(if (file-exists? default)
default
(let ([installation (build-path (find-lib-dir) "pkgs" (file-name-from-path default))])
@ -1771,10 +1776,10 @@
installation
default))))
(define (pkg-index-suggestions-for-module module-path
#:index-file [index-file (choose-index-file)])
(if (file-exists? index-file)
(parameterize ([db:current-pkg-index-file index-file])
(define (pkg-catalog-suggestions-for-module module-path
#:catalog-file [catalog-file (choose-catalog-file)])
(if (file-exists? catalog-file)
(parameterize ([db:current-pkg-catalog-file catalog-file])
(let* ([mod (collapse-module-path
module-path
(lambda () (build-path (current-directory) "dummy.rkt")))]
@ -1809,7 +1814,7 @@
(parameter/c string?)]
[current-pkg-error
(parameter/c procedure?)]
[current-pkg-indexes
[current-pkg-catalogs
(parameter/c (or/c #f (listof url?)))]
[pkg-directory
(-> string? path-string?)]
@ -1853,12 +1858,12 @@
#:ignore-checksums? boolean?
#:quiet? boolean?)
(or/c #f (listof (or/c path-string? (non-empty-listof path-string?)))))]
[pkg-index-show
[pkg-catalog-show
(->* ((listof string?))
(#:all? boolean?
#:only-names? boolean?)
void?)]
[pkg-index-copy
[pkg-catalog-copy
(->* ((listof path-string?) path-string?)
(#:from-config? any/c
#:merge? boolean?
@ -1880,22 +1885,22 @@
(values path?
(or/c #f string?)
boolean?))]
[pkg-config-indexes
[pkg-config-catalogs
(-> (listof string?))]
[pkg-index-update-local
[pkg-catalog-update-local
(->* ()
(#:index-file path-string?
(#:catalog-file path-string?
#:quiet? boolean?)
void?)]
[pkg-index-suggestions-for-module
[pkg-catalog-suggestions-for-module
(->* (module-path?)
(#:index-file path-string?)
(#:catalog-file path-string?)
(listof string?))]
[get-all-pkg-names-from-indexes
[get-all-pkg-names-from-catalogs
(-> (listof string?))]
[get-all-pkg-details-from-indexes
[get-all-pkg-details-from-catalogs
(-> (hash/c string? (hash/c symbol? any/c)))]
[get-pkg-details-from-indexes
[get-pkg-details-from-catalogs
(-> string?
(or/c #f (hash/c symbol? any/c)))]
[get-pkg-content

View File

@ -62,7 +62,7 @@
" (default for most packages)"
" force: installs the package despite missing dependencies"
" search-ask: looks for the dependencies on your package naming services"
" (default if package is an indexed name) and asks if you would"
" (default if package is a package name) and asks if you would"
" like it installed"
" search-auto: like 'search-ask' but does not ask for permission to install")]
[#:bool force () "Ignores conflicts"]
@ -103,7 +103,7 @@
" (default for most packages)"
" force: installs the package despite missing dependencies"
" search-ask: looks for the dependencies on your package naming services"
" (default if package is an indexed name) and asks if you would"
" (default if package is an package name) and asks if you would"
" like it installed"
" search-auto: like 'search-ask' but does not ask for permission to install")]
[#:bool update-deps () "Check named packages' dependencies for updates"]
@ -121,14 +121,14 @@
'update
scope installation shared user
(lambda ()
(with-pkg-lock
(define setup-collects
(pkg-update pkg
#:all? all
#:dep-behavior deps
#:deps? update-deps))
(when setup-collects
(setup no-setup setup-collects)))))]
(with-pkg-lock
(define setup-collects
(pkg-update pkg
#:all? all
#:dep-behavior deps
#:deps? update-deps))
(when setup-collects
(setup no-setup setup-collects)))))]
[remove
"Remove packages"
#:once-each
@ -225,36 +225,38 @@
#:args (package-directory)
(parameterize ([current-pkg-error (pkg-error 'create)])
(pkg-create (if manifest 'MANIFEST (or format 'zip)) package-directory))]
[index-show
"Show information about packages as reported by index"
[catalog-show
"Show information about packages as reported by catalog"
#:once-any
[(#:str index #f) index () "Use <index> instead of configured indexes"]
[(#:str catalog #f) catalog () "Use <catalog> instead of configured catalogs"]
#:once-each
[#:bool all () "Show all packages"]
[#:bool only-names () "Show only package names"]
#:args pkg-name
(when (and all (pair? pkg-name))
((pkg-error 'index-show) "both `--all' and package names provided"))
(parameterize ([current-pkg-indexes (and index
(list (string->url index)))]
[current-pkg-error (pkg-error 'index-show)])
(pkg-index-show pkg-name
#:all? all
#:only-names? only-names))]
[index-copy
"Copy/merge package name resolver information"
((pkg-error 'catalog-show) "both `--all' and package names provided"))
(parameterize ([current-pkg-catalogs (and catalog
(list (string->url catalog)))]
[current-pkg-error (pkg-error 'catalog-show)])
(pkg-catalog-show pkg-name
#:all? all
#:only-names? only-names))]
[catalog-copy
"Copy/merge package name catalogs"
#:once-each
[#:bool from-config () "Include currently configured packages last"]
[#:bool from-config () "Include currently configured catalogs last"]
#:once-any
[#:bool force () "Force replacement fo existing file/directory"]
[#:bool merge () "Merge to existing database"]
#:once-each
[#:bool override () "While merging, override existing with new"]
#:args index
(parameterize ([current-pkg-error (pkg-error 'index-copy)])
(pkg-index-copy (drop-right index 1)
(last index)
#:from-config? from-config
#:force? force
#:merge? merge
#:override? override))])
#:args catalog
(parameterize ([current-pkg-error (pkg-error 'catalog-copy)])
(when (null? catalog)
((current-pkg-error) "need a destination catalog"))
(pkg-catalog-copy (drop-right catalog 1)
(last catalog)
#:from-config? from-config
#:force? force
#:merge? merge
#:override? override))])

View File

@ -14,4 +14,4 @@ building blocks and local-database support.
@local-table-of-contents[]
@include-section["lib.scrbl"]
@include-section["pnr-db.scrbl"]
@include-section["db.scrbl"]

View File

@ -2,9 +2,9 @@
@(require scribble/bnf
"common.rkt")
@title[#:tag "pnr-protocol"]{Package Name Resolver Protocol}
@title[#:tag "catalog-protocol"]{Package Catalog Protocol}
A @tech{package name resolver} is specified by a URL in one of three
A @tech{package catalog} is specified by a URL in one of three
forms:
@itemlist[
@ -19,10 +19,10 @@ forms:
]
@section{Remote and Directory Indexes}
@section{Remote and Directory Catalogs}
In the case of a remote URL or a local directory naming an
@tech{index}, the URL/path is extended as follows to obtain
In the case of a remote URL or a local directory naming a
@tech{package catalog}, the URL/path is extended as follows to obtain
information about packages:
@itemlist[
@ -64,14 +64,14 @@ information about packages:
]}
@item{@litchar{pkgs} path element: Obtains a list of package names
that are mapped by the @tech{index}. An HTTP request for a remote URL
that are mapped by the @tech{package catalog}. An HTTP request for a remote URL
should respond with a @racket[read]-able list of strings. A
path in a local directory formed by adding @filepath{pkg} and
@nonterm{package} should refer to a file that similarly
contains a @racket[read]-able list of strings.
This URL/path form is used by @command-ref{index-copy} and
tools that allow a user to browse an index.
This URL/path form is used by @command-ref{catalog-copy} and
tools that allow a user to browse an catalog.
In the case of a local directory, if no @filepath{pkgs} file is
available, a list is created by listing all files in the
@ -98,21 +98,21 @@ Note that a local directory served as files through an HTTP server
works as a remote URL, as long as the @filepath{pkgs} and
@filepath{pkgs-all} files are present.
The source for the PLT-hosted @tech{package name resolvers} is in the
@racket[(collection-file-path "pkg-index" "meta")]
The source for the PLT-hosted @tech{package catalog} is in the
@racket[(collection-file-path "pkg-catalog" "meta")]
directory of the full Racket distribution.
@; ----------------------------------------
@section{SQLite Indexes}
@section{SQLite Catalogs}
A SQLite database @tech{index} is meant to be constructed and queries
using the @racketmodname[pkg/pnr-db] library, but the database can be
A SQLite database @tech{package catalog} is meant to be constructed and queries
using the @racketmodname[pkg/db] library, but the database can be
constructed in any way as long as it contains the following tables:
@itemlist[
@item{A @tt{pnr} table with the format
@item{A @tt{catalog} table with the format
@verbatim[#:indent 2]{(id SMALLINT,
url TEXT,
@ -120,45 +120,45 @@ constructed in any way as long as it contains the following tables:
Normally, the only row in this table is @tt{(0, "local", 0)},
but a database that records the content of a set of other
indexes can also be used as an index, in which case each row
represents an index; the @tt{id} field is a unique identifier
for each index, the @tt{url} field is the index's URL, and the
@tt{pos} column orders the index relative to others (where a
catalogs can also be used as an catalog, in which case each row
represents an catalog; the @tt{id} field is a unique identifier
for each catalog, the @tt{url} field is the catalog's URL, and the
@tt{pos} column orders the catalog relative to others (where a
lower @tt{pos} takes precedence).}
@item{A @tt{pkg} table with the format
@verbatim[#:indent 2]{(name TEXT,
pnr SMALLINT,
catalog SMALLINT,
author TEXT,
source TEXT,
checksum TEXT,
desc TEXT)}
The @tt{pnr} field is normally @tt{0}; in the case that the
database reflects multiple other indexes, the @tt{pnr} field
indicates the package entry's source index.
The @tt{catalog} field is normally @tt{0}; in the case that the
database reflects multiple other catalogs, the @tt{catalog} field
indicates the package entry's source catalog.
The @tt{pkg} and @tt{pnr} fields together determine a unique
The @tt{pkg} and @tt{catalog} fields together determine a unique
row in the table.}
@item{A @tt{tags} table with the form
@verbatim[#:indent 2]{(pkg TEXT,
pnr TEXT,
catalog TEXT,
tag TEXT)}
where the @tt{pkg} and @tt{pnr} combination identifies a unique
where the @tt{pkg} and @tt{catalog} combination identifies a unique
row in @tt{pkg}.}
@item{A @tt{modules} table with the form
@verbatim[#:indent 2]{(name TEXT,
pkg TEXT,
pnr SMALLINT,
catalog SMALLINT,
checksum TEXT)}
where the @tt{pkg} and @tt{pnr} combination identifies a unique
where the @tt{pkg} and @tt{catalog} combination identifies a unique
row in @tt{pkg}, and @racket[name] is a printed module path.
This table is not currently used by any @exec{raco pkg}

View File

@ -1,22 +1,22 @@
#lang scribble/manual
@(require (for-label racket/base
racket/contract/base
pkg/pnr-db
pkg/db
syntax/modcollapse))
@title[#:tag "pnr-db"]{Package Name Database}
@title[#:tag "db"]{Package Catalog Database}
@defmodule[pkg/pnr-db]{The @racketmodname[pkg/pnr-db] library provides
tools for storing and retrieving @tech{package name resolver}
@defmodule[pkg/db]{The @racketmodname[pkg/db] library provides
tools for storing and retrieving @tech{package catalog}
information in a local database.}
The functions provided by @racketmodname[pkg/pnr-db] do not actually
The functions provided by @racketmodname[pkg/db] do not actually
manage packages; they do not change or consult the local database of
installed modules in any @tech{package scope}. The functions provided
by @racketmodname[pkg/pnr-db] simply reflect a local copy of the
information that a @tech{package name resolver} and individual package
by @racketmodname[pkg/db] simply reflect a local copy of the
information that a @tech{package catalog} and individual package
might provide (but with no guarantee of being in sync with an actual
@tech{package name resolver} or package).
@tech{package catalog} or package).
The database is implemented as an SQLite database with its own
locking, so no additional locks are needed for database access, but
@ -24,7 +24,7 @@ beware of concurrent database changes that could break your program
logic.
@defstruct[pkg ([name string?]
[index string?]
[catalog string?]
[author string?]
[source string?]
[checksum string?]
@ -32,12 +32,12 @@ logic.
#:transparent]{
Represents a package implementation in the database. The @racket[name]
(@tech{package name}) and @racket[index] (@tech{package name
resolver}, normally a URL) fields are always nonempty
(@tech{package name}) and @racket[catalog] (@tech{package catalog},
normally a URL) fields are always nonempty
strings. Otherwise, unknown fields are represented by empty strings.}
@defparam[current-pkg-index-file file path-string?]{
@defparam[current-pkg-catalog-file file path-string?]{
A parameter that determines the file path used to hold the SQLite
database. The default value is in the user's add-on directory and in
@ -45,39 +45,38 @@ a version-specific subdirectory.}
@deftogether[(
@defproc[(get-indexes) (listof string?)]
@defproc[(set-indexes! [indexes (listof string?)]) void?]
@defproc[(get-catalogs) (listof string?)]
@defproc[(set-catalogs! [catalogs (listof string?)]) void?]
)]{
Returns or sets the list of strings for all @tech{package name
resolvers} represented in the database. (Within the database, each
@tech{package name resolver} gets its own identifying number.)
Returns or sets the list of strings for all @tech{package catalog}
represented in the database. (Within the database, each
@tech{package catalog} gets its own identifying number.)
The order of indices in the list represents a search order.
The @racket[set-indexes!] function removes information for any other
@tech{package name resolvers} from the database.}
The @racket[set-catalogs!] function removes information for any other
@tech{package catalogs} from the database.}
@defproc[(get-pkgs [#:name name (or/c #f string?) #f]
[#:index index (or/c #f string?) #f])
[#:catalog catalog (or/c #f string?) #f])
(listof pkg?)]{
Gets a list of package descriptions. If @racket[name] or
@racket[index] is not @racket[#f] (or if both are not @racket[#f]),
@racket[catalog] is not @racket[#f] (or if both are not @racket[#f]),
then the result includes only matching packages.
The result list is ordered by precedence of the @tech{package name
resolver}.}
The result list is ordered by precedence of the @tech{package catalog}.}
@defproc[(set-pkgs! [index string?] [pkgs (listof (or/c string? pkg?))]
@defproc[(set-pkgs! [catalog string?] [pkgs (listof (or/c string? pkg?))]
[#:clear-other-checksums? clear-other-checksums? #t])
void?]{
Sets the list of all packages that are recognized by the
@tech{package name resolver} @racket[index].
@tech{package catalog} @racket[catalog].
Information about any other package for @racket[index] is removed from
Information about any other package for @racket[catalog] is removed from
the database. If a string is provided for @racket[pkgs], it is
treated as a package name; if additional information is already
recorded in the database for the package name, then the additional
@ -90,7 +89,7 @@ list of module paths) is removed from the database.}
@defproc[(set-pkg! [name string?]
[index string?]
[catalog string?]
[author string?]
[source string?]
[checksum string?]
@ -99,7 +98,7 @@ list of module paths) is removed from the database.}
void?]{
Sets the information for a specific package @racket[name] as
recognized by the @tech{package name resolver} @racket[index].
recognized by the @tech{package catalog} @racket[catalog].
If @racket[clear-other-checksums?] is true, then information (such as
a list of module paths) is removed from the database when it is
@ -107,29 +106,29 @@ specific to a checksum other than @racket[checksum].}
@deftogether[(
@defproc[(get-pkg-tags [name string?] [index string?])
@defproc[(get-pkg-tags [name string?] [catalog string?])
(listof string?)]
@defproc[(set-pkg-tags! [name string?] [index string?]
@defproc[(set-pkg-tags! [name string?] [catalog string?]
[module-paths (listof string?)])
void?]
)]{
Gets or sets a list of tags for the package
@racket[name] as recognized by the @tech{package name resolver}
@racket[index].}
@racket[name] as recognized by the @tech{package catalog}
@racket[catalog].}
@deftogether[(
@defproc[(get-pkg-modules [name string?] [index string?] [checksum string?])
@defproc[(get-pkg-modules [name string?] [catalog string?] [checksum string?])
(listof module-path?)]
@defproc[(set-pkg-modules! [name string?] [index string?] [checksum string?]
@defproc[(set-pkg-modules! [name string?] [catalog string?] [checksum string?]
[module-paths (listof module-path?)])
void?]
)]{
Gets or sets a list of module paths that are provided for the package
@racket[name] as recognized by the @tech{package name resolver}
@racket[index] and for a specific @tech{checksum}. The module paths
@racket[name] as recognized by the @tech{package catalog}
@racket[catalog] and for a specific @tech{checksum}. The module paths
should be normalized in the sense of @racket[collapse-module-path].}
@ -141,11 +140,11 @@ Reports a list of packages that implement the given
@racket[collapse-module-path].}
@defproc[(get-pkgs-without-modules [#:index index (or/c #f string?) #f])
@defproc[(get-pkgs-without-modules [#:catalog catalog (or/c #f string?) #f])
(listof pkg?)]{
Returns a list of packages (optionally constrained to @racket[index])
Returns a list of packages (optionally constrained to @racket[catalog])
for which the database has no modules recorded.
Each resulting @racket[pkg] has its @racket[name], @racketidfont{index}, and
Each resulting @racket[pkg] has its @racket[name], @racketidfont{catalog}, and
@racket[checksum] field set, but other fields may be @racket[""].}

View File

@ -4,7 +4,7 @@
racket/contract/base
pkg
pkg/lib
(only-in pkg/pnr-db current-pkg-index-file)
(only-in pkg/db current-pkg-catalog-file)
net/url
syntax/modcollapse
setup/getinfo))
@ -53,21 +53,21 @@ argument. The @exec{raco pkg} command sets this parameter to use
argument.}
@defparam[current-pkg-indexes indexes (or/c #f (listof url?))]{
@defparam[current-pkg-catalogs catalogs (or/c #f (listof url?))]{
A parameter that determines the @tech{package name resolvers} that are
A parameter that determines the @tech{package catalogs} that are
consulted to resolve a @tech{package name}. If the parameter's value
is @racket[#f], then the result of @racket[pkg-config-indexes] is
is @racket[#f], then the result of @racket[pkg-config-catalogs] is
used.}
@defproc[(pkg-config-indexes) (listof string?)]{
@defproc[(pkg-config-catalogs) (listof string?)]{
Returns a list of URL strings for the user's configured @tech{package
name resolvers}.}
catalogs}.}
@defstruct[pkg-info ([orig-pkg (or/c (list/c 'pnr string?)
@defstruct[pkg-info ([orig-pkg (or/c (list/c 'catalog string?)
(list/c 'url string?)
(list/c 'link string?))]
[checksum (or/c #f string?)]
@ -220,71 +220,71 @@ The package lock must be held to allow reads; see
@racket[with-pkg-lock/read-only].}
@defproc[(pkg-index-show [names (listof string?)]
[#:all? all? boolean? #f]
[#:only-names? only-names? boolean? #f])
@defproc[(pkg-catalog-show [names (listof string?)]
[#:all? all? boolean? #f]
[#:only-names? only-names? boolean? #f])
void?]{
Implements the @racket[index-show] command. If @racket[all?] is true,
Implements the @racket[catalog-show] command. If @racket[all?] is true,
then @racket[names] should be empty.}
@defproc[(pkg-index-copy [sources (listof path-string?)]
[dest path-string?]
[#:from-config? from-config? boolean? #f]
[#:merge? merge? boolean? #f]
[#:force? force? boolean? #f]
[#:override? override? boolean? #f])
@defproc[(pkg-catalog-copy [sources (listof path-string?)]
[dest path-string?]
[#:from-config? from-config? boolean? #f]
[#:merge? merge? boolean? #f]
[#:force? force? boolean? #f]
[#:override? override? boolean? #f])
void?]{
Implements the @racket[index-copy] command.}
Implements the @racket[catalog-copy] command.}
@defproc[(pkg-index-update-local [#:index-file index-file path-string? (current-pkg-index-file)]
[#:quiet? quiet? boolean? #f])
@defproc[(pkg-catalog-update-local [#:catalog-file catalog-file path-string? (current-pkg-catalog-file)]
[#:quiet? quiet? boolean? #f])
void?]{
Consults the user's configured @tech{package name resolvers} (like
@racket[pkg-index-copy]) and package servers to populate the database
@racket[index-file] with information about available packages and the
Consults the user's configured @tech{package catalogs} (like
@racket[pkg-catalog-copy]) and package servers to populate the database
@racket[catalog-file] with information about available packages and the
modules that they implement.}
@defproc[(pkg-index-suggestions-for-module
@defproc[(pkg-catalog-suggestions-for-module
[module-path module-path?]
[#:index-file index-file path-string? ....])
[#:catalog-file catalog-file path-string? ....])
(listof string?)]{
Consults @racket[index-file] and returns a list of available packages
Consults @racket[catalog-file] and returns a list of available packages
that provide the module specified by @racket[module-path].
The default @racket[index-file] is @racket[(current-pkg-index-file)]
The default @racket[catalog-file] is @racket[(current-pkg-catalog-file)]
if that file exists, otherwise a file in the racket installation is
tried.}
@defproc[(get-all-pkg-names-from-indexes) (listof string?)]{
@defproc[(get-all-pkg-names-from-catalogs) (listof string?)]{
Consults @tech{package name resolvers} to obtain a list of available
Consults @tech{package catalogs} to obtain a list of available
@tech{package names}.}
@defproc[(get-all-pkg-details-from-indexes)
@defproc[(get-all-pkg-details-from-catalogs)
(hash/c string? (hash/c symbol? any/c))]{
Consults @tech{package name resolvers} to obtain a hash table of available
Consults @tech{package catalogs} to obtain a hash table of available
@tech{package names} mapped to details about the package. Details for
a particular package are provided by a hash table that maps symbols
such as @racket['source], @racket['checksum], and @racket['author].}
@defproc[(get-pkg-details-from-indexes [name string?])
@defproc[(get-pkg-details-from-catalogs [name string?])
(or/c #f (hash/c symbol? any/c))]{
Consults @tech{package name resolvers} to obtain information for a
Consults @tech{package catalogs} to obtain information for a
single @tech{package name}, returning @racket[#f] if the @tech{package
name} has no resolution. Details for the package are provided in the
same form as from @racket[get-all-pkg-details-from-indexes].}
same form as from @racket[get-all-pkg-details-from-catalogs].}
@defproc[(get-pkg-content [desc pkg-desc?]

View File

@ -164,7 +164,7 @@ specified as a GitHub reference is automatically prefixed with
is the last element of @nonterm{optional-subpath} if it is
non-empty, otherwise the inferred name is @nonterm{repository}.}
@item{a @tech{package name} -- A @tech{package name resolver} is
@item{a @tech{package name} -- A @tech{package catalog} is
consulted to determine the source and @tech{checksum} for the package. For
example, @exec{tic-tac-toe} is a package name that can be used as a
package source.
@ -175,20 +175,19 @@ means that it has only the characters @|package-name-chars|.}
]
A @deftech{package name resolver} (@deftech{PNR},
a.k.a. @deftech{index}) is a server or database that converts package
names to other package sources. A PNR is identified by a string
A @deftech{package catalog} is a server or database that converts package
names to other package sources. A @tech{package catalog} is identified by a string
representing a URL, where a @litchar{http://} or @litchar{https://}
URL indicates a remote server, and a @litchar{file://} URL indicates a
local database in the form of an SQLite database or a directory tree.
local catalog in the form of an SQLite database or a directory tree.
PLT supports two @tech{package name resolvers} that are enabled by
PLT supports two @tech{package catalog} servers that are enabled by
default: @url{https://pkg.racket-lang.org} for new packages and
@url{https://planet-compat.racket-lang.org} for automatically
generated packages for old @|PLaneT| packages. Anyone may host a
@tech{package name resolver}, and any file-serving HTTP host can act
as a basic @tech{package name resolver}. See @secref["pnr-protocol"]
for information on how package information is extracted from a PNR.
@tech{package catalog}, and any file-serving HTTP host can act
as a basic @tech{package catalog} server. See @secref["catalog-protocol"]
for information on how package information is extracted from a catalog.
After a package is installed, the original source of its installation
is recorded, as well as whether the instalation was an @tech{automatic installation}. An
@ -262,8 +261,8 @@ sub-sub-commands:
@itemlist[
@item{@exec{fail} --- Cancels the installation if dependencies are version requirements are unmet (default for most packages)}
@item{@exec{force} --- Installs the package(s) despite missing dependencies or version requirements (unsafe)}
@item{@exec{search-ask} --- Looks for the dependencies or updates via the configured @tech{package name resolvers}
(default if the dependency is an indexed name) but asks if you would like it installed or updated.}
@item{@exec{search-ask} --- Looks for the dependencies or updates via the configured @tech{package catalogs}
(default if the dependency is a @tech{package name}) but asks if you would like it installed or updated.}
@item{@exec{search-auto} --- Like @exec{search-ask}, but does not ask for permission to install or update.}
]}
@ -366,7 +365,7 @@ View and modify package configuration options. This command accepts the followin
The valid keys are:
@itemlist[
@item{@exec{indexes} --- A list of URLs for @tech{package name resolvers}.}
@item{@exec{catalogs} --- A list of URLs for @tech{package catalogs}.}
@item{@exec{default-scope} --- Either @exec{installation}, @exec{user}, or @exec{shared}.
This configuration option exists only with the @exec{installation} scope
(i.e., it's an installation-wide configuration of the default @tech{package scope} for @exec{raco pkg} commands).}
@ -384,9 +383,9 @@ View and modify package configuration options. This command accepts the followin
]
}
@item{@command/toc{index-show} @nonterm{option} ... @nonterm{package-name} ...
--- Consults @tech{package name resolvers} for a package (that is not necessarily installed)
and displays the resolver's information for the package, such as its source URL and
@item{@command/toc{catalog-show} @nonterm{option} ... @nonterm{package-name} ...
--- Consults @tech{package catalogs} for a package (that is not necessarily installed)
and displays the catalog's information for the package, such as its source URL and
a checksum. This command accepts the following @nonterm{option}s:
@itemlist[
@ -394,35 +393,35 @@ View and modify package configuration options. This command accepts the followin
supply no @nonterm{packaee-name}s.}
@item{@DFlag{only-names} --- Show only package names. This option is mainly useful with
@DFlag{all}, but when a @nonterm{packaee-name} is provided,
indexes are consulted to ensure that he package is available.}
@item{@DFlag{index} @nonterm{index} --- Query @nonterm{index} instead of the currently configured
@tech{package name resolvers}.}
catalogs are consulted to ensure that he package is available.}
@item{@DFlag{catalog} @nonterm{catalog} --- Query @nonterm{catalog} instead of the currently configured
@tech{package catalogs}.}
]
}
@item{@command/toc{index-copy} @nonterm{option} ... @nonterm{src-index} ... @nonterm{dest-index}
--- Copies information from @tech{package name resolvers} names by @nonterm{src-index}es
to a local database or directory @nonterm{dest-index},
which can be used as a new @tech{package name resolver}.
@item{@command/toc{catalog-copy} @nonterm{option} ... @nonterm{src-catalog} ... @nonterm{dest-catalog}
--- Copies information from @tech{package catalog} names by @nonterm{src-catalog}s
to a local database or directory @nonterm{dest-catalog},
which can be used as a new @tech{package catalog}.
The @nonterm{src-index}es can be remote or local, while @nonterm{dest-index} must be local
The @nonterm{src-catalog}s can be remote or local, while @nonterm{dest-catalog} must be local
(i.e., a directory path or a SQLite database path, as inferred from the path).
If a @nonterm{src-index} or @nonterm{dest-index} does not start with a URL scheme, it is
treated as a filesystem path. Information from multiple @nonterm{src-index}es is merged,
with information from earlier @nonterm{src-index}es taking precedence over later
@nonterm{src-index}es.
If a @nonterm{src-catalog} or @nonterm{dest-catalog} does not start with a URL scheme, it is
treated as a filesystem path. Information from multiple @nonterm{src-catalog}s is merged,
with information from earlier @nonterm{src-catalog}s taking precedence over later
@nonterm{src-catalog}s.
This command accepts the following @nonterm{option}s:
@itemlist[
@item{@DFlag{from-config} --- Adds the currently configured
@tech{package name resolvers} to the end of the @nonterm{src-index}es list.}
@item{@DFlag{force} --- Replaces @nonterm{dest-index} if it exists already.}
@item{@DFlag{merge} --- Adds to @nonterm{dest-index} if it exists already. By default,
information already in @nonterm{dest-index} takes precedence
@tech{package catalogs} to the end of the @nonterm{src-catalog}s list.}
@item{@DFlag{force} --- Replaces @nonterm{dest-catalog} if it exists already.}
@item{@DFlag{merge} --- Adds to @nonterm{dest-catalog} if it exists already. By default,
information already in @nonterm{dest-catalog} takes precedence
over new information.}
@item{@DFlag{override} --- Changes merging so that new information takes precedence
over information already in @nonterm{dest-index}.}
over information already in @nonterm{dest-catalog}.}
]
}
@ -442,8 +441,8 @@ to the command sub-sub-commands.
@defthing[show procedure?]
@defthing[config procedure?]
@defthing[create procedure?]
@defthing[index-show procedure?]
@defthing[index-copy procedure?])
@defthing[catalog-show procedure?]
@defthing[catalog-copy procedure?])
]{
Duplicates the @seclink["cmdline"]{command line interface}.
@ -549,9 +548,9 @@ discovered by those who used your package source when they use
By using either of the above deployment techniques, anyone will be
able to use your package by referring to your @tech{package source}.
However, they will not be able to refer to
it by a simple name until it is listed on a @tech{package name resolver}.
it by a simple name until it is listed on a @tech{package catalog}.
If you'd like to use the official @tech{package name resolver}, browse
If you'd like to use the official @tech{package catalog}, browse
to
@link["https://pkg.racket-lang.org/manage/upload"]{https://pkg.racket-lang.org/manage/upload}
and upload a new package. You will need to create an account and log
@ -564,7 +563,7 @@ updates.
If you use this server, and use GitHub for deployment, then you will
never need to open a web browser to update your package for end
users. You just need to push to your GitHub repository, then within 24
hours, the official @tech{package name resolver} will notice, and
hours, the official @tech{package catalog} will notice, and
@exec{raco pkg update} will work on your user's machines.
@subsection{Naming and Designing Packages}
@ -596,7 +595,7 @@ present interfaces to external, versioned things, such as
package implementors to effectively declare dependencies on provided
features. Such declarations allow @exec{raco pkg install} and
@exec{raco pkg update} to help check dependencies. Declaring and
changing a version is optional, and @tech{package name resolvers}
changing a version is optional, and @tech{package catalog}
ignore version declarations; in particular, a package is a candidate
for updating when its @tech{checksum} changes, independent of whether
the package's version changes or in which direction the version
@ -700,7 +699,7 @@ The following @filepath{info.rkt} fields are used by the package manager:
set up via @exec{raco setup} after the package is installed, or
@racket['all] to indicate that all collections need to be
setup. By default, only collections included in the package are
set up (plus collections for global documentation indexes and
set up (plus collections for global documentation catalogs and
links).}
]
@ -709,10 +708,10 @@ The following @filepath{info.rkt} fields are used by the package manager:
@section{@|Planet1| Compatibility}
PLT maintains a @tech{package name resolver} to serve packages that
PLT maintains a @tech{package catalog} to serve packages that
were developed using the original @seclink[#:doc '(lib
"planet/planet.scrbl") "top"]{@|Planet1|} package system. This
compatibility resolver is at
compatibility catalog is at
@link["https://planet-compat.racket-lang.org/"]{https://planet-compat.racket-lang.org/},
which is included by default in the package-server search path.
@ -747,7 +746,7 @@ future.
@include-section["apis.scrbl"]
@include-section["pnr-protocol.scrbl"]
@include-section["catalog-protocol.scrbl"]
@; ----------------------------------------
@ -836,21 +835,21 @@ Packages are updated only when you run a tool such as
@command-ref{update}, so packages are never updated
implicitly. Furthermore, you can snapshot a set of package archives
and install from those archives, instead of relying on package name
resolution through a @tech{package name resolver}.
resolution through a @tech{package catalog}.
If you want to control the resolution of package names (including
specific @tech{checksum}s) but not necessary keep a copy of all package
code (assuming that old @tech{checksum}s remain available, such as
through Github), you can create a snapshot of the @tech{package name}
to @tech{package source} mapping by using @command-ref{index-copy}.
to @tech{package source} mapping by using @command-ref{catalog-copy}.
For example,
@commandline{raco pkg index-copy --from-config /home/joe/snapshot.sqlite}
@commandline{raco pkg catalog-copy --from-config /home/joe/snapshot.sqlite}
creates a snapshot @filepath{/home/joe/snapshot.sqlite} of the current
package name resolution, and then
@commandline{raco pkg config --set indexes file:///home/joe/snapshot.sqlite}
@commandline{raco pkg config --set catalogs file:///home/joe/snapshot.sqlite}
directs all package-name resolution to the snapshot. You can configure
resolution for specific package names by editing the snapshot.
@ -917,7 +916,7 @@ out of beta when these are completed.
@itemlist[
@item{The official PNR will divide packages into three
@item{The official catalog server will divide packages into three
categories: @reponame{planet}, @reponame{solar-system}, and @reponame{galaxy}. The definitions
for these categories are:
@ -966,10 +965,10 @@ the @reponame{solar-system} category, automatically.
}
@item{In order to mitigate the costs of external linking vis a vis the
inability to understand code in isolation, we will create a module
resolver that searches for providers of modules on the configured
@tech{package name resolvers}. For example, if a module requires
@filepath{data/matrix.rkt}, and it is not available, then the PNR will
inability to understand code in isolation, we will create exception
printers that search for providers of modules on the configured
@tech{package catalogs}. For example, if a module requires
@filepath{data/matrix.rkt}, and it is not available, then the catalog will
be consulted to discover what packages provide it. @emph{Only packages
in @reponame{solar-system} or @reponame{planet} will be
returned.} (This category restriction ensures that the package to
@ -981,8 +980,8 @@ wish to automatically install @reponame{planet} packages but not
@reponame{solar-system} packages, while others may not want to install
any.)
This feature will be generalized across all @tech{package name
resolvers}, so users could maintain their own category definitions with
This feature will be generalized across all @tech{package catalogs},
so users could maintain their own category definitions with
different policies.}
]
@ -994,15 +993,15 @@ require a lot of cross-Racket integration.
@itemlist[
@item{The official PNR is bare bones. It could conceivably do a lot
@item{The official catalog server is bare bones. It could conceivably do a lot
more: keep track of more statistics, enable "social" interactions
about packages, link to documentation, problem reports, licenses,
etc. Some of this is easy and obvious, but the community's needs are
unclear.}
@item{It would be nice to encrypt information from the official
@tech{package name resolver} with a public key shipped with Racket, and
allow other resolvers to implement a similar security scheme.}
@tech{package catalog} with a public key shipped with Racket, and
allow other catalogs to implement a similar security scheme.}
@item{Packages in the @reponame{planet} category should be tested on
DrDr. This would require a way to communicate information about how
@ -1029,12 +1028,12 @@ these included are painful to maintain and unreliable given users with
different versions of Racket installed.
One solution is to have a separate place where such "binary" packages
are available. For example, PLT could run a PNR for every Racket
are available. For example, PLT could run a catalog server for every Racket
version, i.e., @filepath{https://binaries.racket-lang.org/5.3.1.4},
that would contain the binaries for all the packages in the
@reponame{planet} category. Thus, when you install package
@pkgname{tic-tac-toe} you could also install the binary version from
the appropriate PNR.
the appropriate catalog.
There are obvious problems with this... it could be expensive for PLT
in terms of space and time... Racket compilation is not necessarily

View File

@ -2,17 +2,17 @@
(require pkg/lib
rackunit)
;; The `test-api' function is meant to be called via "test-indexes.rkt"
;; The `test-api' function is meant to be called via "test-catalogs.rkt"
(provide test-api)
(define (test-api)
(check-true (andmap string? (pkg-config-indexes)))
(check-true (andmap string? (pkg-config-catalogs)))
(define pkg-names (get-all-pkg-names-from-indexes))
(define pkg-names (get-all-pkg-names-from-catalogs))
(check-not-false (member "pkg-test1" pkg-names))
(check-not-false (member "pkg-test2" pkg-names))
(define details (get-all-pkg-details-from-indexes))
(define details (get-all-pkg-details-from-catalogs))
(check-not-false (hash-ref details "pkg-test1" #f))
(check-not-false (hash-ref details "pkg-test2" #f))
@ -23,7 +23,7 @@
'source)
"http://localhost:9999/pkg-test2.zip")
(define test1-details (get-pkg-details-from-indexes "pkg-test1"))
(define test1-details (get-pkg-details-from-catalogs "pkg-test1"))
(check-equal? test1-details
(hash-ref details "pkg-test1"))

View File

@ -54,4 +54,4 @@
"versions"
"platform"
"raco"
"indexes")
"catalogs")

View File

@ -0,0 +1,86 @@
#lang racket/base
(require pkg/lib
(prefix-in db: pkg/db)
racket/file
racket/format
"shelly.rkt"
"util.rkt")
(pkg-tests
(shelly-begin
(initialize-catalogs)
$ "raco pkg config --set catalogs http://localhost:9990"
$ "racket -l racket/base -l pkg/lib -e '(pkg-config-catalogs)'"
=stdout> "'(\"http://localhost:9990\")\n"
$ "racket -l racket/base -l tests/pkg/test-catalogs-api -e '(test-api)'"
=stderr> ""
(define d (make-temporary-file "pkg-~a" 'directory))
(define db (build-path d "catalog.sqlite"))
(define dir (build-path d "catalog"))
(define dir2 (build-path d "catalog2"))
$ (~a "raco pkg catalog-copy --from-config " (path->string db))
$ (~a "raco pkg config --set catalogs file://" (path->string db))
$ "raco pkg catalog-show pkg-test1"
=stdout> #rx"Source: http://localhost:9999/pkg-test1.zip"
(parameterize ([db:current-pkg-catalog-file db])
(db:set-pkgs! "local"
(append (db:get-pkgs)
(list
(db:pkg "fish" "local" "nemo@sub" "http://localhost:9999/fish.zip" "123"
"Not a whale")))))
$ "raco pkg catalog-show fish" =stdout> #rx"Checksum: 123"
$ (~a "raco pkg catalog-copy " (path->string db) " " (path->string dir))
$ (~a "raco pkg config --set catalogs file://" (path->string dir))
$ "raco pkg catalog-show fish" =stdout> #rx"Checksum: 123"
$ "raco pkg catalog-show --only-names fish" =stdout> #rx"fish"
$ "raco pkg catalog-show --only-names --all" =stdout> #rx"fish"
(delete-file (build-path dir "pkgs"))
(delete-file (build-path dir "pkgs-all"))
$ "raco pkg catalog-show fish" =stdout> #rx"Checksum: 123"
$ "raco pkg catalog-show --only-names fish" =stdout> #rx"^fish"
$ "raco pkg catalog-show --only-names --all" =stdout> #rx"^fish"
(delete-file (build-path dir "pkg/fish"))
$ "raco pkg catalog-show fish" =exit> 1
(define (try-merge dest)
(shelly-begin
$ (~a "raco pkg config --set catalogs file://" (path->string dest))
(make-directory* (build-path dir2 "pkg"))
(define (add-whale! cksum)
(call-with-output-file*
(build-path dir2 "pkg" "whale")
#:exists 'truncate
(lambda (o)
(write (hash 'name "whale"
'checksum cksum
'source "http://localhost:9999/whale.plt")
o))))
(add-whale! "345")
$ (~a "raco pkg catalog-show --catalog file://" (path->string dir2) " whale") =stdout> #rx"Checksum: 345"
$ "raco pkg catalog-show whale" =exit> 1
$ (~a "raco pkg catalog-copy --merge " (path->string dir2) " " (path->string dest))
$ "raco pkg catalog-show whale" =stdout> #rx"Checksum: 345"
(add-whale! "567")
$ (~a "raco pkg catalog-copy --merge " (path->string dir2) " " (path->string dest))
$ "raco pkg catalog-show whale" =stdout> #rx"Checksum: 345"
$ (~a "raco pkg catalog-copy --merge --override " (path->string dir2) " " (path->string dest))
$ "raco pkg catalog-show whale" =stdout> #rx"Checksum: 567"))
(try-merge dir)
(try-merge db)
$ "raco pkg config --set catalogs http://localhost:9990"
(delete-directory/files d)))

View File

@ -15,7 +15,7 @@
(pkg-tests
(shelly-begin
(initialize-indexes)
(initialize-catalogs)
(shelly-case
"checksums"
@ -44,7 +44,7 @@
(file->string "test-pkgs/pkg-test1-bad-checksum.zip.CHECKSUM")
'source
"http://localhost:9999/pkg-test1-bad-checksum.zip"))
$ "raco pkg config --set indexes http://localhost:9990 http://localhost:9991"
$ "raco pkg config --set catalogs http://localhost:9990 http://localhost:9991"
$ "racket -e '(require pkg-test1)'" =exit> 1
$ "raco pkg install pkg-test1" =exit> 1
$ "racket -e '(require pkg-test1)'" =exit> 1))

View File

@ -6,6 +6,6 @@
(with-fake-root
(shelly-case
"reading and writing configs"
$ "raco pkg config indexes" =stdout> "https://pkg.racket-lang.org\nhttps://planet-compat.racket-lang.org\n"
$ "raco pkg config --set indexes http://localhost:9000"
$ "raco pkg config indexes" =stdout> "http://localhost:9000\n")))
$ "raco pkg config catalogs" =stdout> "https://pkg.racket-lang.org\nhttps://planet-compat.racket-lang.org\n"
$ "raco pkg config --set catalogs http://localhost:9000"
$ "raco pkg config catalogs" =stdout> "http://localhost:9000\n")))

View File

@ -15,7 +15,7 @@
(pkg-tests
(shelly-begin
(initialize-indexes)
(initialize-catalogs)
$ "raco pkg create --format plt test-pkgs/pkg-test1/"
$ "raco pkg create --format plt test-pkgs/pkg-test1-not-conflict/"

View File

@ -15,7 +15,7 @@
(pkg-tests
(shelly-begin
(initialize-indexes)
(initialize-catalogs)
(shelly-case
"dependencies"
@ -63,7 +63,7 @@
(with-fake-root
(shelly-case
"local - search-ask [y]"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "racket -e '(require pkg-test2)'" =exit> 1
$ "raco pkg install --deps search-ask test-pkgs/pkg-test2.zip" =exit> 0 <input= "y\n"
$ "racket -e '(require pkg-test2)'" =exit> 0
@ -74,7 +74,7 @@
(with-fake-root
(shelly-case
"local - search-ask []"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "racket -e '(require pkg-test2)'" =exit> 1
$ "raco pkg install --deps search-ask test-pkgs/pkg-test2.zip" =exit> 0 <input= "\n"
$ "racket -e '(require pkg-test2)'" =exit> 0
@ -92,7 +92,7 @@
(with-fake-root
(shelly-case
"local - search-auto"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "racket -e '(require pkg-test2)'" =exit> 1
$ "raco pkg install --deps search-auto test-pkgs/pkg-test2.zip" =exit> 0
$ "racket -e '(require pkg-test2)'" =exit> 0
@ -103,7 +103,7 @@
(with-fake-root
(shelly-case
"remote - search-ask (default) [y]"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "racket -e '(require pkg-test2)'" =exit> 1
$ "raco pkg install pkg-test2" =exit> 0 <input= "y\n"
$ "racket -e '(require pkg-test2)'" =exit> 0

View File

@ -1,86 +0,0 @@
#lang racket/base
(require pkg/lib
(prefix-in db: pkg/pnr-db)
racket/file
racket/format
"shelly.rkt"
"util.rkt")
(pkg-tests
(shelly-begin
(initialize-indexes)
$ "raco pkg config --set indexes http://localhost:9990"
$ "racket -l racket/base -l pkg/lib -e '(pkg-config-indexes)'"
=stdout> "'(\"http://localhost:9990\")\n"
$ "racket -l racket/base -l tests/pkg/test-indexes-api -e '(test-api)'"
=stderr> ""
(define d (make-temporary-file "pkg-~a" 'directory))
(define db (build-path d "pnr.sqlite"))
(define dir (build-path d "pnr"))
(define dir2 (build-path d "pnr2"))
$ (~a "raco pkg index-copy --from-config " (path->string db))
$ (~a "raco pkg config --set indexes file://" (path->string db))
$ "raco pkg index-show pkg-test1"
=stdout> #rx"Source: http://localhost:9999/pkg-test1.zip"
(parameterize ([db:current-pkg-index-file db])
(db:set-pkgs! "local"
(append (db:get-pkgs)
(list
(db:pkg "fish" "local" "nemo@sub" "http://localhost:9999/fish.zip" "123"
"Not a whale")))))
$ "raco pkg index-show fish" =stdout> #rx"Checksum: 123"
$ (~a "raco pkg index-copy " (path->string db) " " (path->string dir))
$ (~a "raco pkg config --set indexes file://" (path->string dir))
$ "raco pkg index-show fish" =stdout> #rx"Checksum: 123"
$ "raco pkg index-show --only-names fish" =stdout> #rx"fish"
$ "raco pkg index-show --only-names --all" =stdout> #rx"fish"
(delete-file (build-path dir "pkgs"))
(delete-file (build-path dir "pkgs-all"))
$ "raco pkg index-show fish" =stdout> #rx"Checksum: 123"
$ "raco pkg index-show --only-names fish" =stdout> #rx"^fish"
$ "raco pkg index-show --only-names --all" =stdout> #rx"^fish"
(delete-file (build-path dir "pkg/fish"))
$ "raco pkg index-show fish" =exit> 1
(define (try-merge dest)
(shelly-begin
$ (~a "raco pkg config --set indexes file://" (path->string dest))
(make-directory* (build-path dir2 "pkg"))
(define (add-whale! cksum)
(call-with-output-file*
(build-path dir2 "pkg" "whale")
#:exists 'truncate
(lambda (o)
(write (hash 'name "whale"
'checksum cksum
'source "http://localhost:9999/whale.plt")
o))))
(add-whale! "345")
$ (~a "raco pkg index-show --index file://" (path->string dir2) " whale") =stdout> #rx"Checksum: 345"
$ "raco pkg index-show whale" =exit> 1
$ (~a "raco pkg index-copy --merge " (path->string dir2) " " (path->string dest))
$ "raco pkg index-show whale" =stdout> #rx"Checksum: 345"
(add-whale! "567")
$ (~a "raco pkg index-copy --merge " (path->string dir2) " " (path->string dest))
$ "raco pkg index-show whale" =stdout> #rx"Checksum: 345"
$ (~a "raco pkg index-copy --merge --override " (path->string dir2) " " (path->string dest))
$ "raco pkg index-show whale" =stdout> #rx"Checksum: 567"))
(try-merge dir)
(try-merge db)
$ "raco pkg config --set indexes http://localhost:9990"
(delete-directory/files d)))

View File

@ -15,7 +15,7 @@
(pkg-tests
(shelly-begin
(initialize-indexes)
(initialize-catalogs)
(shelly-case
"raco pkg install tests"
@ -98,13 +98,13 @@
(with-fake-root
(shelly-case
"remote/name package, doesn't work when no package there"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "raco pkg install pkg-test1-not-there" =exit> 1))
(with-fake-root
(shelly-case
"remote/name package"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "racket -e '(require pkg-test1)'" =exit> 1
$ "raco pkg install pkg-test1"
$ "racket -e '(require pkg-test1)'"
@ -114,7 +114,7 @@
(with-fake-root
(shelly-case
"remote/name package (multi)"
$ "raco pkg config --set indexes http://localhost:9990 http://localhost:9991"
$ "raco pkg config --set catalogs http://localhost:9990 http://localhost:9991"
$ "racket -e '(require pkg-test1)'" =exit> 1
$ "raco pkg install --deps search-auto pkg-test2-snd"
$ "racket -e '(require pkg-test1)'"

View File

@ -11,7 +11,7 @@
"A lock is used to guarantee serial access to the package database"
;; Step 1: Start a special server that waits for our signal to respond
(initialize-indexes)
(initialize-catalogs)
(define okay-to-respond?-sema (make-semaphore))
(thread
(λ ()
@ -27,7 +27,7 @@
(sleep 1)))
;; Step 2: Assign it as our server
$ "raco pkg config --set indexes http://localhost:9967"
$ "raco pkg config --set catalogs http://localhost:9967"
;; Step 3: Start an installation request in the background
(thread

View File

@ -31,7 +31,7 @@
(with-fake-root
(shelly-case
"remote/name package"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "racket -e '(require planet2-test1)'" =exit> 1
$ "raco pkg install planet2-test1-github-different-checksum"
$ "racket -e '(require planet2-test1)'"

View File

@ -3,14 +3,14 @@
racket/file
racket/format
pkg/util
(prefix-in db: pkg/pnr-db)
(prefix-in db: pkg/db)
"shelly.rkt"
"util.rkt")
(pkg-tests
(shelly-begin
(define pkgs-dir (make-temporary-file "~a-pkgs" 'directory))
(define db (build-path pkgs-dir "pnr.sqlite"))
(define db (build-path pkgs-dir "catalog.sqlite"))
(define pkg-x-dir (build-path pkgs-dir "pkg-x"))
(make-directory* pkg-x-dir)
@ -28,8 +28,8 @@
("pkg-x-platform-no" #:platform #rx"no such platform")))
o)))
(parameterize ([db:current-pkg-index-file db])
(db:set-indexes! '("local"))
(parameterize ([db:current-pkg-catalog-file db])
(db:set-catalogs! '("local"))
(db:set-pkgs! "local"
'("pkg-x" "pkg-x-windows" "pkg-x-unix" "pkg-x-macosx"
"pkg-x-platform1" "pkg-x-platform2")))
@ -44,7 +44,7 @@
(build-path coll-dir "main.rkt")
(lambda (o)
(displayln "#lang racket/base" o)))
(parameterize ([db:current-pkg-index-file db])
(parameterize ([db:current-pkg-catalog-file db])
(db:set-pkg! pkg-name "local" "author@place" (path->string dir) "123456" "")))
(create-package "pkg-x")
@ -56,7 +56,7 @@
(with-fake-root
(shelly-begin
$ (~a "raco pkg config --set indexes file://" (path->string db))
$ (~a "raco pkg config --set catalogs file://" (path->string db))
$ "racket -e '(require pkg-x)'" =exit> 1
$ "raco pkg install --deps search-auto pkg-x" =exit> 0
$ "racket -e '(require pkg-x)'" =exit> 0

View File

@ -15,7 +15,7 @@
(pkg-tests
(shelly-begin
(initialize-indexes)
(initialize-catalogs)
(shelly-case
"remove and show"
@ -55,16 +55,16 @@
(with-fake-root
(shelly-case
"autoremove"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "racket -e '(require pkg-test1)'" =exit> 1
$ "racket -e '(require pkg-test2)'" =exit> 1
$ "raco pkg install --deps search-auto test-pkgs/pkg-test2.zip" =exit> 0
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(pnr pkg-test1\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "racket -e '(require pkg-test2)'" =exit> 0
$ "racket -e '(require pkg-test2/contains-dep)'" =exit> 0
$ "raco pkg remove pkg-test2"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(pnr pkg-test1\\)\n"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\n"
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "raco pkg remove --auto"
$ "raco pkg show -u" =stdout> " [none]\n"

View File

@ -10,7 +10,7 @@
(file->string "test-pkgs/pkg-b-first.plt.CHECKSUM")
'source
"http://localhost:9999/pkg-b-first.plt"))
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "raco pkg install pkg-b"
$ "racket -e '(require pkg-b)'" =exit> 42
(hash-set! *index-ht-1* "pkg-b"
@ -34,7 +34,7 @@
(with-fake-root
(shelly-case
"update and then remove an auto"
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
(hash-set! *index-ht-1* "pkg-b"
(hasheq 'checksum
(file->string "test-pkgs/pkg-b-second.plt.CHECKSUM")
@ -46,12 +46,12 @@
'source
"http://localhost:9999/pkg-a-first.plt"))
$ "raco pkg install --deps search-auto pkg-b" =exit> 0 <input= "y\n"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(pnr pkg-a\\)\npkg-b +[a-f0-9]+ +\\(pnr pkg-b\\)\n"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog pkg-a\\)\npkg-b +[a-f0-9]+ +\\(catalog pkg-b\\)\n"
$ "racket -e '(require pkg-b)'" =exit> 43
$ "racket -e '(require pkg-a)'" =exit> 0
;; remove auto doesn't do anything because everything is needed
$ "raco pkg remove --auto"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(pnr pkg-a\\)\npkg-b +[a-f0-9]+ +\\(pnr pkg-b\\)\n"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog pkg-a\\)\npkg-b +[a-f0-9]+ +\\(catalog pkg-b\\)\n"
$ "racket -e '(require pkg-b)'" =exit> 43
$ "racket -e '(require pkg-a)'" =exit> 0
;; pkg-a is now an auto
@ -63,7 +63,7 @@
$ "raco pkg update -a" =exit> 0
$ "racket -e '(require pkg-a)'" =exit> 43
$ "raco pkg remove pkg-b"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ +\\(pnr pkg-a\\)\n"
$ "raco pkg show -u" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ +\\(catalog pkg-a\\)\n"
$ "racket -e '(require pkg-b)'" =exit> 1
;; pkg-a is now not needed
$ "raco pkg remove --auto"

View File

@ -10,7 +10,7 @@
(file->string "test-pkgs/pkg-b-first.plt.CHECKSUM")
'source
"http://localhost:9999/pkg-b-first.plt"))
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "raco pkg install pkg-b"
$ "racket -e '(require pkg-b)'" =exit> 42
(hash-set! *index-ht-1* "pkg-b"

View File

@ -15,7 +15,7 @@
(pkg-tests
(shelly-begin
(initialize-indexes)
(initialize-catalogs)
(shelly-case
"update"
@ -86,15 +86,15 @@
(shelly-install**
"named remote packages can be update"
"pkg-test1" "pkg-test1"
($ "raco pkg config --set indexes http://localhost:9990")
($ "raco pkg config --set catalogs http://localhost:9990")
($ "raco pkg update pkg-test1" =exit> 0 =stdout> "No updates available\n"
$ "racket -e '(require pkg-test1/update)'" =exit> 42
$ "cp test-pkgs/pkg-test1-v2.zip test-pkgs/pkg-test1.zip"
$ "cp test-pkgs/pkg-test1-v2.zip.CHECKSUM test-pkgs/pkg-test1.zip.CHECKSUM"
(initialize-indexes)
(initialize-catalogs)
$ "raco pkg update pkg-test1" =exit> 0
$ "racket -e '(require pkg-test1/update)'" =exit> 43))
(finally
$ "cp -f test-pkgs/pkg-test1.zip.bak test-pkgs/pkg-test1.zip"
$ "cp -f test-pkgs/pkg-test1.zip.CHECKSUM.bak test-pkgs/pkg-test1.zip.CHECKSUM"
(initialize-indexes))))))
(initialize-catalogs))))))

View File

@ -15,7 +15,7 @@
(pkg-tests
(shelly-begin
(initialize-indexes)
(initialize-catalogs)
(shelly-case
"create packages"
@ -35,7 +35,7 @@
'source
"http://localhost:9999/pkg-w-one.zip"))
$ "raco pkg config --set indexes http://localhost:9990"
$ "raco pkg config --set catalogs http://localhost:9990"
(shelly-case
"update"
@ -61,5 +61,5 @@
(shelly-begin "auto-update now succeeds (installs and version matches)"
$ "raco pkg install --deps search-auto pkg-w"))
(initialize-indexes)))
(initialize-catalogs)))

View File

@ -128,7 +128,7 @@
(define-syntax-rule (shelly-install message pkg more ...)
(shelly-install* message pkg "pkg-test1" more ...))
(define (initialize-indexes)
(define (initialize-catalogs)
(hash-set! *index-ht-1* "pkg-test1"
(hasheq 'checksum
(file->string "test-pkgs/pkg-test1.zip.CHECKSUM")