stackage-metadata 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+71/−10 lines, 5 files
Files
- ChangeLog.md +4/−0
- README.md +5/−1
- Stackage/Metadata.hs +12/−0
- app/all-cabal-metadata-tool.hs +49/−8
- stackage-metadata.cabal +1/−1
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.2.0.0++* More metadata fields+ ## 0.1.0.0 * Initial release
README.md view
@@ -3,4 +3,8 @@ [](https://travis-ci.org/commercialhaskell/all-cabal-metadata-tool) Tool for extracting metadata on all packages. Mostly used for-[all-cabal-metadata](https://github.com/commercialhaskell/all-cabal-metadata)+[all-cabal-metadata](https://github.com/commercialhaskell/all-cabal-metadata).+Note that this library will gain some capabilities in the future for projects+looking to read from the all-cabal-metadata repository. One motivating use case+is [Stackage Server](https://www.stackage.org), though command line utilities+would make sense as well.
Stackage/Metadata.hs view
@@ -31,6 +31,10 @@ , piChangeLogType :: !Text , piBasicDeps :: !(Map PackageName VersionRange) , piTestBenchDeps :: !(Map PackageName VersionRange)+ , piAuthor :: !Text+ , piMaintainer :: !Text+ , piHomepage :: !Text+ , piLicenseName :: !Text } deriving (Show, Eq, Typeable) instance ToJSON PackageInfo where@@ -45,6 +49,10 @@ , "changelog-type" .= piChangeLogType pi , "basic-deps" .= showM (piBasicDeps pi) , "test-bench-deps" .= showM (piTestBenchDeps pi)+ , "author" .= piAuthor pi+ , "maintainer" .= piMaintainer pi+ , "homepage" .= piHomepage pi+ , "license-name" .= piLicenseName pi ] where showM = Map.mapKeysWith const renderDistText . Map.map renderDistText@@ -60,6 +68,10 @@ <*> o .: "changelog-type" <*> (o .: "basic-deps" >>= parseM) <*> (o .: "test-bench-deps" >>= parseM)+ <*> o .: "author"+ <*> o .: "maintainer"+ <*> o .: "homepage"+ <*> o .: "license-name" where parseM = fmap Map.fromList . mapM go . Map.toList go (name, range) = do
app/all-cabal-metadata-tool.hs view
@@ -16,6 +16,7 @@ import qualified Data.Conduit.List as CL import Data.Map (Map) import qualified Data.Map as Map+import Data.Maybe (fromMaybe) import Data.Set (Set) import qualified Data.Set as Set import Data.Text (Text, pack, toLower,@@ -23,27 +24,34 @@ import Data.Text.Encoding (decodeUtf8With) import qualified Data.Text.Encoding as TE import Data.Text.Encoding.Error (lenientDecode)-import Data.Version (Version)+import Data.Version (Version (Version)) import Data.Yaml (decodeEither', decodeFileEither, encodeFile)+import Distribution.Compiler (CompilerFlavor (GHC)) import Distribution.Package (Dependency (..), PackageIdentifier (..), PackageName) import Distribution.PackageDescription (CondTree (..), Condition (..),- ConfVar (..),- condBenchmarks,+ ConfVar (..), Flag (flagName, flagDefault), GenericPackageDescription,+ author, condBenchmarks, condExecutables, condLibrary, condTestSuites,- description, package,+ description,+ genPackageFlags,+ homepage, license,+ maintainer, package, packageDescription, synopsis) import Distribution.PackageDescription.Parse (ParseResult (..))+import Distribution.System (Arch (X86_64),+ OS (Linux)) import Distribution.Version (VersionRange, intersectVersionRanges,- simplifyVersionRange)+ simplifyVersionRange,+ withinRange) import Network.HTTP.Client (Manager, brConsume, newManager, responseBody,@@ -55,6 +63,7 @@ import Stackage.PackageIndex.Conduit import Stackage.Update import System.Directory (createDirectoryIfMissing)+import System.Environment (getArgs) import System.FilePath (splitExtension, takeDirectory, takeFileName, (<.>),@@ -64,6 +73,11 @@ main :: IO () main = do+ args <- getArgs+ limitTo <-+ case args of+ [x] -> return $! read x+ _ -> return 500 stackageUpdate $ setVerify False defaultStackageUpdateSettings man <- newManager tlsManagerSettings@@ -97,7 +111,7 @@ CL.mapMaybeM (updatePackage set packageLocation) liftIO $ saveDeprecated man )- =$ CL.isolate 500+ =$ CL.isolate limitTo =$ CL.sinkNull saveDeprecated :: Manager -> IO ()@@ -146,7 +160,7 @@ liftIO $ do createDirectoryIfMissing True $ takeDirectory fp- let checkCond = const True -- FIXME do something intelligent+ let checkCond = getCheckCond gpd getDeps' = getDeps checkCond encodeFile fp PackageInfo { piLatest = version@@ -163,6 +177,10 @@ , piTestBenchDeps = combineDeps $ map (getDeps' . snd) (condTestSuites gpd) ++ map (getDeps' . snd) (condBenchmarks gpd)+ , piAuthor = pack $ author pd+ , piMaintainer = pack $ maintainer pd+ , piHomepage = pack $ homepage pd+ , piLicenseName = pack $ renderDistText $ license pd } return $ Just () where@@ -207,7 +225,30 @@ ".markdown" -> "markdown" _ -> "text" --- | FIXME this function should get cleaned up and merged into stackage-common+-- | FIXME these functions should get cleaned up and merged into stackage-common+getCheckCond :: GenericPackageDescription -> Condition ConfVar -> Bool+getCheckCond gpd =+ go+ where+ go (Var (OS os)) = os == Linux -- arbitrary+ go (Var (Arch arch)) = arch == X86_64 -- arbitrary+ go (Var (Flag flag)) =+ fromMaybe False -- arbitrary+ $ Map.lookup flag flags+ go (Var (Impl flavor range)) = flavor == GHC+ && ghcVersion `withinRange` range+ go (Lit b) = b+ go (CNot c) = not $ go c+ go (CAnd x y) = go x && go y+ go (COr x y) = go x || go y++ ghcVersion = Version [7, 10, 1] [] -- arbitrary++ flags =+ Map.fromList $ map toPair $ genPackageFlags gpd+ where+ toPair f = (flagName f, flagDefault f)+ getDeps :: (Condition ConfVar -> Bool) -> CondTree ConfVar [Dependency] a -> Map PackageName VersionRange
stackage-metadata.cabal view
@@ -1,5 +1,5 @@ name: stackage-metadata-version: 0.1.0.0+version: 0.2.0.0 synopsis: Grab current metadata for all packages description: See README.md homepage: https://github.com/commercialhaskell/all-cabal-metadata-tool