<commit_before>module Network.Hackage.Client where

import Distribution.Package
import Distribution.PackageDescription
import Distribution.Version
import Data.Version
import Data.Maybe
import Text.ParserCombinators.ReadP
import Distribution.ParseUtils

type PathName = String

-- Resolved dependency, pkg location and resolved dependencies of the dependency.
data ResolvedDependency
    = ResolvedDependency PackageIdentifier String [(Dependency,Maybe ResolvedDependency)]
      deriving (Eq,Show)

data Pkg = Pkg String [String] String
    deriving (Show, Read)

getPkgDescription :: String -> PackageIdentifier -> IO (Maybe String)
getPkgDescription url pkgId = do
    fmap Just ( getFrom url (pathOf pkgId "cabal") )

getPkgDescriptions :: String -> [PackageIdentifier] -> IO [Maybe String]
getPkgDescriptions url pkgIds = mapM (getPkgDescription url) pkgIds

getDependencies :: String -> [Dependency] -> IO [(Dependency, Maybe ResolvedDependency)]
getDependencies _ _ = fail "getDependencies unimplemented" -- remote url "getDependencies"

listPackages :: String -> IO [(PackageIdentifier,[Dependency],String)]
listPackages url = do
    x    <- getFrom url "latest.txt" -- remote url "listPackages"
    pkgs <- readIO x
    return $ map parsePkg pkgs
    where
    parsePkg :: Pkg -> (PackageIdentifier,[Dependency],String)
    parsePkg (Pkg ident deps _) = (pkgId, pkgDeps, pkgURL)
        where
        pkgId   = parseWith parsePackageId ident
        pkgDeps = map (parseWith parseDependency) deps
        pkgURL  = url ++ "/" ++ pathOf pkgId "tar.gz"

pathOf :: PackageIdentifier -> String -> PathName
pathOf pkgId ext = concat [pkgName pkgId, "/", showPackageId pkgId, ".", ext]

parseWith :: Show a => ReadP a -> String -> a
parseWith f s = case reverse (readP_to_S f s) of<commit_msg>it's now 00-latest not latest<commit_after>module Network.Hackage.Client where

import Distribution.Package
import Distribution.PackageDescription
import Distribution.Version
import Data.Version
import Data.Maybe
import Text.ParserCombinators.ReadP
import Distribution.ParseUtils

type PathName = String

-- Resolved dependency, pkg location and resolved dependencies of the dependency.
data ResolvedDependency
    = ResolvedDependency PackageIdentifier String [(Dependency,Maybe ResolvedDependency)]
      deriving (Eq,Show)

data Pkg = Pkg String [String] String
    deriving (Show, Read)

getPkgDescription :: String -> PackageIdentifier -> IO (Maybe String)
getPkgDescription url pkgId = do
    fmap Just ( getFrom url (pathOf pkgId "cabal") )

getPkgDescriptions :: String -> [PackageIdentifier] -> IO [Maybe String]
getPkgDescriptions url pkgIds = mapM (getPkgDescription url) pkgIds

getDependencies :: String -> [Dependency] -> IO [(Dependency, Maybe ResolvedDependency)]
getDependencies _ _ = fail "getDependencies unimplemented" -- remote url "getDependencies"

listPackages :: String -> IO [(PackageIdentifier,[Dependency],String)]
listPackages url = do
    x    <- getFrom url "00-latest.txt" -- remote url "listPackages"
    pkgs <- readIO x
    return $ map parsePkg pkgs
    where
    parsePkg :: Pkg -> (PackageIdentifier,[Dependency],String)
    parsePkg (Pkg ident deps _) = (pkgId, pkgDeps, pkgURL)
        where
        pkgId   = parseWith parsePackageId ident
        pkgDeps = map (parseWith parseDependency) deps
        pkgURL  = url ++ "/" ++ pathOf pkgId "tar.gz"

pathOf :: PackageIdentifier -> String -> PathName
pathOf pkgId ext = concat [pkgName pkgId, "/", showPackageId pkgId, ".", ext]

parseWith :: Show a => ReadP a -> String -> a
parseWith f s = case reverse (readP_to_S f s) of
{'fraction_non_alphanumeric': 0.09393183707398171, 'fraction_numerical': 0.0011083402604599613, 'mean_word_length': 4.224312590448625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3710632', 'n_tokens_mistral': 1062, 'n_tokens_neox': 999, 'n_words': 339}