Commit 587adf09 authored by Michael Hanus 's avatar Michael Hanus
Browse files

CPM updated

parent eb52fa6f
......@@ -5,7 +5,7 @@
\usepackage{listings}
\usepackage{amsmath}
\lstset{aboveskip=1.5ex,
belowskip=1.5ex,
belowskip=1.2ex,
showstringspaces=false,
mathescape=true,
flexiblecolumns=false,
......@@ -649,7 +649,7 @@ category (see Section~\ref{sec:reference})
of the central package index.
The option \code{--csv} shows the information in CSV format.
\item[\fbox{\code{search [--module] $query$}}]
\item[\fbox{\code{search [--module|--exec] $query$}}]
Searches the names, synopses, and exported module names of all
packages of the central package index for occurrences of the given
search term.
......@@ -660,6 +660,17 @@ exporting the module \code{JSON.Data} can be found by the command
\begin{lstlisting}
> cpm search --module JSON.Data
\end{lstlisting}
%
If the option \code{--exec} is set, then the search is restricted
to the name of the executable provided by the package.
For instance, the command
%
\begin{lstlisting}
> cpm search --exec show
\end{lstlisting}
%
lists all packages where the name of the executable contains the
string \ccode{show}.
\item[\fbox{\code{update}}] Updates the local copy of the central package index
to the newest available version.
......
......@@ -47,7 +47,7 @@ cpmBanner :: String
cpmBanner = unlines [bannerLine,bannerText,bannerLine]
where
bannerText =
"Curry Package Manager <curry-language.org/tools/cpm> (version of 02/07/2017)"
"Curry Package Manager <curry-language.org/tools/cpm> (version of 17/07/2017)"
bannerLine = take (length bannerText) (repeat '-')
main :: IO ()
......@@ -97,8 +97,8 @@ runWithArgs opts = do
New o -> newPackage o
_ -> do repo <- readRepository config
case optCommand opts of
List o -> listCmd o config repo
Search o -> search o config repo
List o -> listCmd o config repo
Search o -> searchCmd o config repo
_ -> do globalCache <- getGlobalCache config repo
case optCommand opts of
Deps -> deps config repo globalCache
......@@ -182,8 +182,9 @@ data ListOptions = ListOptions
}
data SearchOptions = SearchOptions
{ searchQuery :: String
, searchModule :: Bool
{ searchQuery :: String -- the term to search for
, searchModule :: Bool -- search for some module?
, searchExec :: Bool -- search for some executable?
}
data UpgradeOptions = UpgradeOptions
......@@ -253,7 +254,7 @@ listOpts s = case optCommand s of
searchOpts :: Options -> SearchOptions
searchOpts s = case optCommand s of
Search opts -> opts
_ -> SearchOptions "" False
_ -> SearchOptions "" False False
upgradeOpts :: Options -> UpgradeOptions
upgradeOpts s = case optCommand s of
......@@ -596,7 +597,12 @@ optionParser = optParser
{ searchModule = True } })
( short "m"
<> long "module"
<> help "Search an exported module" )
<> help "Search for an exported module" )
<.> flag (\a -> Right $ a { optCommand = Search (searchOpts a)
{ searchExec = True } })
( short "x"
<> long "exec"
<> help "Search for the name of an executable" )
<.> arg (\s a -> Right $ a { optCommand = Search (searchOpts a)
{ searchQuery = s } })
( metavar "QUERY"
......@@ -858,21 +864,15 @@ listCmd (ListOptions lv csv cat) cfg repo =
else renderPkgs allpkgs
in putStr listresult >> succeedIO ()
where
-- filter all packages compatible to the current compiler but leave at least
-- one package
filterCompatPkgs pkgs =
let comppkgs = filter (isCompatibleToCompiler cfg) pkgs
in if null comppkgs then take 1 pkgs else comppkgs
-- all packages (and versions if `lv`)
allpkgs = concatMap (if lv then id else ((:[]) . head . filterCompatPkgs))
allpkgs = concatMap (if lv then id else ((:[]) . filterCompatPkgs cfg))
(sortBy (\ps1 ps2 -> name (head ps1) <= name (head ps2))
(listPackages repo))
-- all categories together with their package names:
catgroups =
let pkgid p = name p ++ '-' : showVersionIfCompatible cfg p
newpkgs = map (head . filterCompatPkgs) (listPackages repo)
newpkgs = map (filterCompatPkgs cfg) (listPackages repo)
catpkgs = concatMap (\p -> map (\c -> (c, pkgid p)) (category p))
newpkgs
nocatps = map pkgid (filter (null . category) newpkgs)
......@@ -896,6 +896,14 @@ listCmd (ListOptions lv csv cat) cfg repo =
if csv then showCSV (head rows : drop 2 rows)
else unlines [render (table rows colsizes), cpmInfo, cpmUpdate]
--- Returns the first package of a list of packages compatible to the
--- current compiler (according to the given configuration).
--- If there is no compatible package, returns the first one.
filterCompatPkgs :: Config -> [Package] -> Package
filterCompatPkgs cfg pkgs =
let comppkgs = filter (isCompatibleToCompiler cfg) pkgs
in if null comppkgs then head pkgs else head comppkgs
-- Format a list of packages by showing their names, synopsis, and versions
-- as table rows. Returns also the column sizes.
packageVersionAsTable :: Config -> [Package] -> ([Int],[[String]])
......@@ -923,16 +931,21 @@ cpmUpdate = "Use 'cpm update' to download the newest package index."
--- Search in all (compiler-compatible) packages in the given repository.
search :: SearchOptions -> Config -> Repository -> IO (ErrorLogger ())
search (SearchOptions q smod) cfg repo = putStr rendered >> succeedIO ()
searchCmd :: SearchOptions -> Config -> Repository -> IO (ErrorLogger ())
searchCmd (SearchOptions q smod sexec) cfg repo =
putStr rendered >> succeedIO ()
where
results = sortBy (\p1 p2 -> name p1 <= name p2) (searchPackages repo smod q)
results = sortBy (\p1 p2 -> name p1 <= name p2)
(map (filterCompatPkgs cfg)
(searchPackages repo smod sexec q))
(colsizes,rows) = packageVersionAsTable cfg results
rendered = unlines $
if null results
then ["No packages found for '" ++ q, "'", cpmUpdate]
then ["No packages found for '" ++ q ++ "'", cpmUpdate]
else [ render (table rows colsizes), cpmInfo, cpmUpdate ]
--- `upgrade` command.
upgrade :: UpgradeOptions -> Config -> Repository -> GlobalCache
-> IO (ErrorLogger ())
upgrade (UpgradeOptions Nothing) cfg repo gc =
......@@ -946,6 +959,7 @@ upgrade (UpgradeOptions (Just pkg)) cfg repo gc =
upgradeSinglePackage cfg repo gc specDir pkg
--- `link` command.
linkCmd :: LinkOptions -> Config -> IO (ErrorLogger ())
linkCmd (LinkOptions src) _ =
tryFindLocalPackageSpec "." |>= \specDir ->
......
--------------------------------------------------------------------------------
--- This module contains the data types for a package specification and versions
--- as well as functions for reading/showing/comparing package specs and
--- package versions.
--------------------------------------------------------------------------------
------------------------------------------------------------------------------
--- This module contains the data types for a package specification and
--- versions as well as functions for reading/showing/comparing package specs
--- and package versions.
------------------------------------------------------------------------------
module CPM.Package
( Version, initialVersion
......@@ -11,6 +11,7 @@ module CPM.Package
, CompilerCompatibility (..)
, Package (..), emptyPackage
, Dependency (..)
, execOfPackage
, showVersion
, replaceVersionInTag
, readVersion
......@@ -193,6 +194,13 @@ emptyPackage = Package {
, documentation = Nothing
}
--- Returns the name of the executable of the package.
--- Returns the empty string if the package has no executable to install.
execOfPackage :: Package -> String
execOfPackage p =
maybe "" (\ (PackageExecutable e _ _) -> e) (executableSpec p)
------------------------------------------------------------------------------
--- Translates a package to a JSON object.
packageSpecToJSON :: Package -> JValue
packageSpecToJSON pkg = JObject $
......@@ -902,16 +910,20 @@ readVersion s = parse pVersion s
pVersion :: Parser Version
pVersion = pPureVersion
<|> (\(maj, min, pat, _) pre -> (maj, min, pat, Just pre)) <$> pPureVersion <*> (char '-' *> pPreRelease)
<|> (\(maj, min, pat, _) pre -> (maj, min, pat, Just pre))
<$> pPureVersion <*> (char '-' *> pPreRelease)
pPureVersion :: Parser Version
pPureVersion = (\maj (min, pat) -> (maj, min, pat, Nothing)) <$> (pNum <* char '.') <*> ((\min pat -> (min, pat)) <$> pNum <* char '.' <*> pNum)
pPureVersion = (\maj (min, pat) -> (maj, min, pat, Nothing))
<$> (pNum <* char '.') <*> ((\min pat -> (min, pat))
<$> pNum <* char '.' <*> pNum)
pPreRelease :: Parser String
pPreRelease = some (check isAscii anyChar)
pNum :: Parser Int
pNum = (\cs -> foldl1 ((+).(10*)) (map (\c' -> ord c' - ord '0') cs)) <$> some pDigit
pNum = (\cs -> foldl1 ((+).(10*)) (map (\c' -> ord c' - ord '0') cs))
<$> some pDigit
pDigit :: Parser Char
pDigit = check isDigit anyChar
......@@ -209,11 +209,11 @@ renderPackageInfo allinfos plain gc pkg = pPrint doc
boldText s = (if plain then id else bold) $ text s
maxLen = 12
doc = vcat $ [ heading, rule, installed, ver, auth, maintnr, synop
, cats, deps, compilers, descr ] ++
, cats, deps, compilers, descr, execspec ] ++
if allinfos
then [ srcdirs, expmods, cfgmod, execspec] ++ testsuites ++
then [ srcdirs, expmods, cfgmod ] ++ testsuites ++
[ docuspec, src, licns, licfl, copyrt, homepg
, reposy, bugrep]
, reposy, bugrep ]
else []
pkgId = packageId pkg
......@@ -246,13 +246,15 @@ renderPackageInfo allinfos plain gc pkg = pPrint doc
execspec = case executableSpec pkg of
Nothing -> empty
Just (PackageExecutable n m eopts) ->
boldText "Executable" <$$>
indent 4 (boldText "Name " <+> text n) <$$>
indent 4 (boldText "Main module " <+> text m) <$$>
if null eopts
then empty
else indent 4 (boldText "Options ") <+>
align (vsep (map (\ (c,o) -> text $ c ++ ": " ++ o) eopts))
if allinfos
then boldText "Executable" <$$>
indent 4 (boldText "Name " <+> text n) <$$>
indent 4 (boldText "Main module " <+> text m) <$$>
if null eopts
then empty
else indent 4 (boldText "Options ") <+>
align (vsep (map (\ (c,o) -> text $ c ++ ": " ++ o) eopts))
else fill maxLen (boldText "Executable") <+> text n
testsuites = case testSuite pkg of
Nothing -> []
......
......@@ -61,26 +61,33 @@ findAllVersions (Repository ps) p pre =
--- Search the names and synopses of all compiler-compatbile packages
--- in the repository for a particular term.
--- Lower/upercase is ignored for the search.
--- Returns the newest matching version of each package.
--- Returns all matching versions (newest first) of each package.
---
--- @param repo - the repository
--- @searchmod - search for some module?
--- @param q - the term to search for
searchPackages :: Repository -> Bool -> String -> [Package]
searchPackages (Repository ps) searchmod searchstring =
map (head . sortedByVersion) groupedResults
--- @param repo - the repository
--- @param searchmod - search for some module?
--- @param searchexec - search for some executable?
--- @param searchterm - the term to search for
searchPackages :: Repository -> Bool -> Bool -> String -> [[Package]]
searchPackages (Repository ps) searchmod searchexec searchterm =
map sortedByVersion (groupBy (\a b -> name a == name b) allResults)
where
groupedResults = groupBy namesEqual allResults
allResults = if searchmod
then filter (\p -> searchstring `elem` (exportedModules p)) ps
else filter (matches (lowerS searchstring)) ps
allResults = let s = lowerS searchterm
in if searchmod
then filter (\p -> s `elem` exportedModules p) ps
else if searchexec
then filter (\p -> s `isInfixOf`
(lowerS $ execOfPackage p)) ps
else filter (matches s) ps
matches q p = q `isInfixOf` (lowerS $ name p) ||
q `isInfixOf` (lowerS $ synopsis p) ||
q `isInfixOf` (lowerS $ unwords (exportedModules p))
namesEqual a b = (name a) == (name b)
sortedByVersion = sortBy (\a b -> (version a) `vgt` (version b))
sortedByVersion = sortBy (\a b -> version a `vgt` version b)
lowerS = map toLower
--- Get all packages in the repository and group them by versions
--- (newest first).
---
......
......@@ -3,6 +3,9 @@ This directory contains some documention for the Curry Analysis Server System:
manual.tex:
A short description to be included in the main manual of the Curry system.
main.tex:
The manual as a stand-alone LaTeX file.
<ana>.md:
The documentation of the analysis registered with name <ana> in
markdown syntax.
......@@ -28,7 +28,7 @@ Thus, to install the newest version of CASS, use the following commands:
%
\begin{curry}
> cpm update
> cpm installapp cass
> cpm install cass
\end{curry}
%
This downloads the newest package, compiles it, and places
......
......@@ -3,6 +3,9 @@ This directory contains some documention for the Curry Analysis Server System:
manual.tex:
A short description to be included in the main manual of the Curry system.
main.tex:
The manual as a stand-alone LaTeX file.
<ana>.md:
The documentation of the analysis registered with name <ana> in
markdown syntax.
......@@ -28,7 +28,7 @@ Thus, to install the newest version of CASS, use the following commands:
%
\begin{curry}
> cpm update
> cpm installapp cass
> cpm install cass
\end{curry}
%
This downloads the newest package, compiles it, and places
......
......@@ -38,7 +38,7 @@ Thus, to install the newest version of CurryVerify, use the following commands:
%
\begin{curry}
> cpm update
> cpm installapp verify
> cpm install verify
\end{curry}
%
This downloads the newest package, compiles it, and places
......
......@@ -3,6 +3,9 @@ This directory contains some documention for the Curry Analysis Server System:
manual.tex:
A short description to be included in the main manual of the Curry system.
main.tex:
The manual as a stand-alone LaTeX file.
<ana>.md:
The documentation of the analysis registered with name <ana> in
markdown syntax.
......@@ -28,7 +28,7 @@ Thus, to install the newest version of CASS, use the following commands:
%
\begin{curry}
> cpm update
> cpm installapp cass
> cpm install cass
\end{curry}
%
This downloads the newest package, compiles it, and places
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment